2020-03-03 14:50:57 +00:00
|
|
|
import json
|
|
|
|
import urllib.error
|
|
|
|
import urllib.request
|
|
|
|
import zipfile
|
2022-01-28 15:02:17 +00:00
|
|
|
from pathlib import Path
|
2020-03-03 14:50:57 +00:00
|
|
|
from typing import Dict
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
RECORDS_WEBSITE = "https://firmware.corp.sldev.cz/ui_tests/"
|
|
|
|
FIXTURES_MASTER = "https://raw.githubusercontent.com/trezor/trezor-firmware/master/tests/ui_tests/fixtures.json"
|
2022-01-28 15:02:17 +00:00
|
|
|
FIXTURES_CURRENT = Path(__file__).resolve().parent.parent / "fixtures.json"
|
2020-03-03 14:50:57 +00:00
|
|
|
|
2021-06-21 11:55:26 +00:00
|
|
|
_dns_failed = False
|
|
|
|
|
2020-03-03 14:50:57 +00:00
|
|
|
|
2022-01-28 18:26:03 +00:00
|
|
|
def fetch_recorded(hash: str, path: Path) -> None:
|
2021-06-21 11:55:26 +00:00
|
|
|
global _dns_failed
|
|
|
|
|
|
|
|
if _dns_failed:
|
|
|
|
raise RuntimeError("Not trying firmware.corp.sldev.cz again after DNS failure.")
|
|
|
|
|
2020-03-03 14:50:57 +00:00
|
|
|
zip_src = RECORDS_WEBSITE + hash + ".zip"
|
|
|
|
zip_dest = path / "recorded.zip"
|
|
|
|
|
|
|
|
try:
|
|
|
|
urllib.request.urlretrieve(zip_src, zip_dest)
|
|
|
|
except urllib.error.HTTPError:
|
2021-09-27 10:13:51 +00:00
|
|
|
raise RuntimeError(f"No such recorded collection was found on '{zip_src}'.")
|
2020-03-03 14:50:57 +00:00
|
|
|
except urllib.error.URLError:
|
2021-06-21 11:55:26 +00:00
|
|
|
_dns_failed = True
|
2020-03-03 14:50:57 +00:00
|
|
|
raise RuntimeError(
|
|
|
|
"Server firmware.corp.sldev.cz could not be found. Are you on VPN?"
|
|
|
|
)
|
|
|
|
|
|
|
|
with zipfile.ZipFile(zip_dest, "r") as z:
|
|
|
|
z.extractall(path)
|
|
|
|
|
|
|
|
zip_dest.unlink()
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_fixtures_master() -> Dict[str, str]:
|
|
|
|
r = requests.get(FIXTURES_MASTER)
|
|
|
|
r.raise_for_status()
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_fixtures_current() -> Dict[str, str]:
|
|
|
|
with open(FIXTURES_CURRENT) as f:
|
|
|
|
return json.loads(f.read())
|