diff options
author | Ghostkeeper <rubend@tutanota.com> | 2019-09-23 16:03:24 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2019-09-23 16:03:24 +0300 |
commit | 7d40d962e85405d13503a6b7cf4e7c65cd8d5656 (patch) | |
tree | 84ade9a512108b3be6b25fbd2bffd080dd5f35fe /tests/TestIntentManager.py | |
parent | 355248447727c1c0ba0f7b62b581127427b68eaa (diff) |
Mock ContainerTree instead of ContainerRegistry to test intent manager
Because now it relies on the container tree instead of querying the registry anew every time.
Diffstat (limited to 'tests/TestIntentManager.py')
-rw-r--r-- | tests/TestIntentManager.py | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/tests/TestIntentManager.py b/tests/TestIntentManager.py index 97ea663344..2fd06372ce 100644 --- a/tests/TestIntentManager.py +++ b/tests/TestIntentManager.py @@ -11,10 +11,50 @@ from cura.Machines.QualityGroup import QualityGroup from tests.Settings.MockContainer import MockContainer +mocked_intent_metadata = [ + {"id": "um3_aa4_pla_smooth_normal", "GUID": "abcxyz", "definition": "ultimaker3", "variant": "AA 0.4", + "material_id": "generic_pla", "intent_category": "smooth", "quality_type": "normal"}, + {"id": "um3_aa4_pla_strong_abnorm", "GUID": "defqrs", "definition": "ultimaker3", "variant": "AA 0.4", + "material_id": "generic_pla", "intent_category": "strong", "quality_type": "abnorm"}] # type:List[Dict[str, str]] + +mocked_qualitygroup_metadata = { + "normal": QualityGroup("um3_aa4_pla_normal", "normal"), + "abnorm": QualityGroup("um3_aa4_pla_abnorm", "abnorm")} # type:Dict[str, QualityGroup] + @pytest.fixture() def mock_container_tree() -> MagicMock: container_tree = MagicMock() container_tree.getCurrentQualityGroups = MagicMock(return_value = mocked_qualitygroup_metadata) + container_tree.machines = { + "ultimaker3": MagicMock( + variants = { + "AA 0.4": MagicMock( + materials = { + "generic_pla": MagicMock( + qualities = { + "um3_aa4_pla_normal": MagicMock( + intents = { + "smooth": MagicMock( + intent_category = "smooth", + getMetadata = MagicMock(return_value = mocked_intent_metadata[0]) + ) + } + ), + "um3_aa4_pla_abnorm": MagicMock( + intents = { + "strong": MagicMock( + intent_category = "strong", + getMetadata = MagicMock(return_value = mocked_intent_metadata[1]) + ) + } + ) + } + ) + } + ) + } + ) + } return container_tree @pytest.fixture() @@ -27,17 +67,6 @@ def intent_manager(application, extruder_manager, machine_manager, container_reg manager = IntentManager() return manager -mocked_intent_metadata = [ - {"id": "um3_aa4_pla_smooth_normal", "GUID": "abcxyz", "definition": "ultimaker3", "variant": "AA 0.4", - "material_id": "generic_pla", "intent_category": "smooth", "quality_type": "normal"}, - {"id": "um3_aa4_pla_strong_abnorm", "GUID": "defqrs", "definition": "ultimaker3", "variant": "AA 0.4", - "material_id": "generic_pla", "intent_category": "strong", "quality_type": "abnorm"}] # type:List[Dict[str, str]] - -mocked_qualitygroup_metadata = { - "normal": QualityGroup("um3_aa4_pla_normal", "normal"), - "abnorm": QualityGroup("um3_aa4_pla_abnorm", "abnorm")} # type:Dict[str, QualityGroup] - - def mockFindMetadata(**kwargs) -> List[Dict[str, Any]]: if "id" in kwargs: return [x for x in mocked_intent_metadata if x["id"] == kwargs["id"]] @@ -82,16 +111,12 @@ def doSetup(application, extruder_manager, container_registry, global_stack) -> extruder_manager.getUsedExtruderStacks = MagicMock(return_value = [extruder_stack_a, extruder_stack_b]) -def test_intentCategories(application, intent_manager, container_registry): - # Mock .findContainersMetadata so we also test .intentMetadatas (the latter is mostly a wrapper around the former). - container_registry.findContainersMetadata = MagicMock(return_value = mocked_intent_metadata) - - with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = application)): - with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)): - categories = intent_manager.intentCategories("ultimaker3", "AA 0.4", "generic_pla") # type:List[str] - assert "default" in categories, "default should always be in categories" - assert "strong" in categories, "strong should be in categories" - assert "smooth" in categories, "smooth should be in categories" +def test_intentCategories(intent_manager, mock_container_tree): + with patch("cura.Machines.ContainerTree.ContainerTree.getInstance", MagicMock(return_value = mock_container_tree)): + categories = intent_manager.intentCategories("ultimaker3", "AA 0.4", "generic_pla") # type:List[str] + assert "default" in categories, "default should always be in categories" + assert "strong" in categories, "strong should be in categories" + assert "smooth" in categories, "smooth should be in categories" def test_getCurrentAvailableIntents(application, extruder_manager, intent_manager, container_registry, global_stack, mock_container_tree): |