toulouse-smart: do not crash on receiving string in place of block field (#79816)
gitea/passerelle/pipeline/head This commit looks good Details

This commit is contained in:
Nicolas Roche 2023-07-19 14:49:46 +02:00 committed by Nicolas Roche
parent c598673e3d
commit f2652bac36
2 changed files with 20 additions and 0 deletions

View File

@ -177,6 +177,12 @@ class ToulouseSmartResource(BaseResource, HTTPResource):
except (KeyError, TypeError):
block = {}
data = {}
if not isinstance(block, dict):
raise APIError(
"cannot retrieve '%s' block content from post data: got a %s where a dict was expected"
% (wcs_block_varname, type(block)),
http_status=400,
)
cast = {'string': str, 'int': int, 'boolean': bool, 'item': str}
for prop in intervention_type.get('properties') or []:
varname = slugify(prop['name']).replace('-', '_')

View File

@ -493,6 +493,20 @@ def test_create_intervention_no_block(app, smart):
assert resp.json['err_desc'] == "'field2' field is required on 'coin' block"
@mock_response(
['/v1/type-intervention', None, INTERVENTION_TYPES],
)
def test_create_intervention_string_payload(app, smart):
payload = deepcopy(CREATE_INTERVENTION_PAYLOAD)
payload['fields']['coin_raw'] = 'plop'
resp = app.post_json(URL + 'create-intervention/', params=payload, status=400)
assert resp.json['err']
assert (
resp.json['err_desc']
== "cannot retrieve 'coin' block content from post data: got a <class 'str'> where a dict was expected"
)
@mock_response(
['/v1/type-intervention', None, INTERVENTION_TYPES],
)