Fix tests

This commit is contained in:
Daniel Schiavini 2019-01-15 08:20:39 +01:00
parent f478653c37
commit 77c30c891f
6 changed files with 23 additions and 21 deletions

View file

@ -5,7 +5,7 @@
# Constants used for the Cloud API # Constants used for the Cloud API
# --------- # ---------
DEFAULT_CLOUD_API_ROOT = "https://api.ultimaker.com" # type: str DEFAULT_CLOUD_API_ROOT = "https://api.ultimaker.com" # type: str
DEFAULT_CLOUD_API_VERSION = 1 # type: int DEFAULT_CLOUD_API_VERSION = "1" # type: str
DEFAULT_CLOUD_ACCOUNT_API_ROOT = "https://account.ultimaker.com" # type: str DEFAULT_CLOUD_ACCOUNT_API_ROOT = "https://account.ultimaker.com" # type: str
try: try:

View file

@ -101,7 +101,7 @@ class CloudOutputDeviceManager:
if not active_machine: if not active_machine:
return return
# Remove all output devices that we have registered. # Remove all output devices that we have registered. TODO: Why??
for stored_cluster_id in self._remote_clusters: for stored_cluster_id in self._remote_clusters:
self._output_device_manager.removeOutputDevice(stored_cluster_id) self._output_device_manager.removeOutputDevice(stored_cluster_id)

View file

@ -19,6 +19,11 @@ class CloudProgressMessage(Message):
use_inactivity_timer = False use_inactivity_timer = False
) )
## Returns a boolean indicating whether this message is currently visible
@property
def visible(self) -> bool:
return self._visible
## Shows the progress message. ## Shows the progress message.
def show(self): def show(self):
self.setProgress(0) self.setProgress(0)

View file

@ -28,7 +28,7 @@ class TestCloudApiClient(TestCase):
self.account.isLoggedIn.return_value = True self.account.isLoggedIn.return_value = True
self.network = NetworkManagerMock() self.network = NetworkManagerMock()
with patch("src.Cloud.CloudApiClient.QNetworkAccessManager", return_value = self.network): with patch("plugins.UM3NetworkPrinting.src.Cloud.CloudApiClient.QNetworkAccessManager", return_value = self.network):
self.api = CloudApiClient(self.account, self._errorHandler) self.api = CloudApiClient(self.account, self._errorHandler)
def test_getClusters(self): def test_getClusters(self):

View file

@ -41,7 +41,8 @@ class TestCloudOutputDevice(TestCase):
self.network = NetworkManagerMock() self.network = NetworkManagerMock()
self.account = MagicMock(isLoggedIn=True, accessToken="TestAccessToken") self.account = MagicMock(isLoggedIn=True, accessToken="TestAccessToken")
self.onError = MagicMock() self.onError = MagicMock()
with patch("src.Cloud.CloudApiClient.QNetworkAccessManager", return_value = self.network): with patch("plugins.UM3NetworkPrinting.src.Cloud.CloudApiClient.QNetworkAccessManager",
return_value = self.network):
self._api = CloudApiClient(self.account, self.onError) self._api = CloudApiClient(self.account, self.onError)
self.device = CloudOutputDevice(self._api, self.cluster) self.device = CloudOutputDevice(self._api, self.cluster)

View file

