toulouse-maelis: add read family person endpoint (#69891)
This commit is contained in:
parent
c3c2ece5ae
commit
2ef638c934
|
@ -148,6 +148,15 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
return child
|
||||
raise APIError("no '%s' child on '%s' family" % (child_id, family_id), err_code='not-found')
|
||||
|
||||
def get_child_person_raw(self, family_id, child_id, person_id):
|
||||
data = self.get_child_raw(family_id, child_id)
|
||||
for person in data['authorizedPersonList']:
|
||||
if str(person['personInfo']['num']) == person_id:
|
||||
return person
|
||||
raise APIError(
|
||||
"no '%s' authorized person on '%s' child" % (person_id, child_id), err_code='not-found'
|
||||
)
|
||||
|
||||
def add_text_value(self, referential_name, data, keys):
|
||||
'''add text from referentials'''
|
||||
last_key = keys.pop()
|
||||
|
@ -158,10 +167,18 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
if isinstance(data, dict) and last_key in data and data[last_key] is not None:
|
||||
data[last_key + '_text'] = self.get_referential_value(referential_name, data[last_key])
|
||||
|
||||
def add_text_value_to_child_person(self, data):
|
||||
self.add_text_value('Civility', data, ['personInfo', 'civility'])
|
||||
self.add_text_value('Quality', data, ['personQuality', 'code'])
|
||||
self.add_text_value('Sex', data, ['personInfo', 'sexe'])
|
||||
return data
|
||||
|
||||
def add_text_value_to_child(self, data):
|
||||
self.add_text_value('Sex', data, ['sexe'])
|
||||
self.add_text_value('DietCode', data, ['dietcode'])
|
||||
self.add_text_value('PAI', data, ['paiInfoBean', 'code'])
|
||||
for person in data['authorizedPersonList']:
|
||||
self.add_text_value_to_child_person(person)
|
||||
|
||||
# convert O/N string into boolean
|
||||
if data.get('fsl'):
|
||||
|
@ -199,6 +216,11 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
self.add_text_value_to_person(person)
|
||||
return data
|
||||
|
||||
def get_child_person(self, family_id, child_id, person_id):
|
||||
data = self.get_child_person_raw(family_id, child_id, person_id)
|
||||
self.add_text_value_to_child_person(data)
|
||||
return data
|
||||
|
||||
def get_child(self, family_id, child_id):
|
||||
data = self.get_child_raw(family_id, child_id)
|
||||
self.add_text_value_to_child(data)
|
||||
|
@ -435,6 +457,22 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
data = self.get_child(family_id, child_id)
|
||||
return {'data': data}
|
||||
|
||||
@endpoint(
|
||||
display_category='Famille',
|
||||
description="Informations sur une personne autorisée à récupérer l'enfant",
|
||||
perm='can_access',
|
||||
name='read-child-person',
|
||||
parameters={
|
||||
'NameID': {'description': 'Publik NameID'},
|
||||
'child_id': {'description': "Numéro de l'enfant"},
|
||||
'person_id': {'description': 'Numéro de la personne'},
|
||||
},
|
||||
)
|
||||
def read_child_person(self, request, NameID, child_id, person_id):
|
||||
family_id = self.get_link(NameID).family_id
|
||||
data = self.get_child_person(family_id, child_id, person_id)
|
||||
return {'data': data}
|
||||
|
||||
@endpoint(
|
||||
display_category='Famille',
|
||||
description="Vérifier qu'un responsable légal existe en base",
|
||||
|
|
|
@ -122,6 +122,25 @@
|
|||
</fsl>
|
||||
<bPhoto>true</bPhoto>
|
||||
<bLeaveAlone>false</bLeaveAlone>
|
||||
<authorizedPersonList>
|
||||
<personInfo>
|
||||
<num>614719</num>
|
||||
<lastname>BENT</lastname>
|
||||
<firstname>AMEL</firstname>
|
||||
<dateBirth>1985-06-21T00:00:00+02:00</dateBirth>
|
||||
<civility>MME</civility>
|
||||
<sexe>F</sexe>
|
||||
<contact>
|
||||
<phone>0123456789</phone>
|
||||
<mobile>0623456789</mobile>
|
||||
<mail>abent@example.org</mail>
|
||||
</contact>
|
||||
</personInfo>
|
||||
<personQuality>
|
||||
<code>T</code>
|
||||
<libelle>TANTE</libelle>
|
||||
</personQuality>
|
||||
</authorizedPersonList>
|
||||
<medicalRecord>
|
||||
<familyDoctor>
|
||||
<name>DRE</name>
|
||||
|
|
|
@ -594,6 +594,7 @@ def test_read_family(mocked_post, mocked_get, con, app):
|
|||
data = resp.json['data']['childList'][0]
|
||||
del data['fsl']
|
||||
del data['medicalRecord']
|
||||
del data['authorizedPersonList']
|
||||
assert data == {
|
||||
'num': '613880',
|
||||
'lastname': 'DOE',
|
||||
|
@ -605,7 +606,6 @@ def test_read_family(mocked_post, mocked_get, con, app):
|
|||
'dietcode_text': '3- RÉGIME SANS VIANDE',
|
||||
'bPhoto': True,
|
||||
'bLeaveAlone': False,
|
||||
'authorizedPersonList': [],
|
||||
'indicatorList': [],
|
||||
'subscribeSchoolList': [],
|
||||
'mother': {'num': 613963, 'civility': 'MME', 'firstname': 'JANE', 'lastname': 'DOE'},
|
||||
|
@ -679,6 +679,24 @@ def test_read_family(mocked_post, mocked_get, con, app):
|
|||
'civility_text': 'Madame',
|
||||
'quality_text': 'TANTE',
|
||||
}
|
||||
assert resp.json['data']['childList'][0]['authorizedPersonList'][0] == {
|
||||
'personInfo': {
|
||||
'num': 614719,
|
||||
'lastname': 'BENT',
|
||||
'firstname': 'AMEL',
|
||||
'dateBirth': '1985-06-21T00:00:00+02:00',
|
||||
'civility': 'MME',
|
||||
'civility_text': 'Madame',
|
||||
'sexe': 'F',
|
||||
'sexe_text': 'Féminin',
|
||||
'contact': {'phone': '0123456789', 'mobile': '0623456789', 'mail': 'abent@example.org'},
|
||||
},
|
||||
'personQuality': {
|
||||
'code': 'T',
|
||||
'code_text': 'TANTE',
|
||||
'libelle': 'TANTE',
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_read_family_not_linked_error(con, app):
|
||||
|
@ -827,6 +845,8 @@ def test_read_child(mocked_post, mocked_get, con, app):
|
|||
READ_FAMILY,
|
||||
READ_DIETCODE,
|
||||
READ_PAI,
|
||||
READ_CIVILITIES,
|
||||
READ_QUALITIES,
|
||||
]
|
||||
url = get_endpoint('read-child')
|
||||
Link.objects.create(resource=con, family_id='1312', name_id='local')
|
||||
|
@ -861,6 +881,63 @@ def test_read_child_not_found(mocked_post, mocked_get, con, app):
|
|||
assert resp.json['err_desc'] == "no '000000' child on '1312' family"
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
def test_read_child_person(mocked_post, mocked_get, con, app):
|
||||
mocked_get.return_value = FAMILY_SERVICE_WSDL
|
||||
mocked_post.side_effect = [
|
||||
READ_FAMILY,
|
||||
READ_CIVILITIES,
|
||||
READ_QUALITIES,
|
||||
]
|
||||
url = get_endpoint('read-child-person')
|
||||
Link.objects.create(resource=con, family_id='1312', name_id='local')
|
||||
|
||||
resp = app.get(url + '?NameID=local&child_id=613880&person_id=614719')
|
||||
assert resp.json['err'] == 0
|
||||
assert resp.json['data']['personInfo']['firstname'] == 'AMEL'
|
||||
|
||||
|
||||
def test_read_child_person_not_linked_error(con, app):
|
||||
url = get_endpoint('read-child-person')
|
||||
|
||||
resp = app.get(url + '?NameID=local&child_id=613880&person_id=614719')
|
||||
assert resp.json['err'] == 'not-linked'
|
||||
assert resp.json['err_desc'] == 'User not linked to family'
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
def test_read_child_person_no_child_error(mocked_post, mocked_get, con, app):
|
||||
mocked_get.return_value = FAMILY_SERVICE_WSDL
|
||||
mocked_post.side_effect = [
|
||||
READ_FAMILY,
|
||||
]
|
||||
url = get_endpoint('read-child-person')
|
||||
Link.objects.create(resource=con, family_id='1312', name_id='local')
|
||||
|
||||
resp = app.get(url + '?NameID=local&child_id=42&person_id=614719')
|
||||
assert resp.json['err'] == 'not-found'
|
||||
assert resp.json['err_desc'] == "no '42' child on '1312' family"
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
def test_read_child_person_no_person_error(mocked_post, mocked_get, con, app):
|
||||
mocked_get.return_value = FAMILY_SERVICE_WSDL
|
||||
mocked_post.side_effect = [
|
||||
READ_FAMILY,
|
||||
READ_CIVILITIES,
|
||||
READ_QUALITIES,
|
||||
]
|
||||
url = get_endpoint('read-child-person')
|
||||
Link.objects.create(resource=con, family_id='1312', name_id='local')
|
||||
|
||||
resp = app.get(url + '?NameID=local&child_id=613880&person_id=000000')
|
||||
assert resp.json['err'] == 'not-found'
|
||||
assert resp.json['err_desc'] == "no '000000' authorized person on '613880' child"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'post_response, result',
|
||||
[
|
||||
|
|
Loading…
Reference in New Issue