caluire-axel: children_info endpoint (#53825)
This commit is contained in:
parent
4e893cb433
commit
0de766f796
|
@ -29,6 +29,15 @@ def test_link(conn, user):
|
|||
assert data['err'] == 0
|
||||
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()
|
||||
pprint.pprint(res)
|
||||
assert res['err'] == 0
|
||||
print('\n')
|
||||
|
||||
print("Deleting link")
|
||||
url = conn + '/unlink?NameID=%s' % name_id
|
||||
resp = requests.post(url)
|
||||
|
|
|
@ -164,6 +164,20 @@ class CaluireAxel(BaseResource):
|
|||
family_data = self.get_family_data(link.family_id)
|
||||
return {'data': family_data}
|
||||
|
||||
@endpoint(
|
||||
display_category=_('Family account'),
|
||||
display_order=4,
|
||||
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.family_id)
|
||||
return {'data': family_data.get('MEMBRE', [])}
|
||||
|
||||
|
||||
class Link(models.Model):
|
||||
resource = models.ForeignKey(CaluireAxel, on_delete=models.CASCADE)
|
||||
|
|
|
@ -400,3 +400,37 @@ def test_family_info_endpoint(app, resource):
|
|||
assert resp.json['data']['MEMBRE'][2]['text'] == 'Enfant 3 CALUIRE TEST'
|
||||
assert resp.json['data']['MEMBRE'][3]['id'] == '59509'
|
||||
assert resp.json['data']['MEMBRE'][3]['text'] == 'Enfant 5 CALUIRE TEST'
|
||||
|
||||
|
||||
def test_children_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/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('/caluire-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', 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/children_info?NameID=yyy')
|
||||
assert resp.json['err'] == 0
|
||||
assert len(resp.json['data']) == 4
|
||||
assert resp.json['data'][0]['id'] == '50632'
|
||||
assert resp.json['data'][0]['text'] == 'Enfant 1 CALUIRE TEST'
|
||||
assert resp.json['data'][1]['id'] == '50633'
|
||||
assert resp.json['data'][1]['text'] == 'Enfant 2 CALUIRE TEST'
|
||||
assert resp.json['data'][2]['id'] == '54621'
|
||||
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'
|
||||
|
|
Loading…
Reference in New Issue