0001-api-particulier-more-flexible-validation-for-numero_.patch
passerelle/apps/api_particulier/models.py | ||
---|---|---|
345 | 345 |
}, |
346 | 346 |
) |
347 | 347 |
def v2_situation_familiale(self, request, code_postal, numero_allocataire, user=None): |
348 |
if not code_postal.strip() or not numero_allocataire.strip(): |
|
348 |
numero_allocataire = numero_allocataire.strip()[:7] |
|
349 |
code_postal = code_postal.strip() |
|
350 | ||
351 |
if not code_postal or not numero_allocataire: |
|
349 | 352 |
raise APIError('missing code_postal or numero_allocataire') |
353 | ||
350 | 354 |
if len(numero_allocataire) != 7 or not is_number(numero_allocataire): |
351 | 355 |
raise APIError('numero_allocataire should be a 7 digits number') |
352 |
return self.get(
|
|
356 |
data = self.get(
|
|
353 | 357 |
'v2/composition-familiale', |
354 | 358 |
params={ |
355 | 359 |
'codePostal': code_postal, |
... | ... | |
357 | 361 |
}, |
358 | 362 |
user=user, |
359 | 363 |
) |
364 |
data['data']['numero_allocataire'] = numero_allocataire |
|
365 |
data['data']['code_postal'] = code_postal |
|
366 |
return data |
|
360 | 367 | |
361 | 368 |
category = _('Business Process Connectors') |
362 | 369 |
tests/test_api_particulier.py | ||
---|---|---|
338 | 338 |
assert resp.json['err'] == 1 |
339 | 339 |
assert '7 digits' in resp.json['err_desc'] |
340 | 340 | |
341 |
# last letter truncated automatically |
|
342 |
params['numero_allocataire'] = '1234567a' |
|
343 |
resp = endpoint_get( |
|
344 |
'/api-particulier/test/situation-familiale', app, resource, 'situation-familiale', params=params |
|
345 |
) |
|
346 |
assert resp.json['data']['adresse']['codePostalVille'] == '12345 CONDAT' |
|
347 |
# cleaned data is also inlcuded in the response |
|
348 |
assert resp.json['data']['numero_allocataire'] == '1234567' |
|
349 |
assert resp.json['data']['code_postal'] == params['code_postal'] |
|
350 | ||
341 | 351 |
params['code_postal'] = ' ' |
342 | 352 |
resp = endpoint_get( |
343 | 353 |
'/api-particulier/test/situation-familiale', app, resource, 'situation-familiale', params=params |
344 |
- |