42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
import worker
|
|
|
|
|
|
class CadFormatTests(unittest.TestCase):
|
|
def test_source_format_variants(self) -> None:
|
|
self.assertEqual(worker.source_format_for_path(Path("model.STEP")), "step")
|
|
self.assertEqual(worker.source_format_for_path(Path("model.stp")), "step")
|
|
self.assertEqual(worker.source_format_for_path(Path("model.IGES")), "iges")
|
|
self.assertEqual(worker.source_format_for_path(Path("model.igs")), "iges")
|
|
self.assertIsNone(worker.source_format_for_path(Path("model.glb")))
|
|
|
|
def test_process_one_dispatches_iges_converter(self) -> None:
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
worker.UPLOADS_DIR = Path(directory).resolve()
|
|
source_path = worker.UPLOADS_DIR / "model.igs"
|
|
source_path.write_bytes(b"IGES")
|
|
|
|
metadata = {
|
|
"artifact": "uploads/model.xkt",
|
|
"artifactType": "xkt",
|
|
"componentCount": 1,
|
|
}
|
|
with (
|
|
patch.object(worker, "find_ready_conversion_with_same_hash", return_value=None),
|
|
patch.object(worker, "convert_iges_assets", return_value=metadata) as convert_iges,
|
|
):
|
|
self.assertTrue(worker.process_one(source_path))
|
|
|
|
convert_iges.assert_called_once()
|
|
manifest = worker.read_json(worker.manifest_path(source_path))
|
|
self.assertEqual(manifest["sourceFormat"], "iges")
|
|
self.assertEqual(manifest["status"], "ready")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|