def test__onGetRemoteMaterials_withUpdatedMaterial(self, get_instance_mock): reply_mock = MagicMock() device_mock = MagicMock() application_mock = get_instance_mock.return_value container_registry_mock = application_mock.getContainerRegistry.return_value material_manager_mock = application_mock.getMaterialManager.return_value container_registry_mock.getContainerFilePathById = lambda x: _FILES_MAP.get( x) device_mock.createFormPart.return_value = "_xXx_" material_manager_mock.getAllMaterialGroups.return_value = self._LOCAL_MATERIAL_WHITE_NEWER_ALL_RESULT.copy( ) reply_mock.attribute.return_value = 200 reply_mock.readAll.return_value = QByteArray( json.dumps([self._REMOTE_MATERIAL_WHITE]).encode("ascii")) job = SendMaterialJob(device_mock) job._onGetRemoteMaterials(reply_mock) self.assertEqual(1, device_mock.createFormPart.call_count) self.assertEqual(1, device_mock.postFormWithParts.call_count) self.assertEqual([ call.createFormPart( "name=\"file\"; filename=\"generic_pla_white.xml.fdm_material\"", "<xml></xml>"), call.postFormWithParts(target="materials/", parts=["_xXx_"], on_finished=job.sendingFinished) ], device_mock.method_calls)
def test__onGetRemoteMaterials_withNewMaterial(self, application_mock, container_registry_mock, reply_mock, device_mock): application_mock.getContainerRegistry.return_value = container_registry_mock device_mock.createFormPart.return_value = "_xXx_" container_registry_mock.findContainersMetadata.return_value = [ self._LOCAL_MATERIAL_WHITE, self._LOCAL_MATERIAL_BLACK ] reply_mock.attribute.return_value = 200 reply_mock.readAll.return_value = QByteArray( json.dumps([self._REMOTE_MATERIAL_BLACK]).encode("ascii")) with mock.patch.object(Application, "getInstance", new=lambda: application_mock): job = SendMaterialJob(device_mock) job._onGetRemoteMaterials(reply_mock) self.assertEqual(1, device_mock.createFormPart.call_count) self.assertEqual(1, device_mock.postFormWithParts.call_count) self.assertEquals([ call.createFormPart( "name=\"file\"; filename=\"generic_pla_white.xml.fdm_material\"", "<xml></xml>"), call.postFormWithParts(target="materials/", parts=["_xXx_"], on_finished=job.sendingFinished) ], device_mock.method_calls)
def test__onGetRemoteMaterials_withNewMaterial(self, application_mock): reply_mock = MagicMock() device_mock = MagicMock() container_registry_mock = application_mock.getContainerRegistry.return_value material_manager_mock = application_mock.getMaterialManager.return_value container_registry_mock.getContainerFilePathById = lambda x: _FILES_MAP.get(x) device_mock.createFormPart.return_value = "_xXx_" all_results = self._LOCAL_MATERIAL_WHITE_ALL_RESULT.copy() for key, value in self._LOCAL_MATERIAL_BLACK_ALL_RESULT.items(): all_results[key] = value material_manager_mock.getAllMaterialGroups.return_value = all_results reply_mock.attribute.return_value = 200 reply_mock.readAll.return_value = QByteArray(json.dumps([self._REMOTE_MATERIAL_BLACK]).encode("ascii")) with mock.patch.object(Application, "getInstance", new = lambda: application_mock): job = SendMaterialJob(device_mock) job._onGetRemoteMaterials(reply_mock) self.assertEqual(1, device_mock.createFormPart.call_count) self.assertEqual(1, device_mock.postFormWithParts.call_count) self.assertEqual( [call.createFormPart("name=\"file\"; filename=\"generic_pla_white.xml.fdm_material\"", "<xml></xml>"), call.postFormWithParts(target = "materials/", parts = ["_xXx_"], on_finished = job.sendingFinished)], device_mock.method_calls)
def test__onGetRemoteMaterials_withNewMaterial(self, application_mock, container_registry_mock, reply_mock, device_mock): application_mock.getContainerRegistry.return_value = container_registry_mock device_mock.createFormPart.return_value = "_xXx_" container_registry_mock.findContainersMetadata.return_value = [self._LOCAL_MATERIAL_WHITE, self._LOCAL_MATERIAL_BLACK] reply_mock.attribute.return_value = 200 reply_mock.readAll.return_value = QByteArray(json.dumps([self._REMOTE_MATERIAL_BLACK]).encode("ascii")) with mock.patch.object(Application, "getInstance", new = lambda: application_mock): job = SendMaterialJob(device_mock) job._onGetRemoteMaterials(reply_mock) self.assertEqual(1, device_mock.createFormPart.call_count) self.assertEqual(1, device_mock.postFormWithParts.call_count) self.assertEquals( [call.createFormPart("name=\"file\"; filename=\"generic_pla_white.xml.fdm_material\"", "<xml></xml>"), call.postFormWithParts(target = "materials/", parts = ["_xXx_"], on_finished = job.sendingFinished)], device_mock.method_calls)