From 2e5a536effb8df7a2ee894795f0f4cf811f867d2 Mon Sep 17 00:00:00 2001 From: architect Date: Thu, 26 Nov 2026 23:46:44 +0300 Subject: [PATCH] [ARCH] Media contract: all 11 paths respond --- ops/media-alpha/tests/test_media_paths.py | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 ops/media-alpha/tests/test_media_paths.py diff --git a/ops/media-alpha/tests/test_media_paths.py b/ops/media-alpha/tests/test_media_paths.py new file mode 100644 index 0000000..79e7d22 --- /dev/null +++ b/ops/media-alpha/tests/test_media_paths.py @@ -0,0 +1,44 @@ +#!/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": 503, + "/v1/media/continue": 501, + "/v1/media/releases": 501, + "/v1/media/recommendations": 501, + } + 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) + + +if __name__ == "__main__": + unittest.main(verbosity=2)