59 lines
2.1 KiB
Python
59 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Live read-only tests for Media Alpha (local service)."""
|
|
import json
|
|
import unittest
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
BASE = "http://127.0.0.1:9180"
|
|
|
|
|
|
def get(path, headers=None):
|
|
req = urllib.request.Request(BASE + path, headers=headers or {})
|
|
with urllib.request.urlopen(req, timeout=10) as r:
|
|
return r.status, r.read().decode()
|
|
|
|
|
|
class Alpha(unittest.TestCase):
|
|
def test_health(self):
|
|
code, body = get("/health")
|
|
self.assertEqual(code, 200)
|
|
self.assertTrue(json.loads(body).get("jellyfin"))
|
|
|
|
def test_search_returns_real_items(self):
|
|
code, body = get("/v1/media/search?q=the")
|
|
self.assertEqual(code, 200)
|
|
data = json.loads(body)
|
|
self.assertTrue(data.get("ok"))
|
|
self.assertGreater(len(data.get("items") or []), 0)
|
|
|
|
def test_work_availability_playback(self):
|
|
_, body = get("/v1/media/search?q=the")
|
|
items = json.loads(body).get("items") or []
|
|
self.assertTrue(items)
|
|
iid = items[0]["id"]
|
|
code, body = get("/v1/media/works/" + iid)
|
|
self.assertEqual(code, 200)
|
|
self.assertTrue(json.loads(body).get("item"))
|
|
code, body = get("/v1/media/works/" + iid + "/availability")
|
|
self.assertEqual(code, 200)
|
|
self.assertTrue(json.loads(body).get("ok"))
|
|
req = urllib.request.Request(BASE + "/v1/media/playback/resolve",
|
|
data=json.dumps({"id": iid}).encode(),
|
|
headers={"Content-Type": "application/json"}, method="POST")
|
|
with urllib.request.urlopen(req, timeout=10) as r:
|
|
self.assertEqual(r.status, 200)
|
|
|
|
def test_other_email_forbidden(self):
|
|
with self.assertRaises(urllib.error.HTTPError) as ctx:
|
|
get("/", {"X-Audit-Gateway": "1", "X-Audit-User": "other@example.com"})
|
|
self.assertEqual(ctx.exception.code, 403)
|
|
|
|
def test_roman_allowed(self):
|
|
code, _ = get("/", {"X-Audit-Gateway": "1", "X-Audit-User": "maloyakapg@gmail.com"})
|
|
self.assertEqual(code, 200)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=2)
|