#!/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)