mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Fix tests
This commit is contained in:
parent
f478653c37
commit
77c30c891f
6 changed files with 23 additions and 21 deletions
|
@ -5,7 +5,7 @@
|
|||
# Constants used for the Cloud API
|
||||
# ---------
|
||||
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
|
||||
|
||||
try:
|
||||
|
|
|
@ -101,7 +101,7 @@ class CloudOutputDeviceManager:
|
|||
if not active_machine:
|
||||
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:
|
||||
self._output_device_manager.removeOutputDevice(stored_cluster_id)
|
||||
|
||||
|
|
|
@ -19,6 +19,11 @@ class CloudProgressMessage(Message):
|
|||
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.
|
||||
def show(self):
|
||||
self.setProgress(0)
|
||||
|
|
|
@ -28,7 +28,7 @@ class TestCloudApiClient(TestCase):
|
|||
self.account.isLoggedIn.return_value = True
|
||||
|
||||
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)
|
||||
|
||||
def test_getClusters(self):
|
||||
|
|
|
@ -41,7 +41,8 @@ class TestCloudOutputDevice(TestCase):
|
|||
self.network = NetworkManagerMock()
|
||||
self.account = MagicMock(isLoggedIn=True, accessToken="TestAccessToken")
|
||||
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.device = CloudOutputDevice(self._api, self.cluster)
|
||||
|
|
|
@ -5,7 +5,6 @@ from unittest.mock import patch, MagicMock
|
|||
|
||||
from UM.OutputDevice.OutputDeviceManager import OutputDeviceManager
|
||||
from cura.UltimakerCloudAuthentication import CuraCloudAPIRoot
|
||||
from ...src.Cloud.CloudOutputDevice import CloudOutputDevice
|
||||
from ...src.Cloud.CloudOutputDeviceManager import CloudOutputDeviceManager
|
||||
from .Fixtures import parseFixture, readFixture
|
||||
from .NetworkManagerMock import NetworkManagerMock, FakeSignal
|
||||
|
@ -29,8 +28,10 @@ class TestCloudOutputDeviceManager(TestCase):
|
|||
|
||||
self.network = NetworkManagerMock()
|
||||
self.timer = MagicMock(timeout = FakeSignal())
|
||||
with patch("src.Cloud.CloudApiClient.QNetworkAccessManager", return_value = self.network), \
|
||||
patch("src.Cloud.CloudOutputDeviceManager.QTimer", return_value = self.timer):
|
||||
with patch("plugins.UM3NetworkPrinting.src.Cloud.CloudApiClient.QNetworkAccessManager",
|
||||
return_value = self.network), \
|
||||
patch("plugins.UM3NetworkPrinting.src.Cloud.CloudOutputDeviceManager.QTimer",
|
||||
return_value = self.timer):
|
||||
self.manager = CloudOutputDeviceManager()
|
||||
self.clusters_response = parseFixture("getClusters")
|
||||
self.network.prepareReply("GET", self.URL, 200, readFixture("getClusters"))
|
||||
|
@ -53,16 +54,12 @@ class TestCloudOutputDeviceManager(TestCase):
|
|||
self.network.flushReplies()
|
||||
# get the created devices
|
||||
devices = self.device_manager.getOutputDevices()
|
||||
# get the server data
|
||||
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"]))
|
||||
# TODO: Check active device
|
||||
|
||||
for device in clusters:
|
||||
self.device_manager.getOutputDevice(device["cluster_id"]).close()
|
||||
self.device_manager.removeOutputDevice(device["cluster_id"])
|
||||
response_clusters = self.clusters_response.get("data", [])
|
||||
manager_clusters = sorted([device.clusterData.toDict() for device in self.manager._remote_clusters.values()],
|
||||
key=lambda cluster: cluster['cluster_id'], reverse=True)
|
||||
self.assertEqual(response_clusters, manager_clusters)
|
||||
|
||||
## Runs the initial request to retrieve the clusters.
|
||||
def _loadData(self):
|
||||
|
@ -100,7 +97,7 @@ class TestCloudOutputDeviceManager(TestCase):
|
|||
self._loadData()
|
||||
|
||||
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)
|
||||
|
||||
def test_device_connects_by_network_key(self):
|
||||
|
@ -112,13 +109,12 @@ class TestCloudOutputDeviceManager(TestCase):
|
|||
|
||||
self._loadData()
|
||||
|
||||
self.assertEqual([False, True],
|
||||
[self.device_manager.getOutputDevice(cluster["cluster_id"]).isConnected()
|
||||
for cluster in (cluster1, cluster2)])
|
||||
self.assertIsNone(self.device_manager.getOutputDevice(cluster1["cluster_id"]))
|
||||
self.assertTrue(self.device_manager.getOutputDevice(cluster2["cluster_id"]).isConnected())
|
||||
|
||||
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):
|
||||
self.clusters_response = {
|
||||
"errors": [{"id": "notFound", "title": "Not found!", "http_status": "404", "code": "notFound"}]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue