Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime van Kessel <nallath@gmail.com>2019-02-15 17:19:19 +0300
committerJaime van Kessel <nallath@gmail.com>2019-02-15 17:19:19 +0300
commit369c64e1b6d7b060dd04ff50571249455dced830 (patch)
tree1a90eed5a0e5e92aa61364b353212042cb4d3d8a /tests/PrinterOutput
parent338f9c0052ac6a06e194be02104c73243bbd402c (diff)
Add tests for PrintJobOutputModel & PrinterOutputModel
Diffstat (limited to 'tests/PrinterOutput')
-rw-r--r--tests/PrinterOutput/TestPrintJobOutputModel.py78
-rw-r--r--tests/PrinterOutput/TestPrinterOutputModel.py82
2 files changed, 160 insertions, 0 deletions
diff --git a/tests/PrinterOutput/TestPrintJobOutputModel.py b/tests/PrinterOutput/TestPrintJobOutputModel.py
new file mode 100644
index 0000000000..658cff7a7e
--- /dev/null
+++ b/tests/PrinterOutput/TestPrintJobOutputModel.py
@@ -0,0 +1,78 @@
+from unittest.mock import MagicMock
+
+import pytest
+
+from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
+from cura.PrinterOutput.PrintJobOutputModel import PrintJobOutputModel
+from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
+
+test_validate_data_get_set = [
+ {"attribute": "compatibleMachineFamilies", "value": ["yay"]},
+]
+
+test_validate_data_get_update = [
+ {"attribute": "configuration", "value": ConfigurationModel()},
+ {"attribute": "owner", "value": "WHOO"},
+ {"attribute": "assignedPrinter", "value": PrinterOutputModel(MagicMock())},
+ {"attribute": "key", "value": "YAY"},
+ {"attribute": "name", "value": "Turtles"},
+ {"attribute": "timeTotal", "value": 10},
+ {"attribute": "timeElapsed", "value": 20},
+ {"attribute": "state", "value": "BANANNA!"},
+]
+
+
+@pytest.mark.parametrize("data", test_validate_data_get_set)
+def test_getAndSet(data):
+ model = PrintJobOutputModel(MagicMock())
+
+ # Convert the first letter into a capital
+ attribute = list(data["attribute"])
+ attribute[0] = attribute[0].capitalize()
+ attribute = "".join(attribute)
+
+ # mock the correct emit
+ setattr(model, data["attribute"] + "Changed", MagicMock())
+
+ # Attempt to set the value
+ getattr(model, "set" + attribute)(data["value"])
+
+ # Check if signal fired.
+ signal = getattr(model, data["attribute"] + "Changed")
+ assert signal.emit.call_count == 1
+
+ # Ensure that the value got set
+ assert getattr(model, data["attribute"]) == data["value"]
+
+ # Attempt to set the value again
+ getattr(model, "set" + attribute)(data["value"])
+ # The signal should not fire again
+ assert signal.emit.call_count == 1
+
+
+@pytest.mark.parametrize("data", test_validate_data_get_update)
+def test_getAndUpdate(data):
+ model = PrintJobOutputModel(MagicMock())
+
+ # Convert the first letter into a capital
+ attribute = list(data["attribute"])
+ attribute[0] = attribute[0].capitalize()
+ attribute = "".join(attribute)
+
+ # mock the correct emit
+ setattr(model, data["attribute"] + "Changed", MagicMock())
+
+ # Attempt to set the value
+ getattr(model, "update" + attribute)(data["value"])
+
+ # Check if signal fired.
+ signal = getattr(model, data["attribute"] + "Changed")
+ assert signal.emit.call_count == 1
+
+ # Ensure that the value got set
+ assert getattr(model, data["attribute"]) == data["value"]
+
+ # Attempt to set the value again
+ getattr(model, "update" + attribute)(data["value"])
+ # The signal should not fire again
+ assert signal.emit.call_count == 1
diff --git a/tests/PrinterOutput/TestPrinterOutputModel.py b/tests/PrinterOutput/TestPrinterOutputModel.py
new file mode 100644
index 0000000000..f0ed3af633
--- /dev/null
+++ b/tests/PrinterOutput/TestPrinterOutputModel.py
@@ -0,0 +1,82 @@
+
+
+from unittest.mock import MagicMock
+
+import pytest
+
+from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
+from cura.PrinterOutput.PrintJobOutputModel import PrintJobOutputModel
+from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
+
+test_validate_data_get_set = [
+ {"attribute": "name", "value": "YAY"},
+ {"attribute": "targetBedTemperature", "value": 192},
+]
+
+test_validate_data_get_update = [
+ {"attribute": "isPreheating", "value": True},
+ {"attribute": "type", "value": "WHOO"},
+ {"attribute": "buildplate", "value": "NFHA"},
+ {"attribute": "key", "value": "YAY"},
+ {"attribute": "name", "value": "Turtles"},
+ {"attribute": "bedTemperature", "value": 200},
+ {"attribute": "targetBedTemperature", "value": 9001},
+ {"attribute": "activePrintJob", "value": PrintJobOutputModel(MagicMock())},
+ {"attribute": "state", "value": "BEEPBOOP"},
+]
+
+
+@pytest.mark.parametrize("data", test_validate_data_get_set)
+def test_getAndSet(data):
+ model = PrinterOutputModel(MagicMock())
+
+ # Convert the first letter into a capital
+ attribute = list(data["attribute"])
+ attribute[0] = attribute[0].capitalize()
+ attribute = "".join(attribute)
+
+ # mock the correct emit
+ setattr(model, data["attribute"] + "Changed", MagicMock())
+
+ # Attempt to set the value
+ getattr(model, "set" + attribute)(data["value"])
+
+ # Check if signal fired.
+ signal = getattr(model, data["attribute"] + "Changed")
+ assert signal.emit.call_count == 1
+
+ # Ensure that the value got set
+ assert getattr(model, data["attribute"]) == data["value"]
+
+ # Attempt to set the value again
+ getattr(model, "set" + attribute)(data["value"])
+ # The signal should not fire again
+ assert signal.emit.call_count == 1
+
+
+@pytest.mark.parametrize("data", test_validate_data_get_update)
+def test_getAndUpdate(data):
+ model = PrinterOutputModel(MagicMock())
+
+ # Convert the first letter into a capital
+ attribute = list(data["attribute"])
+ attribute[0] = attribute[0].capitalize()
+ attribute = "".join(attribute)
+
+ # mock the correct emit
+ setattr(model, data["attribute"] + "Changed", MagicMock())
+
+ # Attempt to set the value
+ getattr(model, "update" + attribute)(data["value"])
+
+ # Check if signal fired.
+ signal = getattr(model, data["attribute"] + "Changed")
+ assert signal.emit.call_count == 1
+
+ # Ensure that the value got set
+ assert getattr(model, data["attribute"]) == data["value"]
+
+ # Attempt to set the value again
+ getattr(model, "update" + attribute)(data["value"])
+ # The signal should not fire again
+ assert signal.emit.call_count == 1