Files
buryan-infra/ops/media-alpha/tests/test_media_paths.py
T
architect e4735e7323
lint / hygiene (pull_request) Failing after 38s
standard / check (pull_request) Successful in 15s
lint / hygiene (push) Failing after 33s
standard / check (push) Successful in 15s
[ARCH] Media releases from Radarr; 9/10 functional
2026-11-27 10:15:58 +03:00

66 lines
2.4 KiB
Python

#!/usr/bin/env python3
import json, unittest, urllib.request, urllib.error
BASE = "http://127.0.0.1:9180"
def get(path, method="GET", body=None):
data = json.dumps(body).encode() if body is not None else None
h = {"Content-Type": "application/json"} if body is not None else {}
r = urllib.request.Request(BASE + path, data=data, headers=h, method=method)
try:
with urllib.request.urlopen(r, timeout=10) as resp:
return resp.status, json.loads(resp.read().decode() or "{}")
except urllib.error.HTTPError as e:
return e.code, {}
class MediaPaths(unittest.TestCase):
def test_all_contract_paths(self):
_, d = get("/v1/media/search?q=the")
items = d.get("items") or []
self.assertTrue(items)
iid = items[0]["id"]
expected = {
"/v1/media/search?q=the": 200,
"/v1/media/recent": 200,
"/v1/me": 200,
"/v1/media/works/" + iid: 200,
"/v1/media/works/" + iid + "/availability": 200,
"/v1/media/works/" + iid + "/editions": 200,
"/v1/media/requests": 200,
"/v1/media/continue": 200,
"/v1/media/releases": 200,
"/v1/media/recommendations": 503,
}
for path, want in expected.items():
code, _ = get(path)
self.assertEqual(code, want, path)
code, _ = get("/v1/media/playback/resolve", "POST", {"id": iid})
self.assertEqual(code, 200)
def test_home_status(self):
code, d = get("/v1/home/status")
self.assertEqual(code, 200)
self.assertEqual(d.get("jellyfin"), "ok")
self.assertIn("prism", d)
self.assertIn("pending_tasks", d.get("prism") or {})
def test_idempotent_reads_and_resolve(self):
_, a = get("/v1/media/search?q=the")
_, b = get("/v1/media/search?q=the")
self.assertEqual([x["id"] for x in a.get("items") or []],
[x["id"] for x in b.get("items") or []])
iid = (a.get("items") or [{}])[0]["id"]
_, w1 = get("/v1/media/works/" + iid)
_, w2 = get("/v1/media/works/" + iid)
self.assertEqual(w1, w2)
_, p1 = get("/v1/media/playback/resolve", "POST", {"id": iid})
_, p2 = get("/v1/media/playback/resolve", "POST", {"id": iid})
self.assertEqual(p1, p2)
self.assertIn("/details?id=", p1.get("url", ""))
if __name__ == "__main__":
unittest.main(verbosity=2)