toulouse_axel: endpoint for children info (#39796)
This commit is contained in:
parent
c65bb85025
commit
6c4f8ae999
|
@ -120,6 +120,15 @@ def test_link(conn, user):
|
|||
pprint.pprint(res)
|
||||
print('\n')
|
||||
|
||||
print("GET children info")
|
||||
url = conn + '/children_info?NameID=%s' % (name_id)
|
||||
resp = requests.get(url)
|
||||
resp.raise_for_status()
|
||||
res = resp.json()
|
||||
assert res['err'] == 0
|
||||
pprint.pprint(res)
|
||||
print('\n')
|
||||
|
||||
for child in data['data']['ENFANT']:
|
||||
print("GET child info")
|
||||
url = conn + '/child_info?NameID=%s&idpersonne=%s' % (name_id, child['IDPERSONNE'])
|
||||
|
|
|
@ -496,6 +496,17 @@ class ToulouseAxel(BaseResource):
|
|||
family_data = self.get_family_data(link.dui, check_registrations=True)
|
||||
return {'data': family_data}
|
||||
|
||||
@endpoint(
|
||||
description=_("Get information about children"),
|
||||
perm='can_access',
|
||||
parameters={
|
||||
'NameID': {'description': _('Publik ID')},
|
||||
})
|
||||
def children_info(self, request, NameID):
|
||||
link = self.get_link(NameID)
|
||||
family_data = self.get_family_data(link.dui, check_registrations=True)
|
||||
return {'data': family_data.get('ENFANT', [])}
|
||||
|
||||
@endpoint(
|
||||
description=_("Get information about a child"),
|
||||
perm='can_access',
|
||||
|
|
|
@ -689,6 +689,36 @@ def test_family_info_endpoint(app, resource):
|
|||
assert resp.json['data']['ENFANT'][1]['clae_cantine_next'] is True
|
||||
|
||||
|
||||
def test_children_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/children_info?NameID=yyy')
|
||||
assert resp.json['err_desc'] == "Axel error: FooBar"
|
||||
assert resp.json['err'] == 'error'
|
||||
|
||||
|
||||
def test_children_info_endpoint_no_result(app, resource):
|
||||
resp = app.get('/toulouse-axel/test/children_info?NameID=yyy')
|
||||
assert resp.json['err_desc'] == "Person not found"
|
||||
assert resp.json['err'] == 'not-found'
|
||||
|
||||
|
||||
def test_children_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/children_info?NameID=yyy')
|
||||
assert resp.json['err'] == 0
|
||||
assert len(resp.json['data']) == 2
|
||||
assert resp.json['data'][0]['id'] == '4242'
|
||||
assert resp.json['data'][0]['text'] == 'foo foo'
|
||||
assert resp.json['data'][1]['id'] == '3535'
|
||||
assert resp.json['data'][1]['text'] == 'foo foo'
|
||||
|
||||
|
||||
def test_child_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:
|
||||
|
|
Loading…
Reference in New Issue