toulouse-maelis: add endpoint to get RLs and childs data (#75455)
This commit is contained in:
parent
4b64f39337
commit
6210cf3fa3
|
@ -1032,6 +1032,52 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
||||||
data.append(item)
|
data.append(item)
|
||||||
return {'data': data}
|
return {'data': data}
|
||||||
|
|
||||||
|
@endpoint(
|
||||||
|
display_category='Famille',
|
||||||
|
description="Lister les enfants et les responsables légaux",
|
||||||
|
perm='can_access',
|
||||||
|
name='read-rl-and-child-list',
|
||||||
|
parameters={
|
||||||
|
'NameID': {'description': 'Publik NameID'},
|
||||||
|
'family_id': {'description': 'Numéro de DUI'},
|
||||||
|
'rl_text_template': {
|
||||||
|
'description': 'Gabarit utilisé pour la valeur text',
|
||||||
|
'example_value': '{{ lastname }} {{ firstname }}',
|
||||||
|
},
|
||||||
|
'child_text_template': {
|
||||||
|
'description': 'Gabarit utilisé pour la valeur text',
|
||||||
|
'example_value': '{{ lastname }} {{ firstname }}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
def read_rl_and_child_list(
|
||||||
|
self, request, NameID=None, family_id=None, rl_text_template=None, child_text_template=None
|
||||||
|
):
|
||||||
|
family_id = family_id or self.get_link(NameID).family_id
|
||||||
|
result = self.get_family_raw(family_id)
|
||||||
|
if not rl_text_template:
|
||||||
|
rl_text_template = '{{ lastname }} {{ firstname }}'
|
||||||
|
if not child_text_template:
|
||||||
|
child_text_template = '{{ lastname }} {{ firstname }}'
|
||||||
|
|
||||||
|
data = []
|
||||||
|
for rlg in 'RL1', 'RL2':
|
||||||
|
item = result.get(rlg)
|
||||||
|
if not item:
|
||||||
|
break
|
||||||
|
self.add_text_value_to_rl(item)
|
||||||
|
item['id'] = item['num']
|
||||||
|
item['text'] = render_to_string(rl_text_template, item).strip()
|
||||||
|
item['family_id'] = family_id
|
||||||
|
data.append(item)
|
||||||
|
for item in result['childList']:
|
||||||
|
self.add_text_value_to_child(item)
|
||||||
|
item['id'] = item['num']
|
||||||
|
item['text'] = render_to_string(child_text_template, item).strip()
|
||||||
|
item['family_id'] = family_id
|
||||||
|
data.append(item)
|
||||||
|
return {'data': data}
|
||||||
|
|
||||||
@endpoint(
|
@endpoint(
|
||||||
display_category='Famille',
|
display_category='Famille',
|
||||||
description="Lister les personnes autorisées à récupérer l'enfant",
|
description="Lister les personnes autorisées à récupérer l'enfant",
|
||||||
|
|
|
@ -918,6 +918,48 @@ def test_read_rl_list_not_linked_error(con, app):
|
||||||
assert resp.json['err_desc'] == 'User not linked to family'
|
assert resp.json['err_desc'] == 'User not linked to family'
|
||||||
|
|
||||||
|
|
||||||
|
def test_read_rl_and_child_list(family_service, con, app):
|
||||||
|
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
|
||||||
|
url = get_endpoint('read-rl-and-child-list')
|
||||||
|
|
||||||
|
resp = app.get(url + '?family_id=1312')
|
||||||
|
assert resp.json['err'] == 0
|
||||||
|
Link.objects.create(resource=con, family_id='1312', name_id='local')
|
||||||
|
|
||||||
|
resp = app.get(url + '?NameID=local')
|
||||||
|
assert resp.json['err'] == 0
|
||||||
|
assert [(x['id'], x['text']) for x in resp.json['data']] == [
|
||||||
|
('613878', 'DOE JHON'),
|
||||||
|
('613879', 'DOE JANE'),
|
||||||
|
('613880', 'DOE JANNIS'),
|
||||||
|
('613987', 'DOE JOHNNY ALLEN'),
|
||||||
|
('614051', 'DOE ROBERT'),
|
||||||
|
]
|
||||||
|
|
||||||
|
params = {
|
||||||
|
'NameID': 'local',
|
||||||
|
'rl_text_template': 'RL {{ firstname }}, {{ birth.dateBirth|date:"d/m/Y" }}',
|
||||||
|
'child_text_template': 'Child {{ firstname }}, {{ birth.dateBirth|date:"d/m/Y" }}',
|
||||||
|
}
|
||||||
|
resp = app.get(url, params=params)
|
||||||
|
assert resp.json['err'] == 0
|
||||||
|
assert [(x['id'], x['text']) for x in resp.json['data']] == [
|
||||||
|
('613878', 'RL JHON, 25/07/1938'),
|
||||||
|
('613879', 'RL JANE, 21/06/1940'),
|
||||||
|
('613880', 'Child JANNIS, 18/01/1943'),
|
||||||
|
('613987', 'Child JOHNNY ALLEN, 26/11/1942'),
|
||||||
|
('614051', 'Child ROBERT, 23/05/1941'),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_read_rl_and_child_list_not_linked_error(con, app):
|
||||||
|
url = get_endpoint('read-rl-list')
|
||||||
|
|
||||||
|
resp = app.get(url + '?NameID=local')
|
||||||
|
assert resp.json['err'] == 1
|
||||||
|
assert resp.json['err_desc'] == 'User not linked to family'
|
||||||
|
|
||||||
|
|
||||||
def test_read_person_list(family_service, con, app):
|
def test_read_person_list(family_service, con, app):
|
||||||
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
|
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
|
||||||
url = get_endpoint('read-person-list')
|
url = get_endpoint('read-person-list')
|
||||||
|
|
Loading…
Reference in New Issue