mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
Fix the tests so they don't rely on external URL
This commit is contained in:
parent
f5c4b6919d
commit
909c74c9b6
3 changed files with 7 additions and 14 deletions
|
@ -44,7 +44,6 @@ class FirmwareUpdateCheckerJob(Job):
|
|||
result = response.read().decode("utf-8")
|
||||
except URLError:
|
||||
Logger.log("w", "Could not reach '{0}', if this URL is old, consider removal.".format(url))
|
||||
|
||||
return result
|
||||
|
||||
def parseVersionResponse(self, response: str) -> Version:
|
||||
|
|
|
@ -18,7 +18,7 @@ class FirmwareUpdateCheckerLookup:
|
|||
self._machine_id = machine_json.get("id")
|
||||
self._machine_name = machine_name.lower() # Lower in-case upper-case chars are added to the original json.
|
||||
self._check_urls = [] # type:List[str]
|
||||
for check_url in machine_json.get("check_urls"):
|
||||
for check_url in machine_json.get("check_urls", []):
|
||||
self._check_urls.append(check_url)
|
||||
self._redirect_user = machine_json.get("update_url")
|
||||
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
import pytest
|
||||
import json
|
||||
|
||||
import unittest.mock
|
||||
from cura.CuraApplication import CuraApplication
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from UM.Version import Version
|
||||
|
||||
|
@ -18,7 +16,7 @@ json_data = \
|
|||
{
|
||||
"id": 1,
|
||||
"name": "ned",
|
||||
"check_urls": ["http://urlecho.appspot.com/echo?status=200&body=5.1.2.3"],
|
||||
"check_urls": [""],
|
||||
"update_url": "https://ultimaker.com/en/resources/20500-upgrade-firmware",
|
||||
"version_parser": "default"
|
||||
},
|
||||
|
@ -26,7 +24,7 @@ json_data = \
|
|||
{
|
||||
"id": 3,
|
||||
"name": "olivia",
|
||||
"check_urls": ["http://urlecho.appspot.com/echo?status=200&body=4.3.2.1", "https://this-url-clearly-doesnt-exist.net"],
|
||||
"check_urls": [""],
|
||||
"update_url": "https://ultimaker.com/en/resources/20500-upgrade-firmware",
|
||||
"version_parser": "default"
|
||||
},
|
||||
|
@ -34,15 +32,12 @@ json_data = \
|
|||
{
|
||||
"id": 5,
|
||||
"name": "emmerson",
|
||||
"check_urls": ["http://urlecho.appspot.com/echo?status=200&body=0.2.2.2", "http://urlecho.appspot.com/echo?status=200&body=6.7.8.1"],
|
||||
"check_urls": [""],
|
||||
"update_url": "https://ultimaker.com/en/resources/20500-upgrade-firmware",
|
||||
"version_parser": "default"
|
||||
}
|
||||
}
|
||||
|
||||
def dummyCallback():
|
||||
pass
|
||||
|
||||
@pytest.mark.parametrize("name, id", [
|
||||
("ned" , 1),
|
||||
("olivia" , 3),
|
||||
|
@ -63,7 +58,6 @@ def test_FirmwareUpdateCheckerLookup(id, name):
|
|||
])
|
||||
def test_FirmwareUpdateCheckerJob_getCurrentVersion(name, version):
|
||||
machine_data = json_data.get(name)
|
||||
job = FirmwareUpdateCheckerJob(False, name, machine_data, dummyCallback)
|
||||
job._headers = {"User-Agent": "Cura-UnitTests 0"}
|
||||
|
||||
job = FirmwareUpdateCheckerJob(False, name, machine_data, MagicMock)
|
||||
job.getUrlResponse = MagicMock(return_value = str(version)) # Pretend like we got a good response from the server
|
||||
assert job.getCurrentVersion() == version
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue