Merge branch '4.0' of github.com:Ultimaker/Cura into 4.0

This commit is contained in:
Jaime van Kessel 2019-02-19 13:35:10 +01:00
commit 80c83617bc
2 changed files with 25 additions and 5 deletions

View File

@ -61,8 +61,19 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
# \param cluster: The device response received from the cloud API. # \param cluster: The device response received from the cloud API.
# \param parent: The optional parent of this output device. # \param parent: The optional parent of this output device.
def __init__(self, api_client: CloudApiClient, cluster: CloudClusterResponse, parent: QObject = None) -> None: def __init__(self, api_client: CloudApiClient, cluster: CloudClusterResponse, parent: QObject = None) -> None:
# The following properties are expected on each networked output device.
# Because the cloud connection does not off all of these, we manually construct this version here.
# An example of why this is needed is the selection of the compatible file type when exporting the tool path.
properties = {
b"address": b"",
b"name": cluster.host_name.encode() if cluster.host_name else b"",
b"firmware_version": cluster.host_version.encode() if cluster.host_version else b"",
b"printer_type": b""
}
super().__init__(device_id = cluster.cluster_id, address = "", super().__init__(device_id = cluster.cluster_id, address = "",
connection_type = ConnectionType.CloudConnection, properties = {}, parent = parent) connection_type = ConnectionType.CloudConnection, properties = properties, parent = parent)
self._api = api_client self._api = api_client
self._cluster = cluster self._cluster = cluster

View File

@ -21,6 +21,7 @@ class TestCloudOutputDevice(TestCase):
JOB_ID = "ABCDefGHIjKlMNOpQrSTUvYxWZ0-1234567890abcDE=" JOB_ID = "ABCDefGHIjKlMNOpQrSTUvYxWZ0-1234567890abcDE="
HOST_NAME = "ultimakersystem-ccbdd30044ec" HOST_NAME = "ultimakersystem-ccbdd30044ec"
HOST_GUID = "e90ae0ac-1257-4403-91ee-a44c9b7e8050" HOST_GUID = "e90ae0ac-1257-4403-91ee-a44c9b7e8050"
HOST_VERSION = "5.2.0"
STATUS_URL = "{}/connect/v1/clusters/{}/status".format(CuraCloudAPIRoot, CLUSTER_ID) STATUS_URL = "{}/connect/v1/clusters/{}/status".format(CuraCloudAPIRoot, CLUSTER_ID)
PRINT_URL = "{}/connect/v1/clusters/{}/print/{}".format(CuraCloudAPIRoot, CLUSTER_ID, JOB_ID) PRINT_URL = "{}/connect/v1/clusters/{}/print/{}".format(CuraCloudAPIRoot, CLUSTER_ID, JOB_ID)
@ -36,7 +37,7 @@ class TestCloudOutputDevice(TestCase):
patched_method.start() patched_method.start()
self.cluster = CloudClusterResponse(self.CLUSTER_ID, self.HOST_GUID, self.HOST_NAME, is_online=True, self.cluster = CloudClusterResponse(self.CLUSTER_ID, self.HOST_GUID, self.HOST_NAME, is_online=True,
status="active") status="active", host_version=self.HOST_VERSION)
self.network = NetworkManagerMock() self.network = NetworkManagerMock()
self.account = MagicMock(isLoggedIn=True, accessToken="TestAccessToken") self.account = MagicMock(isLoggedIn=True, accessToken="TestAccessToken")
@ -56,6 +57,11 @@ class TestCloudOutputDevice(TestCase):
for patched_method in self.patches: for patched_method in self.patches:
patched_method.stop() patched_method.stop()
# We test for these in order to make sure the correct file type is selected depending on the firmware version.
def test_properties(self):
self.assertEqual(self.device.firmwareVersion, self.HOST_VERSION)
self.assertEqual(self.device.name, self.HOST_NAME)
def test_status(self): def test_status(self):
self.device._update() self.device._update()
self.network.flushReplies() self.network.flushReplies()
@ -114,7 +120,7 @@ class TestCloudOutputDevice(TestCase):
def test_print_to_cloud(self): def test_print_to_cloud(self):
active_machine_mock = self.app.getGlobalContainerStack.return_value active_machine_mock = self.app.getGlobalContainerStack.return_value
active_machine_mock.getMetaDataEntry.side_effect = {"file_formats": "application/gzip"}.get active_machine_mock.getMetaDataEntry.side_effect = {"file_formats": "application/x-ufp"}.get
request_upload_response = parseFixture("putJobUploadResponse") request_upload_response = parseFixture("putJobUploadResponse")
request_print_response = parseFixture("postJobPrintResponse") request_print_response = parseFixture("postJobPrintResponse")
@ -124,6 +130,10 @@ class TestCloudOutputDevice(TestCase):
file_handler = MagicMock() file_handler = MagicMock()
file_handler.getSupportedFileTypesWrite.return_value = [{ file_handler.getSupportedFileTypesWrite.return_value = [{
"extension": "ufp",
"mime_type": "application/x-ufp",
"mode": 2
}, {
"extension": "gcode.gz", "extension": "gcode.gz",
"mime_type": "application/gzip", "mime_type": "application/gzip",
"mode": 2, "mode": 2,
@ -137,10 +147,9 @@ class TestCloudOutputDevice(TestCase):
self.network.flushReplies() self.network.flushReplies()
self.assertEqual( self.assertEqual(
{"data": {"content_type": "application/gzip", "file_size": len(expected_mesh), "job_name": "FileName"}}, {"data": {"content_type": "application/x-ufp", "file_size": len(expected_mesh), "job_name": "FileName"}},
json.loads(self.network.getRequestBody("PUT", self.REQUEST_UPLOAD_URL).decode()) json.loads(self.network.getRequestBody("PUT", self.REQUEST_UPLOAD_URL).decode())
) )
self.assertEqual(expected_mesh, self.assertEqual(expected_mesh,
self.network.getRequestBody("PUT", request_upload_response["data"]["upload_url"])) self.network.getRequestBody("PUT", request_upload_response["data"]["upload_url"]))
self.assertIsNone(self.network.getRequestBody("POST", self.PRINT_URL)) self.assertIsNone(self.network.getRequestBody("POST", self.PRINT_URL))