0002-toulouse-maelis-add-read-family-person-endpoint-6989.patch
passerelle/contrib/toulouse_maelis/models.py | ||
---|---|---|
143 | 143 | |
144 | 144 |
def get_child_raw(self, family_id, child_id): |
145 | 145 |
data = self.get_family_raw(family_id) |
146 | 146 |
for child in data['childList']: |
147 | 147 |
if child['num'] == child_id: |
148 | 148 |
return child |
149 | 149 |
raise APIError("no '%s' child on '%s' family" % (child_id, family_id), err_code='not-found') |
150 | 150 | |
151 |
def get_child_person_raw(self, family_id, child_id, person_id): |
|
152 |
data = self.get_child_raw(family_id, child_id) |
|
153 |
for person in data['authorizedPersonList']: |
|
154 |
if str(person['personInfo']['num']) == person_id: |
|
155 |
return person |
|
156 |
raise APIError( |
|
157 |
"no '%s' authorized person on '%s' child" % (person_id, child_id), err_code='not-found' |
|
158 |
) |
|
159 | ||
151 | 160 |
def add_text_value(self, referential_name, data, keys): |
152 | 161 |
'''add text from referentials''' |
153 | 162 |
last_key = keys.pop() |
154 | 163 |
for key in keys: |
155 | 164 |
if not isinstance(data, dict) or not key in data: |
156 | 165 |
return |
157 | 166 |
data = data[key] |
158 | 167 |
if isinstance(data, dict) and last_key in data and data[last_key] is not None: |
159 | 168 |
data[last_key + '_text'] = self.get_referential_value(referential_name, data[last_key]) |
160 | 169 | |
170 |
def add_text_value_to_child_person(self, data): |
|
171 |
self.add_text_value('Civility', data, ['personInfo', 'civility']) |
|
172 |
self.add_text_value('Quality', data, ['personQuality', 'code']) |
|
173 |
self.add_text_value('Sex', data, ['personInfo', 'sexe']) |
|
174 |
return data |
|
175 | ||
161 | 176 |
def add_text_value_to_child(self, data): |
162 | 177 |
self.add_text_value('Sex', data, ['sexe']) |
163 | 178 |
self.add_text_value('DietCode', data, ['dietcode']) |
164 | 179 |
self.add_text_value('PAI', data, ['paiInfoBean', 'code']) |
180 |
for person in data['authorizedPersonList']: |
|
181 |
self.add_text_value_to_child_person(person) |
|
165 | 182 | |
166 | 183 |
# convert O/N string into boolean |
167 | 184 |
if data.get('fsl'): |
168 | 185 |
for key in ( |
169 | 186 |
'allergieAlimentaire', |
170 | 187 |
'allergieRespiratoire', |
171 | 188 |
'allergieAutre', |
172 | 189 |
'allergieMedicament', |
... | ... | |
194 | 211 |
if data.get(rlg): |
195 | 212 |
self.add_text_value_to_rl(data[rlg]) |
196 | 213 |
for child in data['childList']: |
197 | 214 |
self.add_text_value_to_child(child) |
198 | 215 |
for person in data['emergencyPersonList']: |
199 | 216 |
self.add_text_value_to_person(person) |
200 | 217 |
return data |
201 | 218 | |
219 |
def get_child_person(self, family_id, child_id, person_id): |
|
220 |
data = self.get_child_person_raw(family_id, child_id, person_id) |
|
221 |
self.add_text_value_to_child_person(data) |
|
222 |
return data |
|
223 | ||
202 | 224 |
def get_child(self, family_id, child_id): |
203 | 225 |
data = self.get_child_raw(family_id, child_id) |
204 | 226 |
self.add_text_value_to_child(data) |
205 | 227 |
return data |
206 | 228 | |
207 | 229 |
def get_person(self, family_id, person_id): |
208 | 230 |
data = self.get_person_raw(family_id, person_id) |
209 | 231 |
self.add_text_value_to_person(data) |
... | ... | |
430 | 452 |
'child_id': {'description': "Numéro de l'enfant"}, |
431 | 453 |
}, |
432 | 454 |
) |
433 | 455 |
def read_child(self, request, NameID, child_id): |
434 | 456 |
family_id = self.get_link(NameID).family_id |
435 | 457 |
data = self.get_child(family_id, child_id) |
436 | 458 |
return {'data': data} |
437 | 459 | |
460 |
@endpoint( |
|
461 |
display_category='Famille', |
|
462 |
description="Informations sur une personne autorisée à récupérer l'enfant", |
|
463 |
perm='can_access', |
|
464 |
name='read-child-person', |
|
465 |
parameters={ |
|
466 |
'NameID': {'description': 'Publik NameID'}, |
|
467 |
'child_id': {'description': "Numéro de l'enfant"}, |
|
468 |
'person_id': {'description': 'Numéro de la personne'}, |
|
469 |
}, |
|
470 |
) |
|
471 |
def read_child_person(self, request, NameID, child_id, person_id): |
|
472 |
family_id = self.get_link(NameID).family_id |
|
473 |
data = self.get_child_person(family_id, child_id, person_id) |
|
474 |
return {'data': data} |
|
475 | ||
438 | 476 |
@endpoint( |
439 | 477 |
display_category='Famille', |
440 | 478 |
description="Vérifier qu'un responsable légal existe en base", |
441 | 479 |
perm='can_access', |
442 | 480 |
name='is-rl-exists', |
443 | 481 |
post={'request_body': {'schema': {'application/json': schemas.ISEXISTS_SCHEMA}}}, |
444 | 482 |
) |
445 | 483 |
def is_rl_exists(self, request, post_data): |
tests/data/toulouse_maelis/R_read_family.xml | ||
---|---|---|
117 | 117 |
<obsAssist1>some obsAssist1 text</obsAssist1> |
118 | 118 |
<obsAssist2>some obsAssist2 text</obsAssist2> |
119 | 119 |
<obsAssist3>some obsAssist3 text</obsAssist3> |
120 | 120 |
<cons1Med>some cons1Med text</cons1Med> |
121 | 121 |
<cons2Med>some cons2Med text</cons2Med> |
122 | 122 |
</fsl> |
123 | 123 |
<bPhoto>true</bPhoto> |
124 | 124 |
<bLeaveAlone>false</bLeaveAlone> |
125 |
<authorizedPersonList> |
|
126 |
<personInfo> |
|
127 |
<num>614719</num> |
|
128 |
<lastname>BENT</lastname> |
|
129 |
<firstname>AMEL</firstname> |
|
130 |
<dateBirth>1985-06-21T00:00:00+02:00</dateBirth> |
|
131 |
<civility>MME</civility> |
|
132 |
<sexe>F</sexe> |
|
133 |
<contact> |
|
134 |
<phone>0123456789</phone> |
|
135 |
<mobile>0623456789</mobile> |
|
136 |
<mail>abent@example.org</mail> |
|
137 |
</contact> |
|
138 |
</personInfo> |
|
139 |
<personQuality> |
|
140 |
<code>T</code> |
|
141 |
<libelle>TANTE</libelle> |
|
142 |
</personQuality> |
|
143 |
</authorizedPersonList> |
|
125 | 144 |
<medicalRecord> |
126 | 145 |
<familyDoctor> |
127 | 146 |
<name>DRE</name> |
128 | 147 |
<phone>0612341234</phone> |
129 | 148 |
<address> |
130 | 149 |
<street1>Alameda</street1> |
131 | 150 |
<zipcode>90220</zipcode> |
132 | 151 |
<town>Compton</town> |
tests/test_toulouse_maelis.py | ||
---|---|---|
589 | 589 |
}, |
590 | 590 |
'CAFInfo': None, |
591 | 591 |
'civility_text': 'Monsieur', |
592 | 592 |
'quality_text': 'PERE', |
593 | 593 |
} |
594 | 594 |
data = resp.json['data']['childList'][0] |
595 | 595 |
del data['fsl'] |
596 | 596 |
del data['medicalRecord'] |
597 |
del data['authorizedPersonList'] |
|
597 | 598 |
assert data == { |
598 | 599 |
'num': '613880', |
599 | 600 |
'lastname': 'DOE', |
600 | 601 |
'firstname': 'JANNIS', |
601 | 602 |
'sexe': 'F', |
602 | 603 |
'sexe_text': 'Féminin', |
603 | 604 |
'birth': {'dateBirth': '1943-01-19T00:00:00+01:00', 'place': None}, |
604 | 605 |
'dietcode': 'RSV', |
605 | 606 |
'dietcode_text': '3- RÉGIME SANS VIANDE', |
606 | 607 |
'bPhoto': True, |
607 | 608 |
'bLeaveAlone': False, |
608 |
'authorizedPersonList': [], |
|
609 | 609 |
'indicatorList': [], |
610 | 610 |
'subscribeSchoolList': [], |
611 | 611 |
'mother': {'num': 613963, 'civility': 'MME', 'firstname': 'JANE', 'lastname': 'DOE'}, |
612 | 612 |
'father': {'num': 613878, 'civility': 'M.', 'firstname': 'JHON', 'lastname': 'DOE'}, |
613 | 613 |
'rl': None, |
614 | 614 |
'subscribeActivityList': [], |
615 | 615 |
'paiInfoBean': { |
616 | 616 |
'code': 'PAIALI', |
... | ... | |
674 | 674 |
'quality': 'T', |
675 | 675 |
'civility': 'MME', |
676 | 676 |
'sexe': None, |
677 | 677 |
'contact': {'phone': '0123456789', 'mobile': None, 'mail': 'pueblo@example.org'}, |
678 | 678 |
'numPerson': 614059, |
679 | 679 |
'civility_text': 'Madame', |
680 | 680 |
'quality_text': 'TANTE', |
681 | 681 |
} |
682 |
assert resp.json['data']['childList'][0]['authorizedPersonList'][0] == { |
|
683 |
'personInfo': { |
|
684 |
'num': 614719, |
|
685 |
'lastname': 'BENT', |
|
686 |
'firstname': 'AMEL', |
|
687 |
'dateBirth': '1985-06-21T00:00:00+02:00', |
|
688 |
'civility': 'MME', |
|
689 |
'civility_text': 'Madame', |
|
690 |
'sexe': 'F', |
|
691 |
'sexe_text': 'Féminin', |
|
692 |
'contact': {'phone': '0123456789', 'mobile': '0623456789', 'mail': 'abent@example.org'}, |
|
693 |
}, |
|
694 |
'personQuality': { |
|
695 |
'code': 'T', |
|
696 |
'code_text': 'TANTE', |
|
697 |
'libelle': 'TANTE', |
|
698 |
}, |
|
699 |
} |
|
682 | 700 | |
683 | 701 | |
684 | 702 |
def test_read_family_not_linked_error(con, app): |
685 | 703 |
url = get_endpoint('read-family') |
686 | 704 | |
687 | 705 |
resp = app.get(url + '?NameID=') |
688 | 706 |
assert resp.json['err'] == 'not-linked' |
689 | 707 |
assert resp.json['err_desc'] == 'User not linked to family' |
... | ... | |
822 | 840 |
@mock.patch('passerelle.utils.Request.get') |
823 | 841 |
@mock.patch('passerelle.utils.Request.post') |
824 | 842 |
def test_read_child(mocked_post, mocked_get, con, app): |
825 | 843 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
826 | 844 |
mocked_post.side_effect = [ |
827 | 845 |
READ_FAMILY, |
828 | 846 |
READ_DIETCODE, |
829 | 847 |
READ_PAI, |
848 |
READ_CIVILITIES, |
|
849 |
READ_QUALITIES, |
|
830 | 850 |
] |
831 | 851 |
url = get_endpoint('read-child') |
832 | 852 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
833 | 853 | |
834 | 854 |
resp = app.get(url + '?NameID=local&child_id=613880') |
835 | 855 |
assert resp.json['err'] == 0 |
836 | 856 |
assert resp.json['data']['firstname'] == 'JANNIS' |
837 | 857 | |
... | ... | |
856 | 876 |
url = get_endpoint('read-child') |
857 | 877 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
858 | 878 | |
859 | 879 |
resp = app.get(url + '?NameID=local&child_id=000000') |
860 | 880 |
assert resp.json['err'] == 'not-found' |
861 | 881 |
assert resp.json['err_desc'] == "no '000000' child on '1312' family" |
862 | 882 | |
863 | 883 | |
884 |
@mock.patch('passerelle.utils.Request.get') |
|
885 |
@mock.patch('passerelle.utils.Request.post') |
|
886 |
def test_read_child_person(mocked_post, mocked_get, con, app): |
|
887 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
888 |
mocked_post.side_effect = [ |
|
889 |
READ_FAMILY, |
|
890 |
READ_CIVILITIES, |
|
891 |
READ_QUALITIES, |
|
892 |
] |
|
893 |
url = get_endpoint('read-child-person') |
|
894 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
895 | ||
896 |
resp = app.get(url + '?NameID=local&child_id=613880&person_id=614719') |
|
897 |
assert resp.json['err'] == 0 |
|
898 |
assert resp.json['data']['personInfo']['firstname'] == 'AMEL' |
|
899 | ||
900 | ||
901 |
def test_read_child_person_not_linked_error(con, app): |
|
902 |
url = get_endpoint('read-child-person') |
|
903 | ||
904 |
resp = app.get(url + '?NameID=local&child_id=613880&person_id=614719') |
|
905 |
assert resp.json['err'] == 'not-linked' |
|
906 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
907 | ||
908 | ||
909 |
@mock.patch('passerelle.utils.Request.get') |
|
910 |
@mock.patch('passerelle.utils.Request.post') |
|
911 |
def test_read_child_person_no_child_error(mocked_post, mocked_get, con, app): |
|
912 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
913 |
mocked_post.side_effect = [ |
|
914 |
READ_FAMILY, |
|
915 |
] |
|
916 |
url = get_endpoint('read-child-person') |
|
917 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
918 | ||
919 |
resp = app.get(url + '?NameID=local&child_id=42&person_id=614719') |
|
920 |
assert resp.json['err'] == 'not-found' |
|
921 |
assert resp.json['err_desc'] == "no '42' child on '1312' family" |
|
922 | ||
923 | ||
924 |
@mock.patch('passerelle.utils.Request.get') |
|
925 |
@mock.patch('passerelle.utils.Request.post') |
|
926 |
def test_read_child_person_no_person_error(mocked_post, mocked_get, con, app): |
|
927 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
928 |
mocked_post.side_effect = [ |
|
929 |
READ_FAMILY, |
|
930 |
READ_CIVILITIES, |
|
931 |
READ_QUALITIES, |
|
932 |
] |
|
933 |
url = get_endpoint('read-child-person') |
|
934 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
935 | ||
936 |
resp = app.get(url + '?NameID=local&child_id=613880&person_id=000000') |
|
937 |
assert resp.json['err'] == 'not-found' |
|
938 |
assert resp.json['err_desc'] == "no '000000' authorized person on '613880' child" |
|
939 | ||
940 | ||
864 | 941 |
@pytest.mark.parametrize( |
865 | 942 |
'post_response, result', |
866 | 943 |
[ |
867 | 944 |
(IS_RL_EXISTS_TRUE, True), |
868 | 945 |
(IS_RL_EXISTS_FALSE, False), |
869 | 946 |
], |
870 | 947 |
) |
871 | 948 |
@mock.patch('passerelle.utils.Request.get') |
872 |
- |