Skip to content

Commit 092789a

Browse files
committed
feat(structuralModel): Recursive test_route_wrong_params
1 parent a078183 commit 092789a

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

src/opengeodeweb_back/test_utils.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,34 @@
1010

1111

1212
def test_route_wrong_params(
13-
client: FlaskClient, route: str, get_full_data: Callable[[], JsonData]
13+
client: FlaskClient, route: str, get_full_data: Callable[[], JsonData], path: list = []
1414
) -> None:
15-
for key, value in get_full_data().items():
15+
def get_json():
1616
json = get_full_data()
17-
json.pop(key)
17+
target = json
18+
for p in path:
19+
target = target[p]
20+
return json, target
21+
22+
data = get_json()[1]
23+
if isinstance(data, dict):
24+
for key, value in data.items():
25+
json, target = get_json()
26+
target.pop(key)
27+
response = client.post(route, json=json)
28+
if response.status_code == 400:
29+
error_description = response.get_json()["description"]
30+
assert "must contain" in error_description
31+
assert f"'{key}'" in error_description
32+
if isinstance(value, (dict, list)):
33+
test_route_wrong_params(client, route, get_full_data, path + [key])
34+
35+
json, target = get_json()
36+
target["dumb_key"] = "dumb_value"
1837
response = client.post(route, json=json)
1938
assert response.status_code == 400
2039
error_description = response.get_json()["description"]
21-
assert "data must contain" in error_description
22-
assert f"'{key}'" in error_description
23-
24-
json = get_full_data()
25-
json["dumb_key"] = "dumb_value"
26-
response = client.post(route, json=json)
27-
assert response.status_code == 400
28-
error_description = response.get_json()["description"]
29-
assert "data must not contain" in error_description
30-
assert "'dumb_key'" in error_description
40+
assert "must not contain" in error_description
41+
assert "'dumb_key'" in error_description
42+
elif isinstance(data, list) and data:
43+
test_route_wrong_params(client, route, get_full_data, path + [0])

0 commit comments

Comments
 (0)