0002-toulouse-maelis-add-quotient-year-filter-on-read-fam.patch
functests/toulouse_maelis/read_family.py | ||
---|---|---|
16 | 16 |
session.verify = False |
17 | 17 |
transport = Transport(session=session) |
18 | 18 |
settings = zeep.Settings(strict=False, xsd_ignore_sequence_order=True) |
19 | 19 |
client = zeep.Client(WSDL_URL, transport=transport, wsse=WSSE, settings=settings) |
20 | 20 | |
21 | 21 |
result = client.service.readFamily( |
22 | 22 |
dossierNumber=family_id, |
23 | 23 |
# schoolYear= |
24 |
# incomeYear=2020, # <-- pour avoir les quotients
|
|
24 |
# incomeYear=2022, # <-- pour filtrer les quotients sur cette année
|
|
25 | 25 |
# referenceYear=2020, |
26 | 26 |
) |
27 | 27 |
print(result) |
28 | 28 | |
29 | 29 | |
30 | 30 |
if __name__ == "__main__": |
31 | 31 |
parser = argparse.ArgumentParser() |
32 | 32 |
parser.add_argument('--verbose', '-v', type=int, default=2, help='display errors') |
functests/toulouse_maelis/test_family.py | ||
---|---|---|
725 | 725 | |
726 | 726 |
# add quotient on another income year |
727 | 727 |
payload['yearRev'] = '2020' |
728 | 728 |
resp = requests.post(url, json=payload) |
729 | 729 |
resp.raise_for_status() |
730 | 730 |
assert resp.json()['err'] == 0 |
731 | 731 |
data = diff_rlg(conn, create_data['name_id'], 1, 'test_update_quotient.json', 'quotientList') |
732 | 732 |
assert len(data['RL1']['quotientList']) == 3 |
733 | ||
734 |
# test read-family with reference year |
|
735 |
url = conn + '/read-family?NameID=%s&income_year=%s' % (create_data['name_id'], '2020') |
|
736 |
resp = requests.get(url) |
|
737 |
resp.raise_for_status() |
|
738 |
res = resp.json() |
|
739 |
assert res['err'] == 0 |
|
740 |
return len(res['data']['RL1']['quotientList']) == 1 |
passerelle/contrib/toulouse_maelis/models.py | ||
---|---|---|
182 | 182 |
return key |
183 | 183 | |
184 | 184 |
def get_link(self, NameID): |
185 | 185 |
try: |
186 | 186 |
return self.link_set.get(name_id=NameID) |
187 | 187 |
except Link.DoesNotExist: |
188 | 188 |
raise APIError('User not linked to family', err_code='not-linked') |
189 | 189 | |
190 |
def get_family_raw(self, family_id): |
|
191 |
response = self.call('Family', 'readFamily', dossierNumber=family_id) |
|
190 |
def get_family_raw(self, family_id, **kwargs):
|
|
191 |
response = self.call('Family', 'readFamily', dossierNumber=family_id, **kwargs)
|
|
192 | 192 |
data = serialize_object(response) |
193 | 193 |
return data |
194 | 194 | |
195 |
def get_rl_raw(self, family_id, rl_id): |
|
196 |
data = self.get_family_raw(family_id) |
|
195 |
def get_rl_raw(self, family_id, rl_id, **kwargs):
|
|
196 |
data = self.get_family_raw(family_id, **kwargs)
|
|
197 | 197 |
if data['RL1']['num'] == rl_id: |
198 | 198 |
return data['RL1'] |
199 | 199 |
elif data['RL2'] and data['RL2']['num'] == rl_id: |
200 | 200 |
return data['RL2'] |
201 | 201 |
raise APIError("no '%s' RL on '%s' family" % (rl_id, family_id), err_code='not-found') |
202 | 202 | |
203 | 203 |
def get_person_raw(self, family_id, person_id): |
204 | 204 |
data = self.get_family_raw(family_id) |
... | ... | |
285 | 285 |
self.add_text_value_to_child(data) |
286 | 286 |
return data |
287 | 287 | |
288 | 288 |
def get_person(self, family_id, person_id): |
289 | 289 |
data = self.get_person_raw(family_id, person_id) |
290 | 290 |
self.add_text_value_to_person(data) |
291 | 291 |
return data |
292 | 292 | |
293 |
def get_rl(self, family_id, rl_id): |
|
294 |
data = self.get_rl_raw(family_id, rl_id) |
|
293 |
def get_rl(self, family_id, rl_id, **kwargs):
|
|
294 |
data = self.get_rl_raw(family_id, rl_id, **kwargs)
|
|
295 | 295 |
self.add_text_value_to_rl(data) |
296 | 296 |
return data |
297 | 297 | |
298 |
def get_family(self, family_id): |
|
299 |
data = self.get_family_raw(family_id) |
|
298 |
def get_family(self, family_id, **kwargs):
|
|
299 |
data = self.get_family_raw(family_id, **kwargs)
|
|
300 | 300 |
self.add_text_value_to_family(data) |
301 | 301 |
return data |
302 | 302 | |
303 | 303 |
def assert_key_in_referential(self, referential_name, key_value, keys_text, required=True): |
304 | 304 |
if not key_value: |
305 | 305 |
if required: |
306 | 306 |
raise APIError("%s is required and could not be None" % keys_text, err_code='field-required') |
307 | 307 |
return |
... | ... | |
689 | 689 |
link.delete() |
690 | 690 |
return {'data': 'ok'} |
691 | 691 | |
692 | 692 |
@endpoint( |
693 | 693 |
display_category='Famille', |
694 | 694 |
description='Informations sur la famille', |
695 | 695 |
perm='can_access', |
696 | 696 |
name='read-family', |
697 |
parameters={'NameID': {'description': 'Publik NameID'}}, |
|
697 |
parameters={ |
|
698 |
'NameID': {'description': 'Publik NameID'}, |
|
699 |
'income_year': {'description': 'Année de revenu pour filtrer les quotients'}, |
|
700 |
}, |
|
698 | 701 |
) |
699 |
def read_family(self, request, NameID): |
|
702 |
def read_family(self, request, NameID, income_year=None):
|
|
700 | 703 |
family_id = self.get_link(NameID).family_id |
701 |
data = self.get_family(family_id) |
|
704 |
data = self.get_family(family_id, incomeYear=income_year)
|
|
702 | 705 |
return {'data': data} |
703 | 706 | |
704 | 707 |
@endpoint( |
705 | 708 |
display_category='Famille', |
706 | 709 |
description="Informations sur un responsable légal", |
707 | 710 |
perm='can_access', |
708 | 711 |
name='read-rl', |
709 | 712 |
parameters={ |
710 | 713 |
'NameID': {'description': 'Publik NameID'}, |
711 | 714 |
'rl_id': {'description': 'Numéro du représentant légal'}, |
715 |
'income_year': {'description': 'Année de revenu pour filtrer les quotients'}, |
|
712 | 716 |
}, |
713 | 717 |
) |
714 |
def read_rl(self, request, NameID, rl_id): |
|
718 |
def read_rl(self, request, NameID, rl_id, income_year=None):
|
|
715 | 719 |
family_id = self.get_link(NameID).family_id |
716 |
data = self.get_rl(family_id, rl_id) |
|
720 |
data = self.get_rl(family_id, rl_id, incomeYear=income_year)
|
|
717 | 721 |
return {'data': data} |
718 | 722 | |
719 | 723 |
@endpoint( |
720 | 724 |
display_category='Famille', |
721 | 725 |
description="Informations sur une personne autorisée à récupérer les enfants ou à prévenir en cas d'urgence", |
722 | 726 |
perm='can_access', |
723 | 727 |
name='read-person', |
724 | 728 |
parameters={ |
tests/data/toulouse_maelis/R_read_family_with_income_year.xml | ||
---|---|---|
1 |
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> |
|
2 |
<soap:Body> |
|
3 |
<ns2:readFamilyResponse xmlns:ns2="family.ws.maelis.sigec.com"> |
|
4 |
<familyResult> |
|
5 |
<number>1312</number> |
|
6 |
<category>BI</category> |
|
7 |
<situation>M</situation> |
|
8 |
<flagCom>true</flagCom> |
|
9 |
<nbChild>2</nbChild> |
|
10 |
<RL1> |
|
11 |
<num>613878</num> |
|
12 |
<lastname>DOE</lastname> |
|
13 |
<firstname>JHON</firstname> |
|
14 |
<quality>PERE</quality> |
|
15 |
<civility>M.</civility> |
|
16 |
<birth> |
|
17 |
<dateBirth>1938-07-26T00:00:00+01:00</dateBirth> |
|
18 |
<place>Rabbat</place> |
|
19 |
<countryCode>99350</countryCode> |
|
20 |
</birth> |
|
21 |
<adresse> |
|
22 |
<idStreet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/> |
|
23 |
<num>170</num> |
|
24 |
<street1>Chateau d'eau</street1> |
|
25 |
<town>Paris</town> |
|
26 |
<zipcode>75014</zipcode> |
|
27 |
</adresse> |
|
28 |
<contact> |
|
29 |
<phone>non</phone> |
|
30 |
<mobile>0777777777</mobile> |
|
31 |
<mail>djhon@example.org</mail> |
|
32 |
<isContactMail>true</isContactMail> |
|
33 |
<isContactSms>true</isContactSms> |
|
34 |
<isInvoicePdf>true</isInvoicePdf> |
|
35 |
</contact> |
|
36 |
<profession> |
|
37 |
<addressPro/> |
|
38 |
</profession> |
|
39 |
<quotientList> |
|
40 |
<yearRev>2020</yearRev> |
|
41 |
<dateStart>2021-01-01T00:00:00+01:00</dateStart> |
|
42 |
<dateEnd>2021-12-31T00:00:00+01:00</dateEnd> |
|
43 |
<mtt>1500.33</mtt> |
|
44 |
<cdquo>QS</cdquo> |
|
45 |
</quotientList> |
|
46 |
</RL1> |
|
47 |
<RL2> |
|
48 |
<num>613879</num> |
|
49 |
<lastname>DOE</lastname> |
|
50 |
<firstname>JANE</firstname> |
|
51 |
<maidenName>SMITH</maidenName> |
|
52 |
<quality>MERE</quality> |
|
53 |
<civility>MME</civility> |
|
54 |
<birth> |
|
55 |
<dateBirth>1940-06-22T00:00:00+02:00</dateBirth> |
|
56 |
<place>Bardot</place> |
|
57 |
<countryCode>99351</countryCode> |
|
58 |
</birth> |
|
59 |
<adresse> |
|
60 |
<idStreet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/> |
|
61 |
<num>170</num> |
|
62 |
<street1>Chateau d'eau</street1> |
|
63 |
<town>Paris</town> |
|
64 |
<zipcode>75014</zipcode> |
|
65 |
</adresse> |
|
66 |
<contact> |
|
67 |
<isContactMail>false</isContactMail> |
|
68 |
<isContactSms>false</isContactSms> |
|
69 |
<isInvoicePdf>false</isInvoicePdf> |
|
70 |
</contact> |
|
71 |
<profession> |
|
72 |
<codeCSP>ART</codeCSP> |
|
73 |
<profession>informaticien</profession> |
|
74 |
<employerName>EO</employerName> |
|
75 |
<phone>0123456789</phone> |
|
76 |
<addressPro> |
|
77 |
<town>Orléans</town> |
|
78 |
</addressPro> |
|
79 |
</profession> |
|
80 |
<CAFInfo> |
|
81 |
<number>789</number> |
|
82 |
<organ>A10007752822</organ> |
|
83 |
</CAFInfo> |
|
84 |
</RL2> |
|
85 |
<emergencyPersonList> |
|
86 |
<numPerson>614059</numPerson> |
|
87 |
<civility>MME</civility> |
|
88 |
<firstname>KENY</firstname> |
|
89 |
<lastname>ARKANA</lastname> |
|
90 |
<dateBirth>1982-12-20T00:00:00+01:00</dateBirth> |
|
91 |
<quality>T</quality> |
|
92 |
<contact> |
|
93 |
<phone>0123456789</phone> |
|
94 |
<mail>pueblo@example.org</mail> |
|
95 |
</contact> |
|
96 |
</emergencyPersonList> |
|
97 |
<childList> |
|
98 |
<num>613880</num> |
|
99 |
<lastname>DOE</lastname> |
|
100 |
<firstname>JANNIS</firstname> |
|
101 |
<sexe>F</sexe> |
|
102 |
<birth> |
|
103 |
<dateBirth>1943-01-19T00:00:00+01:00</dateBirth> |
|
104 |
<place>Saint-louis</place> |
|
105 |
<communeCode>91122</communeCode> |
|
106 |
<countryCode>99100</countryCode> |
|
107 |
</birth> |
|
108 |
<dietcode>RSV</dietcode> |
|
109 |
<bPhoto>true</bPhoto> |
|
110 |
<bLeaveAlone>false</bLeaveAlone> |
|
111 |
<authorizedPersonList> |
|
112 |
<personInfo> |
|
113 |
<num>614719</num> |
|
114 |
<lastname>BENT</lastname> |
|
115 |
<firstname>AMEL</firstname> |
|
116 |
<dateBirth>1985-06-21T00:00:00+02:00</dateBirth> |
|
117 |
<civility>MME</civility> |
|
118 |
<sexe>F</sexe> |
|
119 |
<contact> |
|
120 |
<phone>0123456789</phone> |
|
121 |
<mobile>0623456789</mobile> |
|
122 |
<mail>abent@example.org</mail> |
|
123 |
</contact> |
|
124 |
</personInfo> |
|
125 |
<personQuality> |
|
126 |
<code>T</code> |
|
127 |
<libelle>TANTE</libelle> |
|
128 |
</personQuality> |
|
129 |
</authorizedPersonList> |
|
130 |
<medicalRecord> |
|
131 |
<familyDoctor> |
|
132 |
<name>DRE</name> |
|
133 |
<phone>0612341234</phone> |
|
134 |
<address> |
|
135 |
<street1>Alameda</street1> |
|
136 |
<zipcode>90220</zipcode> |
|
137 |
<town>Compton</town> |
|
138 |
</address> |
|
139 |
</familyDoctor> |
|
140 |
<allergy1>butterscotch, imitation butterscotch, glow-in-the-dark monster make-up</allergy1> |
|
141 |
<allergy2>shrimp and cauliflower</allergy2> |
|
142 |
<comment1>the shrimp allergy isn't fully identified</comment1> |
|
143 |
<observ1>Ay Caramba!</observ1> |
|
144 |
<observ2>Eat my shorts!</observ2> |
|
145 |
<isAuthHospital>true</isAuthHospital> |
|
146 |
<hospital>Springfield General Hospital</hospital> |
|
147 |
<vaccinList> |
|
148 |
<code>ROR</code> |
|
149 |
<label>ROUGEOLE-OREILLONS-RUBEOLE</label> |
|
150 |
<vaccinationDate>2012-02-22T00:00:00+01:00</vaccinationDate> |
|
151 |
</vaccinList> |
|
152 |
<vaccinList> |
|
153 |
<code>DTC</code> |
|
154 |
<label>DIPHTERIE TETANOS COQUELUCHE</label> |
|
155 |
<vaccinationDate>2011-01-11T00:00:00+01:00</vaccinationDate> |
|
156 |
</vaccinList> |
|
157 |
<vaccinList> |
|
158 |
<code>ROR</code> |
|
159 |
<label>ROUGEOLE-OREILLONS-RUBEOLE</label> |
|
160 |
<vaccinationDate>1970-01-11T00:00:00+01:00</vaccinationDate> |
|
161 |
</vaccinList> |
|
162 |
</medicalRecord> |
|
163 |
<mother> |
|
164 |
<num>613963</num> |
|
165 |
<civility>MME</civility> |
|
166 |
<firstname>JANE</firstname> |
|
167 |
<lastname>DOE</lastname> |
|
168 |
</mother> |
|
169 |
<father> |
|
170 |
<num>613878</num> |
|
171 |
<civility>M.</civility> |
|
172 |
<firstname>JHON</firstname> |
|
173 |
<lastname>DOE</lastname> |
|
174 |
</father> |
|
175 |
<paiInfoBean> |
|
176 |
<code>PAIALI</code> |
|
177 |
<dateDeb>2022-01-01T00:00:00+01:00</dateDeb> |
|
178 |
<dateFin>2022-12-31T00:00:00+01:00</dateFin> |
|
179 |
<description>bla bla PAI</description> |
|
180 |
</paiInfoBean> |
|
181 |
</childList> |
|
182 |
<childList> |
|
183 |
<num>613987</num> |
|
184 |
<lastname>DOE</lastname> |
|
185 |
<firstname>JOHNNY ALLEN</firstname> |
|
186 |
<sexe>M</sexe> |
|
187 |
<birth> |
|
188 |
<dateBirth>1942-11-27T00:00:00+01:00</dateBirth> |
|
189 |
<place>Seattle</place> |
|
190 |
</birth> |
|
191 |
<bPhoto>false</bPhoto> |
|
192 |
<bLeaveAlone>false</bLeaveAlone> |
|
193 |
<paiInfoBean/> |
|
194 |
</childList> |
|
195 |
<childList> |
|
196 |
<num>614051</num> |
|
197 |
<lastname>DOE</lastname> |
|
198 |
<firstname>ROBERT</firstname> |
|
199 |
<sexe>M</sexe> |
|
200 |
<birth> |
|
201 |
<dateBirth>1941-05-24T00:00:00+02:00</dateBirth> |
|
202 |
<place>Duluth</place> |
|
203 |
</birth> |
|
204 |
<bPhoto>true</bPhoto> |
|
205 |
<bLeaveAlone>false</bLeaveAlone> |
|
206 |
<paiInfoBean/> |
|
207 |
</childList> |
|
208 |
</familyResult> |
|
209 |
</ns2:readFamilyResponse> |
|
210 |
</soap:Body> |
|
211 |
</soap:Envelope> |
tests/test_toulouse_maelis.py | ||
---|---|---|
39 | 39 |
ACTIVITY_SERVICE_WSDL = FakedResponse(content=get_xml_file('ActivityService.wsdl'), status_code=200) |
40 | 40 |
INVOICE_SERVICE_WSDL = FakedResponse(content=get_xml_file('InvoiceService.wsdl'), status_code=200) |
41 | 41 |
FAILED_AUTH = FakedResponse(content=get_xml_file('R_failed_authentication.xml'), status_code=500) |
42 | 42 |
ISWSRUNNING_TRUE = FakedResponse(content=get_xml_file('R_is_ws_running.xml') % b'true', status_code=200) |
43 | 43 |
ISWSRUNNING_FALSE = FakedResponse(content=get_xml_file('R_is_ws_running.xml') % b'false', status_code=200) |
44 | 44 |
READ_FAMILY = FakedResponse(content=get_xml_file('R_read_family.xml'), status_code=200) |
45 | 45 |
READ_FAMILY_LAX = FakedResponse(content=get_xml_file('R_read_family_relax.xml'), status_code=200) |
46 | 46 |
READ_FAMILY_ORD = FakedResponse(content=get_xml_file('R_read_family_reordered.xml'), status_code=200) |
47 |
READ_FAMILY_QUOTIENT = FakedResponse( |
|
48 |
content=get_xml_file('R_read_family_with_income_year.xml'), status_code=200 |
|
49 |
) |
|
47 | 50 |
READ_RL1_FAMILY = FakedResponse(content=get_xml_file('R_read_family_with_only_rl1.xml'), status_code=200) |
48 | 51 |
IS_RL_EXISTS_TRUE = FakedResponse(content=get_xml_file('R_is_rl_exists.xml') % b'true', status_code=200) |
49 | 52 |
IS_RL_EXISTS_FALSE = FakedResponse(content=get_xml_file('R_is_rl_exists.xml') % b'false', status_code=200) |
50 | 53 |
IS_CHILD_EXISTS_TRUE = FakedResponse(content=get_xml_file('R_is_child_exists.xml') % b'true', status_code=200) |
51 | 54 |
IS_CHILD_EXISTS_FALSE = FakedResponse( |
52 | 55 |
content=get_xml_file('R_is_child_exists.xml') % b'false', status_code=200 |
53 | 56 |
) |
54 | 57 |
CREATE_FAMILY = FakedResponse(content=get_xml_file('R_create_family.xml'), status_code=200) |
... | ... | |
853 | 856 |
url = get_endpoint('read-rl') |
854 | 857 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
855 | 858 | |
856 | 859 |
resp = app.get(url + '?NameID=local&rl_id=613878') |
857 | 860 |
assert resp.json['err'] == 0 |
858 | 861 |
assert resp.json['data']['firstname'] == 'JHON' |
859 | 862 | |
860 | 863 | |
864 |
@mock.patch('passerelle.utils.Request.get') |
|
865 |
@mock.patch('passerelle.utils.Request.post') |
|
866 |
def test_read_rl1_with_income_year(mocked_post, mocked_get, con, app): |
|
867 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
868 |
mocked_post.return_value = READ_FAMILY_QUOTIENT |
|
869 |
url = get_endpoint('read-rl') |
|
870 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
871 | ||
872 |
resp = app.get(url + '?NameID=local&rl_id=613878&income_year=2020') |
|
873 |
assert resp.json['err'] == 0 |
|
874 |
assert resp.json['data']['quotientList'] == [ |
|
875 |
{ |
|
876 |
'yearRev': 2020, |
|
877 |
'dateStart': '2021-01-01T00:00:00+01:00', |
|
878 |
'dateEnd': '2021-12-31T00:00:00+01:00', |
|
879 |
'mtt': 1500.33, |
|
880 |
'cdquo': 'QS', |
|
881 |
'cdquo_text': 'QUOTIENT SCOLAIRE', |
|
882 |
'codeUti': None, |
|
883 |
} |
|
884 |
] |
|
885 | ||
886 | ||
861 | 887 |
@mock.patch('passerelle.utils.Request.get') |
862 | 888 |
@mock.patch('passerelle.utils.Request.post') |
863 | 889 |
def test_read_rl2(mocked_post, mocked_get, con, app): |
864 | 890 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
865 | 891 |
mocked_post.return_value = READ_FAMILY |
866 | 892 |
url = get_endpoint('read-rl') |
867 | 893 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
868 | 894 | |
869 |
- |