TestDiscoveredCloudPrintersModel.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. from unittest.mock import MagicMock
  2. import pytest
  3. from cura.Machines.Models.DiscoveredCloudPrintersModel import DiscoveredCloudPrintersModel
  4. @pytest.fixture()
  5. def discovered_cloud_printers_model(application) -> DiscoveredCloudPrintersModel:
  6. return DiscoveredCloudPrintersModel(application)
  7. def test_discoveredCloudPrinters(discovered_cloud_printers_model):
  8. new_devices = [{
  9. "key": "Bite my shiny metal a$$",
  10. "name": "Bender",
  11. "machine_type": "Bender robot",
  12. "firmware_version": "8.0.0.8.5"
  13. }]
  14. discovered_cloud_printers_model.cloudPrintersDetectedChanged = MagicMock()
  15. # Test if adding a cloud printer in the model works
  16. discovered_cloud_printers_model.addDiscoveredCloudPrinters(new_devices)
  17. assert len(discovered_cloud_printers_model._discovered_cloud_printers_list) == 1
  18. assert discovered_cloud_printers_model.cloudPrintersDetectedChanged.emit.call_count == 1
  19. # Make sure that the signal was called with "True" as input
  20. discovered_cloud_printers_model.cloudPrintersDetectedChanged.emit.assert_called_with(True)
  21. # Test if clearing the model works
  22. discovered_cloud_printers_model.clear()
  23. assert len(discovered_cloud_printers_model._discovered_cloud_printers_list) == 0
  24. assert discovered_cloud_printers_model.cloudPrintersDetectedChanged.emit.call_count == 2
  25. # Make sure that the signal was called with "False" as input
  26. discovered_cloud_printers_model.cloudPrintersDetectedChanged.emit.assert_called_with(False)