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
|
|
|
|
|
2022-03-22 11:12:11 +00:00
|
|
|
RECORDS_WEBSITE = "https://data.trezor.io/dev/firmware/ui_tests/"
|
2020-03-03 14:50:57 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2022-01-28 18:26:03 +00:00
|
|
|
def fetch_recorded(hash: str, path: Path) -> None:
|
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
|
|
|
|
|
|
|
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())
|