Skip to content

Commit 9ad7016

Browse files
committed
fix(schema validation): match fastjsonschema test_utils error msg
1 parent 366fa6f commit 9ad7016

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

src/opengeodeweb_back/test_utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ def test_route_wrong_params(client, route, get_full_data):
1212
response = client.post(route, json=json)
1313
assert response.status_code == 400
1414
error_description = response.json["description"]
15-
assert error_description == f"Validation error: '{key}' is a required property"
15+
assert "data must contain" in error_description
16+
assert f"'{key}'" in error_description
1617

1718
json = get_full_data()
1819
json["dumb_key"] = "dumb_value"
1920
response = client.post(route, json=json)
2021
assert response.status_code == 400
2122
error_description = response.json["description"]
22-
assert (
23-
error_description
24-
== "Validation error: Additional properties are not allowed ('dumb_key' was unexpected)"
25-
)
23+
assert "data must not contain" in error_description
24+
assert "'dumb_key'" in error_description

src/opengeodeweb_back/utils_functions.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,7 @@ def validate_request(request, schema):
8585
validate(json_data)
8686
except fastjsonschema.JsonSchemaException as e:
8787
error_msg = str(e)
88-
89-
if "data must contain" in error_msg:
90-
field = error_msg.split("data must contain ['")[1].split("']")[0]
91-
error_msg = f"'{field}' is a required property"
92-
elif "data must not contain" in error_msg:
93-
field = error_msg.split("data must not contain {'")[1].split("'")[0]
94-
error_msg = f"Additional properties are not allowed ('{field}' was unexpected)"
95-
96-
flask.abort(400, f"Validation error: {error_msg}")
88+
flask.abort(400, error_msg)
9789

9890

9991
def set_interval(func, sec, args=None):

0 commit comments

Comments
 (0)