-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathtest_fixture_coverage.py
More file actions
195 lines (173 loc) · 7.63 KB
/
Copy pathtest_fixture_coverage.py
File metadata and controls
195 lines (173 loc) · 7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
"""TEST-01: Validate synthetic_v3_spec_full.json exercises all v3-specific features."""
import json
import pytest
from pathlib import Path
from parser_v3 import resolve_ref, parse_request_body, parse_params_v3, clear_cache
FIXTURES = Path(__file__).parent / "fixtures"
@pytest.fixture
def full_spec():
with open(FIXTURES / "synthetic_v3_spec_full.json") as f:
return json.load(f)
@pytest.fixture(autouse=True)
def reset_cache():
clear_cache()
yield
clear_cache()
class TestFixtureCoverage:
"""Assert the comprehensive fixture exercises every v3-specific feature."""
def test_ref_with_cycle(self, full_spec):
"""Circular $ref returns empty dict sentinel without stack overflow."""
result = resolve_ref(full_spec, "#/components/schemas/Circular")
assert result == {}
def test_ref_chain_cycle(self, full_spec):
"""Multi-hop cycle (ChainA -> ChainB -> ChainA) detected."""
result = resolve_ref(full_spec, "#/components/schemas/ChainA")
assert "properties" in result
# ChainB refs back to ChainA
chain_b = resolve_ref(full_spec, "#/components/schemas/ChainB")
assert "properties" in chain_b
def test_ref_normal_resolution(self, full_spec):
"""Normal $ref resolves to schema dict."""
result = resolve_ref(full_spec, "#/components/schemas/Network")
assert result["type"] == "object"
assert "properties" in result
def test_request_body_json(self, full_spec):
"""Fixture has endpoint with application/json requestBody."""
found = False
for path, path_item in full_spec["paths"].items():
for method in ("put", "post"):
if method in path_item:
op = path_item[method]
params, ct = parse_request_body(op, full_spec)
if ct == "application/json" and params:
found = True
break
if found:
break
assert found, "No endpoint with application/json requestBody found"
def test_request_body_multipart(self, full_spec):
"""Fixture has endpoint with multipart/form-data requestBody."""
found = False
for path, path_item in full_spec["paths"].items():
for method in ("put", "post"):
if method in path_item:
op = path_item[method]
_, ct = parse_request_body(op, full_spec)
if ct == "multipart/form-data":
found = True
break
if found:
break
assert found, "No endpoint with multipart/form-data requestBody found"
def test_request_body_octet_stream(self, full_spec):
"""Fixture has endpoint with application/octet-stream requestBody."""
found = False
for path, path_item in full_spec["paths"].items():
for method in ("put", "post"):
if method in path_item:
op = path_item[method]
_, ct = parse_request_body(op, full_spec)
if ct == "application/octet-stream":
found = True
break
if found:
break
assert found, "No endpoint with application/octet-stream requestBody found"
def test_oneof_query_param(self, full_spec):
"""Fixture has query param with oneOf schema."""
found = False
for path, path_item in full_spec["paths"].items():
for method in ("get", "post", "put", "delete"):
if method in path_item:
op = path_item[method]
params, _ = parse_params_v3(op, path_item, full_spec)
for name, entry in params.items():
if " or " in entry.get("type", ""):
found = True
break
if found:
break
if found:
break
assert found, "No oneOf query param found"
def test_nullable_param(self, full_spec):
"""Fixture has at least one param with nullable: true."""
found = False
for path, path_item in full_spec["paths"].items():
for method in ("get", "post", "put", "delete"):
if method in path_item:
op = path_item[method]
params, _ = parse_params_v3(op, path_item, full_spec)
for name, entry in params.items():
if entry.get("nullable") is True:
found = True
break
if found:
break
if found:
break
assert found, "No nullable param found"
def test_path_level_params(self, full_spec):
"""Fixture has path-level parameters key on at least one path."""
found = any(
"parameters" in path_item
for path_item in full_spec["paths"].values()
)
assert found, "No path-level parameters found"
def test_array_param_with_style(self, full_spec):
"""Fixture has array query param that gets style/explode defaults."""
found = False
for path, path_item in full_spec["paths"].items():
for method in ("get", "post", "put", "delete"):
if method in path_item:
op = path_item[method]
params, _ = parse_params_v3(op, path_item, full_spec)
for name, entry in params.items():
if entry.get("type") == "array" and "style" in entry:
found = True
break
if found:
break
if found:
break
assert found, "No array param with style/explode found"
def test_pagination_injection(self, full_spec):
"""Fixture has perPage param triggering pagination params injection."""
found = False
for path, path_item in full_spec["paths"].items():
for method in ("get",):
if method in path_item:
op = path_item[method]
params, _ = parse_params_v3(op, path_item, full_spec)
if "total_pages" in params and "direction" in params:
found = True
break
if found:
break
assert found, "No pagination injection found"
def test_batchable_actions(self, full_spec):
"""Fixture has x-batchable-actions with >= 3 entries."""
actions = full_spec.get("x-batchable-actions", [])
assert len(actions) >= 3
def test_multiple_scopes(self, full_spec):
"""Fixture has tags for both networks and organizations."""
tag_names = [t["name"] for t in full_spec["tags"]]
assert "networks" in tag_names
assert "organizations" in tag_names
def test_enum_param(self, full_spec):
"""Fixture has at least one param with enum values."""
found = False
for path, path_item in full_spec["paths"].items():
for method in ("get", "post", "put", "delete"):
if method in path_item:
op = path_item[method]
params, _ = parse_params_v3(op, path_item, full_spec)
for name, entry in params.items():
if "enum" in entry:
found = True
break
if found:
break
if found:
break
assert found, "No enum param found"