mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
Fix the first tests
This commit is contained in:
parent
f8f133d2ef
commit
dc17bd8499
2 changed files with 16 additions and 8 deletions
|
@ -157,6 +157,7 @@ class SendMaterialJob(Job):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parseReply(cls, reply: QNetworkReply) -> Dict[str, ClusterMaterial]:
|
def _parseReply(cls, reply: QNetworkReply) -> Dict[str, ClusterMaterial]:
|
||||||
remote_materials_list = json.loads(reply.readAll().data().decode("utf-8"))
|
remote_materials_list = json.loads(reply.readAll().data().decode("utf-8"))
|
||||||
|
print("remote_materials_list", remote_materials_list)
|
||||||
return {material["guid"]: ClusterMaterial(**material) for material in remote_materials_list}
|
return {material["guid"]: ClusterMaterial(**material) for material in remote_materials_list}
|
||||||
|
|
||||||
## Retrieves a list of local materials
|
## Retrieves a list of local materials
|
||||||
|
|
|
@ -90,26 +90,33 @@ class TestSendMaterialJob(TestCase):
|
||||||
def test_run(self, device_mock):
|
def test_run(self, device_mock):
|
||||||
job = SendMaterialJob(device_mock)
|
job = SendMaterialJob(device_mock)
|
||||||
job.run()
|
job.run()
|
||||||
|
|
||||||
|
# We expect the materials endpoint to be called when the job runs.
|
||||||
device_mock.get.assert_called_with("materials/", on_finished=job._onGetRemoteMaterials)
|
device_mock.get.assert_called_with("materials/", on_finished=job._onGetRemoteMaterials)
|
||||||
|
|
||||||
@patch("plugins.UM3NetworkPrinting.src.ClusterUM3OutputDevice")
|
@patch("plugins.UM3NetworkPrinting.src.ClusterUM3OutputDevice")
|
||||||
@patch("PyQt5.QtNetwork.QNetworkReply")
|
@patch("PyQt5.QtNetwork.QNetworkReply")
|
||||||
def test_sendMissingMaterials_withFailedRequest(self, reply_mock, device_mock):
|
def test_sendMissingMaterials_withFailedRequest(self, reply_mock, device_mock):
|
||||||
reply_mock.attribute.return_value = 404
|
reply_mock.attribute.return_value = 404
|
||||||
SendMaterialJob(device_mock).run()
|
job = SendMaterialJob(device_mock)
|
||||||
reply_mock.attribute.assert_called_with(0)
|
job._onGetRemoteMaterials(reply_mock)
|
||||||
self.assertEqual(reply_mock.method_calls, [call.attribute(0)])
|
|
||||||
self.assertEqual(device_mock._onGetRemoteMaterials.method_calls, [])
|
# We expect the error string to be retrieved and the device not to be called for any follow up.
|
||||||
|
self.assertEqual([call.attribute(0), call.errorString()], reply_mock.method_calls)
|
||||||
|
self.assertEqual([], device_mock.method_calls)
|
||||||
|
|
||||||
@patch("plugins.UM3NetworkPrinting.src.ClusterUM3OutputDevice")
|
@patch("plugins.UM3NetworkPrinting.src.ClusterUM3OutputDevice")
|
||||||
@patch("PyQt5.QtNetwork.QNetworkReply")
|
@patch("PyQt5.QtNetwork.QNetworkReply")
|
||||||
def test_sendMissingMaterials_withBadJsonAnswer(self, reply_mock, device_mock):
|
def test_sendMissingMaterials_withBadJsonAnswer(self, reply_mock, device_mock):
|
||||||
reply_mock.attribute.return_value = 200
|
reply_mock.attribute.return_value = 200
|
||||||
reply_mock.readAll.return_value = QByteArray(b'Six sick hicks nick six slick bricks with picks and sticks.')
|
reply_mock.readAll.return_value = QByteArray(b'Six sick hicks nick six slick bricks with picks and sticks.')
|
||||||
SendMaterialJob(device_mock).run()
|
job = SendMaterialJob(device_mock)
|
||||||
reply_mock.attribute.assert_called_with(0)
|
job._onGetRemoteMaterials(reply_mock)
|
||||||
self.assertEqual(reply_mock.method_calls, [call.attribute(0), call.readAll()])
|
|
||||||
self.assertEqual(device_mock._onGetRemoteMaterials.method_calls, [])
|
# We expect the reply to be called once to try to get the printers from the list (readAll()).
|
||||||
|
# Given that the parsing there fails we do no expect the device to be called for any follow up.
|
||||||
|
self.assertEqual([call.attribute(0), call.readAll()], reply_mock.method_calls)
|
||||||
|
self.assertEqual([], device_mock.method_calls)
|
||||||
|
|
||||||
# @patch("PyQt5.QtNetwork.QNetworkReply")
|
# @patch("PyQt5.QtNetwork.QNetworkReply")
|
||||||
# def test_sendMissingMaterials_withMissingGuid(self, reply_mock):
|
# def test_sendMissingMaterials_withMissingGuid(self, reply_mock):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue