caluire-axel: child_info endpoint (#53825)
This commit is contained in:
parent
0de766f796
commit
8b5a7562cc
|
@ -38,6 +38,16 @@ def test_link(conn, user):
|
|||
assert res['err'] == 0
|
||||
print('\n')
|
||||
|
||||
for child in data['data']['MEMBRE']:
|
||||
print("GET child info")
|
||||
url = conn + '/child_info?NameID=%s&idpersonne=%s' % (name_id, child['IDENT'])
|
||||
resp = requests.get(url)
|
||||
resp.raise_for_status()
|
||||
res = resp.json()
|
||||
pprint.pprint(res)
|
||||
assert res['err'] == 0
|
||||
print('\n')
|
||||
|
||||
print("Deleting link")
|
||||
url = conn + '/unlink?NameID=%s' % name_id
|
||||
resp = requests.post(url)
|
||||
|
|
|
@ -178,6 +178,26 @@ class CaluireAxel(BaseResource):
|
|||
family_data = self.get_family_data(link.family_id)
|
||||
return {'data': family_data.get('MEMBRE', [])}
|
||||
|
||||
@endpoint(
|
||||
display_category=_('Family account'),
|
||||
display_order=5,
|
||||
description=_("Get information about a child"),
|
||||
perm='can_access',
|
||||
parameters={
|
||||
'NameID': {'description': _('Publik ID')},
|
||||
'idpersonne': {'description': _('Child ID')},
|
||||
},
|
||||
)
|
||||
def child_info(self, request, idpersonne, NameID):
|
||||
link = self.get_link(NameID)
|
||||
family_data = self.get_family_data(link.family_id)
|
||||
|
||||
for child in family_data.get('MEMBRE', []):
|
||||
if child['IDENT'] == idpersonne:
|
||||
return {'data': child}
|
||||
|
||||
raise APIError('Child not found', err_code='not-found')
|
||||
|
||||
|
||||
class Link(models.Model):
|
||||
resource = models.ForeignKey(CaluireAxel, on_delete=models.CASCADE)
|
||||
|
|
|
@ -434,3 +434,59 @@ def test_children_info_endpoint(app, resource):
|
|||
assert resp.json['data'][2]['text'] == 'Enfant 3 CALUIRE TEST'
|
||||
assert resp.json['data'][3]['id'] == '59509'
|
||||
assert resp.json['data'][3]['text'] == 'Enfant 5 CALUIRE TEST'
|
||||
|
||||
|
||||
def test_child_info_endpoint_axel_error(app, resource):
|
||||
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
||||
with mock.patch('passerelle.contrib.caluire_axel.schemas.get_famille_individus') as operation:
|
||||
operation.side_effect = AxelError('FooBar')
|
||||
resp = app.get('/caluire-axel/test/child_info?NameID=yyy&idpersonne=zzz')
|
||||
assert resp.json['err_desc'] == "Axel error: FooBar"
|
||||
assert resp.json['err'] == 'error'
|
||||
|
||||
|
||||
def test_child_info_endpoint_no_result(app, resource):
|
||||
resp = app.get('/caluire-axel/test/child_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', family_id='XXX', person_id='42')
|
||||
filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
|
||||
with open(filepath) as xml:
|
||||
content = xml.read()
|
||||
with mock_getdata(content, 'GetFamilleIndividus'):
|
||||
resp = app.get('/caluire-axel/test/child_info?NameID=yyy&idpersonne=zzz')
|
||||
assert resp.json['err_desc'] == "Child not found"
|
||||
assert resp.json['err'] == 'not-found'
|
||||
|
||||
|
||||
def test_child_info_endpoint(app, resource):
|
||||
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
||||
filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
|
||||
with open(filepath) as xml:
|
||||
content = xml.read()
|
||||
with mock_getdata(content, 'GetFamilleIndividus'):
|
||||
resp = app.get('/caluire-axel/test/child_info?NameID=yyy&idpersonne=50632')
|
||||
assert resp.json['err'] == 0
|
||||
assert set(resp.json['data'].keys()) == set(
|
||||
[
|
||||
'ADRESSE',
|
||||
'CIVILITE',
|
||||
'FAMILLE',
|
||||
'GARDEALTERNEE',
|
||||
'IDENT',
|
||||
'MAIL',
|
||||
'NAISSANCE',
|
||||
'NOM',
|
||||
'NOMJF',
|
||||
'PAI',
|
||||
'PRENOM',
|
||||
'SEXE',
|
||||
'TELFIXE',
|
||||
'TELPORTABLE',
|
||||
'id',
|
||||
'text',
|
||||
]
|
||||
)
|
||||
assert resp.json['data']['id'] == '50632'
|
||||
assert resp.json['data']['text'] == 'Enfant 1 CALUIRE TEST'
|
||||
|
|
Loading…
Reference in New Issue