toulouse_maelis: check q is a DUI in search-family-dui (#88873)

A DUI is an xs:int.
This commit is contained in:
Benjamin Dauvergne 2024-03-29 15:10:55 +01:00
parent 23a59e3f0f
commit 10590eb9d9
2 changed files with 17 additions and 9 deletions

View File

@ -1401,15 +1401,19 @@ class ToulouseMaelis(BaseResource, HTTPResource):
},
)
def search_family_dui(self, request, q=None):
data = []
if q:
try:
response = self.call('Family', 'readFamilyList', dossierNumber=q)
except APIError:
pass
else:
data = serialize_object(response)
return {'data': data}
if not q:
return {'data': []}
try:
dui = int(q)
if dui >= 2**32:
raise ValueError
except (TypeError, ValueError):
return {'data': []}
try:
response = self.call('Family', 'readFamilyList', dossierNumber=dui)
except APIError:
return {'data': []}
return {'data': serialize_object(response)}
@endpoint(
display_category='Famille',

View File

@ -1737,6 +1737,10 @@ def test_search_family_dui(family_service, con, app):
assert resp.json['err'] == 0
assert resp.json['data'] == []
resp = app.get(url + '?q=abcd')
assert resp.json['err'] == 0
assert resp.json['data'] == []
@pytest.mark.parametrize(
'xml', ['R_read_family.xml', 'R_read_family_relax.xml', 'R_read_family_reordered.xml']