0003-toulouse-maelis-add-endpoint-to-add-child-person-698.patch
passerelle/contrib/toulouse_maelis/models.py | ||
---|---|---|
850 | 850 |
'nbChild': family['nbChild'], |
851 | 851 |
'nbTotalChild': family['nbTotalChild'], |
852 | 852 |
'nbAES': family['nbAES'], |
853 | 853 |
kind + 'PersonList': [{'personList': personList}], |
854 | 854 |
} |
855 | 855 |
self.call('Family', 'updateFamily', **payload) |
856 | 856 |
return {'data': 'ok'} |
857 | 857 | |
858 |
@endpoint( |
|
859 |
display_category='Famille', |
|
860 |
description="Création d'une personne autorisée à récupérer l'enfant", |
|
861 |
name='create-child-person', |
|
862 |
perm='can_access', |
|
863 |
parameters={ |
|
864 |
'NameID': {'description': 'Publik NameID'}, |
|
865 |
'child_id': {'description': "Numéro de l'enfant"}, |
|
866 |
}, |
|
867 |
post={'request_body': {'schema': {'application/json': schemas.CHILDPERSON2_SCHEMA}}}, |
|
868 |
) |
|
869 |
def create_child_person(self, request, NameID, child_id, post_data): |
|
870 |
family_id = self.get_link(NameID).family_id |
|
871 |
child = self.get_child_raw(family_id, child_id) |
|
872 |
self.replace_null_values(post_data) |
|
873 | ||
874 |
personList = child['authorizedPersonList'] |
|
875 |
personList.append(post_data) |
|
876 |
req = { |
|
877 |
'numFamily': family_id, |
|
878 |
'numPerson': child_id, |
|
879 |
'bLeaveAlone': child['bLeaveAlone'], |
|
880 |
'bPhoto': child['bPhoto'], |
|
881 |
'personList': personList, |
|
882 |
} |
|
883 |
self.call('Family', 'updateChildAutorization', updateChildAutorizationRequest=req) |
|
884 |
return {'data': 'ok'} |
|
885 | ||
858 | 886 |
@endpoint( |
859 | 887 |
display_category='Famille', |
860 | 888 |
description="Créer ou mettre à jour le régime alimentaire d'un enfant", |
861 | 889 |
name='update-child-dietcode', |
862 | 890 |
perm='can_access', |
863 | 891 |
parameters={ |
864 | 892 |
'NameID': {'description': 'Publik NameID'}, |
865 | 893 |
'child_id': {'description': "Numéro de l'enfant"}, |
passerelle/contrib/toulouse_maelis/schemas.py | ||
---|---|---|
694 | 694 |
'properties': { |
695 | 695 |
'adresse': ADDRESS_SCHEMA, |
696 | 696 |
'contact': CONTACT_SCHEMA, |
697 | 697 |
'profession': PROFESSION_SCHEMA, |
698 | 698 |
'CAFInfo': CAFINFO_SCHEMA, |
699 | 699 |
}, |
700 | 700 |
'unflatten': True, |
701 | 701 |
} |
702 | ||
703 |
CHILDPERSON_SCHEMA = FAMILYPERSON_SCHEMA |
|
704 |
del CHILDPERSON_SCHEMA['properties']['quality'] |
|
705 | ||
706 |
PERSONQUALITY_SCHEMA = { |
|
707 |
'$schema': 'http://json-schema.org/draft-04/schema#', |
|
708 |
'title': 'Child person quality', |
|
709 |
'description': "Informations sur la qualité des personnes autorisées à venir chercher l'enfant", |
|
710 |
'type': 'object', |
|
711 |
'required': ['code'], |
|
712 |
'properties': { |
|
713 |
'code': { |
|
714 |
'description': 'Le code', |
|
715 |
'type': 'string', |
|
716 |
}, |
|
717 |
}, |
|
718 |
} |
|
719 | ||
720 |
CHILDPERSON2_SCHEMA = { |
|
721 |
'$schema': 'http://json-schema.org/draft-04/schema#', |
|
722 |
'title': 'Family persons', |
|
723 |
'description': "Informations sur les personnes autorisées à venir chercher l'enfant avec leur qualité", |
|
724 |
'type': 'object', |
|
725 |
'required': ['personInfo', 'personQuality'], |
|
726 |
'properties': { |
|
727 |
'personInfo': CHILDPERSON_SCHEMA, |
|
728 |
'personQuality': PERSONQUALITY_SCHEMA, |
|
729 |
}, |
|
730 |
'unflatten': True, |
|
731 |
} |
tests/data/toulouse_maelis/Q_create_child_person.xml | ||
---|---|---|
1 |
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> |
|
2 |
<soap-env:Header> |
|
3 |
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> |
|
4 |
<wsse:UsernameToken> |
|
5 |
<wsse:Username>maelis-webservice</wsse:Username> |
|
6 |
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password> |
|
7 |
</wsse:UsernameToken> |
|
8 |
</wsse:Security> |
|
9 |
</soap-env:Header> |
|
10 |
<soap-env:Body> |
|
11 |
<ns0:updateChildAutorization xmlns:ns0="family.ws.maelis.sigec.com"> |
|
12 |
<updateChildAutorizationRequest> |
|
13 |
<numFamily>1312</numFamily> |
|
14 |
<numPerson>613880</numPerson> |
|
15 |
<personList> |
|
16 |
<personInfo> |
|
17 |
<num>614719</num> |
|
18 |
<civility>MME</civility> |
|
19 |
<lastname>BENT</lastname> |
|
20 |
<firstname>AMEL</firstname> |
|
21 |
<dateBirth>1985-06-21T00:00:00+02:00</dateBirth> |
|
22 |
<sexe>F</sexe> |
|
23 |
<contact> |
|
24 |
<phone>0123456789</phone> |
|
25 |
<mobile>0623456789</mobile> |
|
26 |
<mail>abent@example.org</mail> |
|
27 |
</contact> |
|
28 |
</personInfo> |
|
29 |
<personQuality> |
|
30 |
<code>T</code> |
|
31 |
<libelle>TANTE</libelle> |
|
32 |
</personQuality> |
|
33 |
</personList> |
|
34 |
<personList> |
|
35 |
<personInfo> |
|
36 |
<civility>MME</civility> |
|
37 |
<lastname>Ross</lastname> |
|
38 |
<firstname>Diana</firstname> |
|
39 |
<dateBirth>1944-03-26</dateBirth> |
|
40 |
<contact> |
|
41 |
<phone>0199999999</phone> |
|
42 |
<mobile>0723456789</mobile> |
|
43 |
<mail>dross@example.org</mail> |
|
44 |
</contact> |
|
45 |
</personInfo> |
|
46 |
<personQuality> |
|
47 |
<code>TUTEUR</code> |
|
48 |
</personQuality> |
|
49 |
</personList> |
|
50 |
<bLeaveAlone>false</bLeaveAlone> |
|
51 |
<bPhoto>true</bPhoto> |
|
52 |
</updateChildAutorizationRequest> |
|
53 |
</ns0:updateChildAutorization> |
|
54 |
</soap-env:Body> |
|
55 |
</soap-env:Envelope> |
tests/data/toulouse_maelis/R_update_child_authorization.xml | ||
---|---|---|
1 |
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> |
|
2 |
<soap:Body> |
|
3 |
<ns2:updateChildAutorizationResponse xmlns:ns2="family.ws.maelis.sigec.com"/> |
|
4 |
</soap:Body> |
|
5 |
</soap:Envelope> |
tests/test_toulouse_maelis.py | ||
---|---|---|
70 | 70 |
UPDATE_PAI = FakedResponse(content=get_xml_file('R_update_child_pai.xml'), status_code=200) |
71 | 71 |
UPDATE_PAI_500 = FakedResponse(content=get_xml_file('R_update_child_pai_soap_error.xml'), status_code=500) |
72 | 72 |
UPDATE_FSL = FakedResponse(content=get_xml_file('R_update_child_fsl.xml'), status_code=200) |
73 | 73 |
UPDATE_FSL_500 = FakedResponse(content=get_xml_file('R_update_child_fsl_soap_error.xml'), status_code=500) |
74 | 74 |
UPDATE_MEDICAL = FakedResponse(content=get_xml_file('R_update_child_fsl.xml'), status_code=200) |
75 | 75 |
UPDATE_MEDICAL_500 = FakedResponse( |
76 | 76 |
content=get_xml_file('R_update_child_medical_record_soap_error.xml'), status_code=500 |
77 | 77 |
) |
78 |
UPDATE_CHILD_AUTO = FakedResponse(content=get_xml_file('R_update_child_authorization.xml'), status_code=200) |
|
78 | 79 | |
79 | 80 | |
80 | 81 |
def assert_sent_payload(mocked_post, query_file): |
81 | 82 |
soap_sent = etree.tostring(etree.fromstring(mocked_post.call_args.kwargs['data']), pretty_print=True) |
82 | 83 |
expected = etree.tostring(etree.fromstring(get_xml_file(query_file)), pretty_print=True) |
83 | 84 |
assert soap_sent.decode() == expected.decode() |
84 | 85 | |
85 | 86 | |
... | ... | |
1832 | 1833 |
url = get_endpoint('delete-person') |
1833 | 1834 | |
1834 | 1835 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
1835 | 1836 |
resp = app.post_json(url + '?NameID=local&person_id=000000&kind=emergency') |
1836 | 1837 |
assert resp.json['err'] == 'not-found' |
1837 | 1838 |
assert resp.json['err_desc'] == "no '000000' authorized person on '1312' family" |
1838 | 1839 | |
1839 | 1840 | |
1841 |
@mock.patch('passerelle.utils.Request.get') |
|
1842 |
@mock.patch('passerelle.utils.Request.post') |
|
1843 |
def test_create_child_person(mocked_post, mocked_get, con, app): |
|
1844 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
1845 |
mocked_post.side_effect = [READ_FAMILY, UPDATE_CHILD_AUTO] |
|
1846 |
url = get_endpoint('create-child-person') |
|
1847 |
params = { |
|
1848 |
'personInfo/civility': 'MME', |
|
1849 |
'personInfo/firstname': 'Diana', |
|
1850 |
'personInfo/lastname': 'Ross', |
|
1851 |
'personInfo/dateBirth': '1944-03-26', |
|
1852 |
'personInfo/contact/phone': '0199999999', |
|
1853 |
'personInfo/contact/mobile': '0723456789', |
|
1854 |
'personInfo/contact/mail': 'dross@example.org', |
|
1855 |
'personQuality/code': 'TUTEUR', |
|
1856 |
} |
|
1857 | ||
1858 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
1859 |
resp = app.post_json(url + '?NameID=local&child_id=613880', params=params) |
|
1860 |
assert_sent_payload(mocked_post, 'Q_create_child_person.xml') |
|
1861 |
assert resp.json['err'] == 0 |
|
1862 | ||
1863 | ||
1864 |
def test_create_child_person_not_linked_error(con, app): |
|
1865 |
url = get_endpoint('create-child-person') |
|
1866 |
params = { |
|
1867 |
'personInfo/civility': 'MME', |
|
1868 |
'personInfo/firstname': 'Diana', |
|
1869 |
'personInfo/lastname': 'Ross', |
|
1870 |
'personInfo/dateBirth': '1944-03-26', |
|
1871 |
'personInfo/contact/phone': '01999999999', |
|
1872 |
'personInfo/contact/mobile': '0723456789', |
|
1873 |
'personInfo/contact/mail': 'dross@example.org', |
|
1874 |
'personQuality/code': 'TUTEUR', |
|
1875 |
} |
|
1876 | ||
1877 |
resp = app.post_json(url + '?NameID=local&child_id=613880', params=params) |
|
1878 |
assert resp.json['err'] == 'not-linked' |
|
1879 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
1880 | ||
1881 | ||
1882 |
@mock.patch('passerelle.utils.Request.get') |
|
1883 |
@mock.patch('passerelle.utils.Request.post') |
|
1884 |
def test_create_child_person_no_child_error(mocked_post, mocked_get, con, app): |
|
1885 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
1886 |
mocked_post.side_effect = [READ_FAMILY] |
|
1887 |
url = get_endpoint('create-child-person') |
|
1888 |
params = { |
|
1889 |
'personInfo/civility': 'MME', |
|
1890 |
'personInfo/firstname': 'Diana', |
|
1891 |
'personInfo/lastname': 'Ross', |
|
1892 |
'personInfo/dateBirth': '1944-03-26', |
|
1893 |
'personInfo/contact/phone': '01999999999', |
|
1894 |
'personInfo/contact/mobile': '0723456789', |
|
1895 |
'personInfo/contact/mail': 'dross@example.org', |
|
1896 |
'personQuality/code': 'TUTEUR', |
|
1897 |
} |
|
1898 | ||
1899 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
1900 |
resp = app.post_json(url + '?NameID=local&child_id=42', params=params) |
|
1901 |
assert resp.json['err'] == 'not-found' |
|
1902 |
assert resp.json['err_desc'] == "no '42' child on '1312' family" |
|
1903 | ||
1904 | ||
1840 | 1905 |
@mock.patch('passerelle.utils.Request.get') |
1841 | 1906 |
@mock.patch('passerelle.utils.Request.post') |
1842 | 1907 |
def test_update_child_dietcode(mocked_post, mocked_get, con, app): |
1843 | 1908 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
1844 | 1909 |
mocked_post.return_value = UPDATE_DIETCODE |
1845 | 1910 |
url = get_endpoint('update-child-dietcode') |
1846 | 1911 | |
1847 | 1912 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
1848 |
- |