|
0981a08…
|
noreply
|
1 |
"""Tests for video_processor.api.openapi_spec.""" |
|
0981a08…
|
noreply
|
2 |
|
|
0981a08…
|
noreply
|
3 |
from video_processor.api.openapi_spec import get_openapi_spec |
|
0981a08…
|
noreply
|
4 |
|
|
0981a08…
|
noreply
|
5 |
|
|
0981a08…
|
noreply
|
6 |
def test_returns_dict(): |
|
0981a08…
|
noreply
|
7 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
8 |
assert isinstance(spec, dict) |
|
0981a08…
|
noreply
|
9 |
|
|
0981a08…
|
noreply
|
10 |
|
|
0981a08…
|
noreply
|
11 |
def test_has_top_level_keys(): |
|
0981a08…
|
noreply
|
12 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
13 |
for key in ("openapi", "info", "paths", "components"): |
|
0981a08…
|
noreply
|
14 |
assert key in spec, f"Missing top-level key: {key}" |
|
0981a08…
|
noreply
|
15 |
|
|
0981a08…
|
noreply
|
16 |
|
|
0981a08…
|
noreply
|
17 |
def test_openapi_version(): |
|
0981a08…
|
noreply
|
18 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
19 |
assert spec["openapi"].startswith("3.0") |
|
0981a08…
|
noreply
|
20 |
|
|
0981a08…
|
noreply
|
21 |
|
|
0981a08…
|
noreply
|
22 |
def test_info_section(): |
|
0981a08…
|
noreply
|
23 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
24 |
info = spec["info"] |
|
0981a08…
|
noreply
|
25 |
assert "title" in info |
|
0981a08…
|
noreply
|
26 |
assert "version" in info |
|
0981a08…
|
noreply
|
27 |
assert "PlanOpticon" in info["title"] |
|
0981a08…
|
noreply
|
28 |
|
|
0981a08…
|
noreply
|
29 |
|
|
0981a08…
|
noreply
|
30 |
def test_expected_paths(): |
|
0981a08…
|
noreply
|
31 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
32 |
expected_paths = [ |
|
0981a08…
|
noreply
|
33 |
"/analyze", |
|
0981a08…
|
noreply
|
34 |
"/jobs/{id}", |
|
0981a08…
|
noreply
|
35 |
"/knowledge-graph/{id}/entities", |
|
0981a08…
|
noreply
|
36 |
"/knowledge-graph/{id}/relationships", |
|
0981a08…
|
noreply
|
37 |
"/knowledge-graph/{id}/query", |
|
0981a08…
|
noreply
|
38 |
] |
|
0981a08…
|
noreply
|
39 |
for path in expected_paths: |
|
0981a08…
|
noreply
|
40 |
assert path in spec["paths"], f"Missing path: {path}" |
|
0981a08…
|
noreply
|
41 |
|
|
0981a08…
|
noreply
|
42 |
|
|
0981a08…
|
noreply
|
43 |
def test_analyze_endpoint(): |
|
0981a08…
|
noreply
|
44 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
45 |
analyze = spec["paths"]["/analyze"] |
|
0981a08…
|
noreply
|
46 |
assert "post" in analyze |
|
0981a08…
|
noreply
|
47 |
post = analyze["post"] |
|
0981a08…
|
noreply
|
48 |
assert "summary" in post |
|
0981a08…
|
noreply
|
49 |
assert "requestBody" in post |
|
0981a08…
|
noreply
|
50 |
assert "responses" in post |
|
0981a08…
|
noreply
|
51 |
assert "202" in post["responses"] |
|
0981a08…
|
noreply
|
52 |
|
|
0981a08…
|
noreply
|
53 |
|
|
0981a08…
|
noreply
|
54 |
def test_jobs_endpoint(): |
|
0981a08…
|
noreply
|
55 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
56 |
jobs = spec["paths"]["/jobs/{id}"] |
|
0981a08…
|
noreply
|
57 |
assert "get" in jobs |
|
0981a08…
|
noreply
|
58 |
get = jobs["get"] |
|
0981a08…
|
noreply
|
59 |
assert "parameters" in get |
|
0981a08…
|
noreply
|
60 |
assert get["parameters"][0]["name"] == "id" |
|
0981a08…
|
noreply
|
61 |
|
|
0981a08…
|
noreply
|
62 |
|
|
0981a08…
|
noreply
|
63 |
def test_entities_endpoint(): |
|
0981a08…
|
noreply
|
64 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
65 |
entities = spec["paths"]["/knowledge-graph/{id}/entities"] |
|
0981a08…
|
noreply
|
66 |
assert "get" in entities |
|
0981a08…
|
noreply
|
67 |
|
|
0981a08…
|
noreply
|
68 |
|
|
0981a08…
|
noreply
|
69 |
def test_relationships_endpoint(): |
|
0981a08…
|
noreply
|
70 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
71 |
rels = spec["paths"]["/knowledge-graph/{id}/relationships"] |
|
0981a08…
|
noreply
|
72 |
assert "get" in rels |
|
0981a08…
|
noreply
|
73 |
|
|
0981a08…
|
noreply
|
74 |
|
|
0981a08…
|
noreply
|
75 |
def test_query_endpoint(): |
|
0981a08…
|
noreply
|
76 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
77 |
query = spec["paths"]["/knowledge-graph/{id}/query"] |
|
0981a08…
|
noreply
|
78 |
assert "get" in query |
|
0981a08…
|
noreply
|
79 |
params = query["get"]["parameters"] |
|
0981a08…
|
noreply
|
80 |
param_names = [p["name"] for p in params] |
|
0981a08…
|
noreply
|
81 |
assert "q" in param_names |
|
0981a08…
|
noreply
|
82 |
|
|
0981a08…
|
noreply
|
83 |
|
|
0981a08…
|
noreply
|
84 |
def test_component_schemas(): |
|
0981a08…
|
noreply
|
85 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
86 |
schemas = spec["components"]["schemas"] |
|
0981a08…
|
noreply
|
87 |
for schema_name in ("Job", "Entity", "Relationship"): |
|
0981a08…
|
noreply
|
88 |
assert schema_name in schemas, f"Missing schema: {schema_name}" |
|
0981a08…
|
noreply
|
89 |
|
|
0981a08…
|
noreply
|
90 |
|
|
0981a08…
|
noreply
|
91 |
def test_job_schema_properties(): |
|
0981a08…
|
noreply
|
92 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
93 |
job = spec["components"]["schemas"]["Job"] |
|
0981a08…
|
noreply
|
94 |
props = job["properties"] |
|
0981a08…
|
noreply
|
95 |
assert "id" in props |
|
0981a08…
|
noreply
|
96 |
assert "status" in props |
|
0981a08…
|
noreply
|
97 |
assert "progress" in props |
|
0981a08…
|
noreply
|
98 |
|
|
0981a08…
|
noreply
|
99 |
|
|
0981a08…
|
noreply
|
100 |
def test_job_status_enum(): |
|
0981a08…
|
noreply
|
101 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
102 |
status = spec["components"]["schemas"]["Job"]["properties"]["status"] |
|
0981a08…
|
noreply
|
103 |
assert "enum" in status |
|
0981a08…
|
noreply
|
104 |
assert "pending" in status["enum"] |
|
0981a08…
|
noreply
|
105 |
assert "completed" in status["enum"] |
|
0981a08…
|
noreply
|
106 |
|
|
0981a08…
|
noreply
|
107 |
|
|
0981a08…
|
noreply
|
108 |
def test_analyze_request_body_schema(): |
|
0981a08…
|
noreply
|
109 |
spec = get_openapi_spec() |
|
0981a08…
|
noreply
|
110 |
schema = spec["paths"]["/analyze"]["post"]["requestBody"]["content"]["application/json"][ |
|
0981a08…
|
noreply
|
111 |
"schema" |
|
0981a08…
|
noreply
|
112 |
] |
|
0981a08…
|
noreply
|
113 |
assert "video_url" in schema["properties"] |
|
0981a08…
|
noreply
|
114 |
assert "video_url" in schema["required"] |