toulouse_axel: endpoint for child contacts info (#39799)
This commit is contained in:
parent
3338accbfe
commit
b9603f2dac
|
@ -59,6 +59,10 @@ def test_link(conn, user):
|
|||
'clae_cantine_current', 'clae_cantine_next']:
|
||||
enfant.pop(key)
|
||||
enfant['AUTORISATIONURGENCEMEDICALE'] = 'OUI'
|
||||
# manage contact fields
|
||||
for contact in enfant.get('CONTACT', []):
|
||||
contact.pop('id')
|
||||
contact.pop('text')
|
||||
if 'SANITAIRE' not in enfant:
|
||||
continue
|
||||
# manage handicap data (not the same schema)
|
||||
|
@ -139,6 +143,15 @@ def test_link(conn, user):
|
|||
pprint.pprint(res)
|
||||
print('\n')
|
||||
|
||||
print("GET child contact info")
|
||||
url = conn + '/child_contacts_info?NameID=%s&idpersonne=%s' % (name_id, child['IDPERSONNE'])
|
||||
resp = requests.get(url)
|
||||
resp.raise_for_status()
|
||||
res = resp.json()
|
||||
assert res['err'] == 0
|
||||
pprint.pprint(res)
|
||||
print('\n')
|
||||
|
||||
print("Deleting link")
|
||||
url = conn + '/unlink?NameID=%s' % name_id
|
||||
resp = requests.post(url)
|
||||
|
|
|
@ -527,6 +527,23 @@ class ToulouseAxel(BaseResource):
|
|||
|
||||
raise APIError('Child not found', err_code='not-found')
|
||||
|
||||
@endpoint(
|
||||
description=_("Get information about a child's contacts"),
|
||||
perm='can_access',
|
||||
parameters={
|
||||
'NameID': {'description': _('Publik ID')},
|
||||
'idpersonne': {'description': _('Child ID')},
|
||||
})
|
||||
def child_contacts_info(self, request, idpersonne, NameID):
|
||||
link = self.get_link(NameID)
|
||||
family_data = self.get_family_data(link.dui, check_registrations=True)
|
||||
|
||||
for child in family_data['ENFANT']:
|
||||
if child['IDPERSONNE'] == idpersonne:
|
||||
return {'data': child.get('CONTACT', [])}
|
||||
|
||||
raise APIError('Child not found', err_code='not-found')
|
||||
|
||||
def pre_sanitize_update_family_data(self, post_data):
|
||||
# before json payload validation, check maj fields and remove empty blocks
|
||||
|
||||
|
|
|
@ -808,6 +808,51 @@ def test_child_info_endpoint(app, resource):
|
|||
assert resp.json['data']['clae_cantine_next'] is False
|
||||
|
||||
|
||||
def test_child_contacts_info_endpoint_axel_error(app, resource):
|
||||
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
|
||||
with mock.patch('passerelle.contrib.toulouse_axel.models.ref_famille_dui') as operation:
|
||||
operation.side_effect = AxelError('FooBar')
|
||||
resp = app.get('/toulouse-axel/test/child_contacts_info?NameID=yyy&idpersonne=zzz')
|
||||
assert resp.json['err_desc'] == "Axel error: FooBar"
|
||||
assert resp.json['err'] == 'error'
|
||||
|
||||
|
||||
def test_child_contacts_info_endpoint_no_result(app, resource):
|
||||
resp = app.get('/toulouse-axel/test/child_contacts_info?NameID=yyy&idpersonne=zzz')
|
||||
assert resp.json['err_desc'] == "Person not found"
|
||||
assert resp.json['err'] == 'not-found'
|
||||
|
||||
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
|
||||
filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/family_info.xml')
|
||||
with open(filepath) as xml:
|
||||
content = xml.read()
|
||||
with mock_getdata(content, 'RefFamilleDui'):
|
||||
resp = app.get('/toulouse-axel/test/child_contacts_info?NameID=yyy&idpersonne=zzz')
|
||||
assert resp.json['err_desc'] == "Child not found"
|
||||
assert resp.json['err'] == 'not-found'
|
||||
|
||||
|
||||
def test_child_contacts_info_endpoint(app, resource):
|
||||
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
|
||||
filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/family_info.xml')
|
||||
with open(filepath) as xml:
|
||||
content = xml.read()
|
||||
with mock_getdata(content, 'RefFamilleDui'):
|
||||
resp = app.get('/toulouse-axel/test/child_contacts_info?NameID=yyy&idpersonne=4242')
|
||||
assert resp.json['err'] == 0
|
||||
assert len(resp.json['data']) == 3
|
||||
assert resp.json['data'][0]['id'] == 0
|
||||
assert resp.json['data'][0]['text'] == 'foo foo'
|
||||
assert resp.json['data'][1]['id'] == 1
|
||||
assert resp.json['data'][1]['text'] == 'foo foo'
|
||||
assert resp.json['data'][2]['id'] == 2
|
||||
assert resp.json['data'][2]['text'] == 'foo foo'
|
||||
with mock_getdata(content, 'RefFamilleDui'):
|
||||
resp = app.get('/toulouse-axel/test/child_contacts_info?NameID=yyy&idpersonne=3535')
|
||||
assert resp.json['err'] == 0
|
||||
assert len(resp.json['data']) == 0
|
||||
|
||||
|
||||
def test_update_family_info_endpoint_axel_error(app, resource, update_params, family_data):
|
||||
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
|
||||
|
||||
|
|
Loading…
Reference in New Issue