TestFirmwareUpdateChecker.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import pytest
  4. from unittest.mock import MagicMock
  5. from UM.Version import Version
  6. import FirmwareUpdateChecker
  7. json_data = \
  8. {
  9. "ned":
  10. {
  11. "id": 1,
  12. "name": "ned",
  13. "check_urls": [""],
  14. "update_url": "https://ultimaker.com/en/resources/20500-upgrade-firmware",
  15. "version_parser": "default"
  16. },
  17. "olivia":
  18. {
  19. "id": 3,
  20. "name": "olivia",
  21. "check_urls": [""],
  22. "update_url": "https://ultimaker.com/en/resources/20500-upgrade-firmware",
  23. "version_parser": "default"
  24. },
  25. "emmerson":
  26. {
  27. "id": 5,
  28. "name": "emmerson",
  29. "check_urls": [""],
  30. "update_url": "https://ultimaker.com/en/resources/20500-upgrade-firmware",
  31. "version_parser": "default"
  32. }
  33. }
  34. @pytest.mark.parametrize("name, id", [
  35. ("ned" , 1),
  36. ("olivia" , 3),
  37. ("emmerson", 5),
  38. ])
  39. def test_FirmwareUpdateCheckerLookup(id, name):
  40. lookup = FirmwareUpdateChecker.FirmwareUpdateCheckerLookup.FirmwareUpdateCheckerLookup(name, json_data.get(name))
  41. assert lookup.getMachineName() == name
  42. assert lookup.getMachineId() == id
  43. assert len(lookup.getCheckUrls()) >= 1
  44. assert lookup.getRedirectUserUrl() is not None
  45. @pytest.mark.parametrize("name, version", [
  46. ("ned" , Version("5.1.2.3")),
  47. ("olivia" , Version("4.3.2.1")),
  48. ("emmerson", Version("6.7.8.1")),
  49. ])
  50. def test_FirmwareUpdateCheckerJob_getCurrentVersion(name, version):
  51. machine_data = json_data.get(name)
  52. job = FirmwareUpdateChecker.FirmwareUpdateCheckerJob.FirmwareUpdateCheckerJob(False, name, machine_data, MagicMock)
  53. job.getUrlResponse = MagicMock(return_value = str(version)) # Pretend like we got a good response from the server
  54. assert job.getCurrentVersion() == version