@ -5,7 +5,6 @@ from unittest.mock import patch, MagicMock
from UM.OutputDevice.OutputDeviceManager import OutputDeviceManager from UM.OutputDevice.OutputDeviceManager import OutputDeviceManager
from cura.UltimakerCloudAuthentication import CuraCloudAPIRoot from cura.UltimakerCloudAuthentication import CuraCloudAPIRoot
from ...src.Cloud.CloudOutputDevice import CloudOutputDevice
from ...src.Cloud.CloudOutputDeviceManager import CloudOutputDeviceManager from ...src.Cloud.CloudOutputDeviceManager import CloudOutputDeviceManager
from .Fixtures import parseFixture, readFixture from .Fixtures import parseFixture, readFixture
from .NetworkManagerMock import NetworkManagerMock, FakeSignal from .NetworkManagerMock import NetworkManagerMock, FakeSignal
@ -29,8 +28,10 @@ class TestCloudOutputDeviceManager(TestCase):
self.network = NetworkManagerMock() self.network = NetworkManagerMock()
self.timer = MagicMock(timeout = FakeSignal()) self.timer = MagicMock(timeout = FakeSignal())
with patch("src.Cloud.CloudApiClient.QNetworkAccessManager", return_value = self.network), \ with patch("plugins.UM3NetworkPrinting.src.Cloud.CloudApiClient.QNetworkAccessManager",
patch("src.Cloud.CloudOutputDeviceManager.QTimer", return_value = self.timer): return_value = self.network), \
patch("plugins.UM3NetworkPrinting.src.Cloud.CloudOutputDeviceManager.QTimer",
return_value = self.timer):
self.manager = CloudOutputDeviceManager() self.manager = CloudOutputDeviceManager()
self.clusters_response = parseFixture("getClusters") self.clusters_response = parseFixture("getClusters")
self.network.prepareReply("GET", self.URL, 200, readFixture("getClusters")) self.network.prepareReply("GET", self.URL, 200, readFixture("getClusters"))
@ -53,16 +54,12 @@ class TestCloudOutputDeviceManager(TestCase):
self.network.flushReplies() self.network.flushReplies()
# get the created devices # get the created devices
devices = self.device_manager.getOutputDevices() devices = self.device_manager.getOutputDevices()
# get the server data # TODO: Check active device
clusters = self.clusters_response.get("data", [])
self.assertEqual([CloudOutputDevice] * len(clusters), [type(d) for d in devices])
self.assertEqual({cluster["cluster_id"] for cluster in clusters}, {device.key for device in devices})
self.assertEqual(clusters, sorted((device.clusterData.toDict() for device in devices),
key=lambda device_dict: device_dict["host_version"]))
for device in clusters: response_clusters = self.clusters_response.get("data", [])
self.device_manager.getOutputDevice(device["cluster_id"]).close() manager_clusters = sorted([device.clusterData.toDict() for device in self.manager._remote_clusters.values()],
self.device_manager.removeOutputDevice(device["cluster_id"]) key=lambda cluster: cluster['cluster_id'], reverse=True)
self.assertEqual(response_clusters, manager_clusters)
## Runs the initial request to retrieve the clusters. ## Runs the initial request to retrieve the clusters.
def _loadData(self): def _loadData(self):
@ -100,7 +97,7 @@ class TestCloudOutputDeviceManager(TestCase):
self._loadData() self._loadData()
self.assertTrue(self.device_manager.getOutputDevice(cluster1["cluster_id"]).isConnected()) self.assertTrue(self.device_manager.getOutputDevice(cluster1["cluster_id"]).isConnected())
self.assertFalse(self.device_manager.getOutputDevice(cluster2["cluster_id"]).isConnected()) self.assertIsNone(self.device_manager.getOutputDevice(cluster2["cluster_id"]))
self.assertEquals([], active_machine_mock.setMetaDataEntry.mock_calls) self.assertEquals([], active_machine_mock.setMetaDataEntry.mock_calls)
def test_device_connects_by_network_key(self): def test_device_connects_by_network_key(self):
@ -112,13 +109,12 @@ class TestCloudOutputDeviceManager(TestCase):
self._loadData() self._loadData()
self.assertEqual([False, True], self.assertIsNone(self.device_manager.getOutputDevice(cluster1["cluster_id"]))
[self.device_manager.getOutputDevice(cluster["cluster_id"]).isConnected() self.assertTrue(self.device_manager.getOutputDevice(cluster2["cluster_id"]).isConnected())
for cluster in (cluster1, cluster2)])
active_machine_mock.setMetaDataEntry.assert_called_with("um_cloud_cluster_id", cluster2["cluster_id"]) active_machine_mock.setMetaDataEntry.assert_called_with("um_cloud_cluster_id", cluster2["cluster_id"])
@patch("src.Cloud.CloudOutputDeviceManager.Message") @patch("plugins.UM3NetworkPrinting.src.Cloud.CloudOutputDeviceManager.Message")
def test_api_error(self, message_mock): def test_api_error(self, message_mock):
self.clusters_response = { self.clusters_response = {
"errors": [{"id": "notFound", "title": "Not found!", "http_status": "404", "code": "notFound"}] "errors": [{"id": "notFound", "title": "Not found!", "http_status": "404", "code": "notFound"}]