TestQualityManager.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from unittest.mock import MagicMock
  2. import pytest
  3. from cura.Machines.QualityManager import QualityManager
  4. mocked_stack = MagicMock()
  5. mocked_extruder = MagicMock()
  6. mocked_material = MagicMock()
  7. mocked_material.getMetaDataEntry = MagicMock(return_value = "base_material")
  8. mocked_extruder.material = mocked_material
  9. mocked_stack.extruders = {"0": mocked_extruder}
  10. @pytest.fixture()
  11. def material_manager():
  12. result = MagicMock()
  13. result.getRootMaterialIDWithoutDiameter = MagicMock(return_value = "base_material")
  14. return result
  15. @pytest.fixture()
  16. def container_registry():
  17. result = MagicMock()
  18. mocked_metadata = [{"id": "test", "definition": "fdmprinter", "quality_type": "normal", "name": "test_name", "global_quality": True, "type": "quality"},
  19. {"id": "test_material", "definition": "fdmprinter", "quality_type": "normal", "name": "test_name_material", "material": "base_material", "type": "quality"},
  20. {"id": "quality_changes_id", "definition": "fdmprinter", "type": "quality_changes", "quality_type": "amazing!", "name": "herp"}]
  21. result.findContainersMetadata = MagicMock(return_value = mocked_metadata)
  22. return result
  23. @pytest.fixture()
  24. def quality_mocked_application(material_manager, container_registry):
  25. result = MagicMock()
  26. result.getMaterialManager = MagicMock(return_value=material_manager)
  27. result.getContainerRegistry = MagicMock(return_value=container_registry)
  28. return result
  29. def test_getQualityGroups(quality_mocked_application):
  30. manager = QualityManager(quality_mocked_application)
  31. manager.initialize()
  32. assert "normal" in manager.getQualityGroups(mocked_stack)
  33. def test_getQualityGroupsForMachineDefinition(quality_mocked_application):
  34. manager = QualityManager(quality_mocked_application)
  35. manager.initialize()
  36. assert "normal" in manager.getQualityGroupsForMachineDefinition(mocked_stack)
  37. def test_getQualityChangesGroup(quality_mocked_application):
  38. manager = QualityManager(quality_mocked_application)
  39. manager.initialize()
  40. assert "herp" in manager.getQualityChangesGroups(mocked_stack)