TestQualityNode.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from unittest.mock import patch, MagicMock
  4. import pytest
  5. from cura.Machines.QualityNode import QualityNode
  6. # Metadata for hypothetical containers that get put in the registry.
  7. metadatas = [
  8. {
  9. "id": "matching_intent", # Matches our query.
  10. "type": "intent",
  11. "definition": "correct_definition",
  12. "variant": "correct_variant",
  13. "material": "correct_material",
  14. "quality_type": "correct_quality_type"
  15. },
  16. {
  17. "id": "matching_intent_2", # Matches our query as well.
  18. "type": "intent",
  19. "definition": "correct_definition",
  20. "variant": "correct_variant",
  21. "material": "correct_material",
  22. "quality_type": "correct_quality_type"
  23. },
  24. {
  25. "id": "bad_type",
  26. "type": "quality", # Doesn't match because it's not an intent.
  27. "definition": "correct_definition",
  28. "variant": "correct_variant",
  29. "material": "correct_material",
  30. "quality_type": "correct_quality_type"
  31. },
  32. {
  33. "id": "bad_definition",
  34. "type": "intent",
  35. "definition": "wrong_definition", # Doesn't match on the definition.
  36. "variant": "correct_variant",
  37. "material": "correct_material",
  38. "quality_type": "correct_quality_type"
  39. },
  40. {
  41. "id": "bad_variant",
  42. "type": "intent",
  43. "definition": "correct_definition",
  44. "variant": "wrong_variant", # Doesn't match on the variant.
  45. "material": "correct_material",
  46. "quality_type": "correct_quality_type"
  47. },
  48. {
  49. "id": "bad_material",
  50. "type": "intent",
  51. "definition": "correct_definition",
  52. "variant": "correct_variant",
  53. "material": "wrong_material", # Doesn't match on the material.
  54. "quality_type": "correct_quality_type"
  55. },
  56. {
  57. "id": "bad_quality",
  58. "type": "intent",
  59. "definition": "correct_definition",
  60. "variant": "correct_variant",
  61. "material": "correct_material",
  62. "quality_type": "wrong_quality_type" # Doesn't match on the quality type.
  63. },
  64. {
  65. "id": "quality_1",
  66. "quality_type": "correct_quality_type",
  67. "material": "correct_material"
  68. }
  69. ]
  70. @pytest.fixture
  71. def container_registry():
  72. result = MagicMock()
  73. def findContainersMetadata(**kwargs):
  74. return [metadata for metadata in metadatas if kwargs.items() <= metadata.items()]
  75. result.findContainersMetadata = findContainersMetadata
  76. result.findInstanceContainersMetadata = findContainersMetadata
  77. return result
  78. def test_qualityNode_machine_1(container_registry):
  79. material_node = MagicMock()
  80. material_node.variant.machine.quality_definition = "correct_definition"
  81. material_node.variant.variant_name = "correct_variant"
  82. with patch("cura.Machines.QualityNode.IntentNode"):
  83. with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
  84. node = QualityNode("quality_1", material_node)
  85. assert len(node.intents) == 3
  86. assert "matching_intent" in node.intents
  87. assert "matching_intent_2" in node.intents
  88. assert "empty_intent" in node.intents