|
10 | 10 |
|
11 | 11 |
|
12 | 12 | 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 = [] |
14 | 14 | ) -> None: |
15 | | - for key, value in get_full_data().items(): |
| 15 | + def get_json(): |
16 | 16 | 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" |
18 | 37 | response = client.post(route, json=json) |
19 | 38 | assert response.status_code == 400 |
20 | 39 | 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