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