Files
buryan-infra/ops/media-alpha/tests/test_alpha.py
T
architect a9d910c743
lint / hygiene (push) Failing after 19s
lint / hygiene (pull_request) Failing after 18s
standard / check (pull_request) Successful in 8s
[ARCH] Media Alpha SSO entry and live tests 4/4
2026-11-26 23:20:31 +03:00

42 lines
1.3 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_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)