toulouse-smart: do not crash on receiving string in place of block field (#79816)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
c598673e3d
commit
f2652bac36
|
@ -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('-', '_')
|
||||
|
|
|
@ -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],
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue