Files
buryan-infra/ops/audit/tests/test_media_contract.py
T
architect 7e079e74e8
lint / hygiene (push) Failing after 24s
standard / check (push) Successful in 11s
lint / hygiene (pull_request) Failing after 28s
standard / check (pull_request) Successful in 11s
[ARCH] Media API structural contract tests: 5 pass
2026-11-26 21:59:25 +03:00

56 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Structural contract checks for Media API. No live API yet."""
import unittest
from pathlib import Path
ROOT = Path("/root/buryan-infra")
CONTRACT = ROOT / "docs/architecture/CONTRACTS/media-api.yaml"
class MediaContract(unittest.TestCase):
@classmethod
def setUpClass(cls):
try:
import yaml
except Exception as e:
raise unittest.SkipTest("pyyaml missing: %s" % e)
cls.spec = yaml.safe_load(CONTRACT.read_text(encoding="utf-8"))
def test_openapi_version(self):
self.assertTrue(str(self.spec.get("openapi", "")).startswith("3."))
def test_required_paths(self):
paths = self.spec.get("paths") or {}
required = {
"/v1/media/search",
"/v1/media/works/{id}",
"/v1/media/works/{id}/editions",
"/v1/media/works/{id}/availability",
"/v1/media/requests",
"/v1/media/requests/{id}",
"/v1/media/continue",
"/v1/media/releases",
"/v1/media/playback/resolve",
"/v1/media/recommendations",
}
self.assertEqual(required - set(paths), set())
def test_oidc(self):
schemes = (self.spec.get("components") or {}).get("securitySchemes") or {}
self.assertIn("authentik", schemes)
self.assertEqual(schemes["authentik"].get("type"), "openIdConnect")
def test_idempotency_header(self):
post = self.spec["paths"]["/v1/media/requests"]["post"]
params = post.get("parameters") or []
self.assertTrue(any(p.get("name") == "Idempotency-Key" for p in params))
def test_no_bearer_literals(self):
text = CONTRACT.read_text(encoding="utf-8")
for bad in ("sk-", "ghp_", "AIza", "Bearer ey"):
self.assertNotIn(bad, text)
if __name__ == "__main__":
unittest.main(verbosity=2)