[skip ci] fix ots
This commit is contained in:
3 files changed
+107
-6
No files matched your search
@@ -8,6 +8,7 @@ import zipfile
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from app.config import env_settings
|
||||
from app.services import android_updates
|
||||
|
||||
@@ -200,3 +201,63 @@ def test_the_route_reports_503_when_updates_are_not_configured(client, monkeypat
|
||||
|
||||
assert response.status_code == 503
|
||||
assert "GITEA_TOKEN" in response.json()["detail"]
|
||||
|
||||
|
||||
def test_sparse_artifact_run_metadata_is_fetched_from_the_run(monkeypatch):
|
||||
_configure(monkeypatch)
|
||||
metadata = _artifact(31, run_id=401, run_number=0, branch="", conclusion="")
|
||||
metadata["workflow_run"] = {"id": 401, "head_sha": "sha-88"}
|
||||
apk = _artifact(
|
||||
32,
|
||||
run_id=401,
|
||||
run_number=0,
|
||||
name=android_updates.APK_ARTIFACT,
|
||||
branch="",
|
||||
conclusion="",
|
||||
)
|
||||
apk["workflow_run"] = {"id": 401, "head_sha": "sha-88"}
|
||||
zips = {
|
||||
31: _zip({"update.json": _metadata_body(88, "0.1.0-master.88")}),
|
||||
32: _zip({"app-release.apk": b"sparse apk"}),
|
||||
}
|
||||
run_requests = 0
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
nonlocal run_requests
|
||||
if request.url.path.endswith("/actions/artifacts"):
|
||||
name = request.url.params.get("name")
|
||||
return httpx.Response(
|
||||
200,
|
||||
json={
|
||||
"total_count": 1,
|
||||
"artifacts": [metadata]
|
||||
if name == android_updates.METADATA_ARTIFACT
|
||||
else [apk],
|
||||
},
|
||||
)
|
||||
if request.url.path.endswith("/actions/runs/401"):
|
||||
run_requests += 1
|
||||
return httpx.Response(
|
||||
200,
|
||||
json={
|
||||
"id": 401,
|
||||
"run_number": 88,
|
||||
"head_branch": "master",
|
||||
"head_sha": "sha-88",
|
||||
"conclusion": "success",
|
||||
},
|
||||
)
|
||||
artifact_id = int(request.url.path.rstrip("/").split("/")[-2])
|
||||
return httpx.Response(200, content=zips[artifact_id])
|
||||
|
||||
_install_transport(monkeypatch, handler)
|
||||
|
||||
metadata = android_updates.latest_android()
|
||||
assert metadata["version_code"] == 88
|
||||
assert metadata["version_name"] == "0.1.0-master.88"
|
||||
assert metadata["commit"] == "sha-88"
|
||||
assert run_requests == 1
|
||||
|
||||
path, same = android_updates.android_apk()
|
||||
assert path.read_bytes() == b"sparse apk"
|
||||
assert same == metadata
|
||||
Reference in new issue
Block a user