mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-11 16:57:51 -06:00
STAR-322: Testing more of the device manager
This commit is contained in:
parent
c495ade2d3
commit
75c2e25a01
3 changed files with 88 additions and 36 deletions
|
@ -11,28 +11,56 @@ from plugins.UM3NetworkPrinting.tests.Cloud.NetworkManagerMock import NetworkMan
|
|||
|
||||
@patch("cura.NetworkClient.QNetworkAccessManager")
|
||||
class TestCloudOutputDeviceManager(TestCase):
|
||||
app = CuraApplication.getInstance() or CuraApplication()
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.app.initialize()
|
||||
self.app = CuraApplication.getInstance()
|
||||
if not self.app:
|
||||
self.app = CuraApplication()
|
||||
self.app.initialize()
|
||||
|
||||
self.network = NetworkManagerMock()
|
||||
self.network.prepareGetClusters()
|
||||
self.manager = CloudOutputDeviceManager()
|
||||
self.clusters_response = self.network.prepareGetClusters()
|
||||
|
||||
## In the tear down method we check whether the state of the output device manager is what we expect based on the
|
||||
# mocked API response.
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
|
||||
def test_device(self, network_mock):
|
||||
network_mock.return_value = self.network
|
||||
|
||||
manager = CloudOutputDeviceManager()
|
||||
manager._account.loginStateChanged.emit(True)
|
||||
manager._update_timer.timeout.emit()
|
||||
|
||||
# let the network send replies
|
||||
self.network.flushReplies()
|
||||
|
||||
# get the created devices
|
||||
devices = self.app.getOutputDeviceManager().getOutputDevices()
|
||||
self.assertEqual([CloudOutputDevice], [type(d) for d in devices])
|
||||
self.assertEqual(["R0YcLJwar1ugh0ikEZsZs8NWKV6vJP_LdYsXgXqAcaNC"], [d.key for d in devices])
|
||||
self.assertEqual(["ultimakersystem-ccbdd30044ec"], [d.host_name for d in devices])
|
||||
# get the server data
|
||||
clusters = self.clusters_response["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({cluster["host_name"] for cluster in clusters}, {device.host_name for device in devices})
|
||||
|
||||
## Runs the initial request to retrieve the clusters.
|
||||
def _loadData(self, network_mock):
|
||||
network_mock.return_value = self.network
|
||||
self.manager._account.loginStateChanged.emit(True)
|
||||
self.manager._update_timer.timeout.emit()
|
||||
|
||||
def test_device_is_created(self, network_mock):
|
||||
# just create the cluster, it is checked at tearDown
|
||||
self._loadData(network_mock)
|
||||
|
||||
def test_device_is_updated(self, network_mock):
|
||||
self._loadData(network_mock)
|
||||
|
||||
# update the cluster from member variable, which is checked at tearDown
|
||||
self.clusters_response["data"][0]["host_name"] = "New host name"
|
||||
self.network.prepareGetClusters(self.clusters_response)
|
||||
|
||||
self.manager._update_timer.timeout.emit()
|
||||
|
||||
def test_device_is_removed(self, network_mock):
|
||||
self._loadData(network_mock)
|
||||
|
||||
# delete the cluster from member variable, which is checked at tearDown
|
||||
del self.clusters_response["data"][1]
|
||||
self.network.prepareGetClusters(self.clusters_response)
|
||||
|
||||
self.manager._update_timer.timeout.emit()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue