Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ werkzeug==3.1.2
# flask
# flask-cors

opengeodeweb-microservice==1.*,>=1.0.14
45 changes: 32 additions & 13 deletions src/opengeodeweb_back/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,40 @@


def test_route_wrong_params(
client: FlaskClient, route: str, get_full_data: Callable[[], JsonData]
client: FlaskClient,
route: str,
get_full_data: Callable[[], JsonData],
path: list[str | int] | None = None,
) -> None:
for key, value in get_full_data().items():
if path is None:
path = []

def get_json() -> tuple[JsonData, Any]:
json = get_full_data()
json.pop(key)
target: Any = json
for sub_path in path:
target = target[sub_path]
return json, target

data = get_json()[1]
if isinstance(data, dict):
for key, value in data.items():
json, target = get_json()
target.pop(key)
response = client.post(route, json=json)
if response.status_code == 400:
error_description: str = response.get_json()["description"]
assert "must contain" in error_description
assert f"'{key}'" in error_description
if isinstance(value, (dict, list)):
test_route_wrong_params(client, route, get_full_data, path + [key])

json, target = get_json()
target["dumb_key"] = "dumb_value"
response = client.post(route, json=json)
assert response.status_code == 400
error_description = response.get_json()["description"]
assert "data must contain" in error_description
assert f"'{key}'" in error_description

json = get_full_data()
json["dumb_key"] = "dumb_value"
response = client.post(route, json=json)
assert response.status_code == 400
error_description = response.get_json()["description"]
assert "data must not contain" in error_description
assert "'dumb_key'" in error_description
assert "must not contain" in error_description
assert "'dumb_key'" in error_description
elif isinstance(data, list) and data:
test_route_wrong_params(client, route, get_full_data, path + [0])