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 | ||
---|---|---|
732 | 732 | |
733 | 733 |
# add quotient on another income year |
734 | 734 |
payload['yearRev'] = '2020' |
735 | 735 |
resp = requests.post(url, json=payload) |
736 | 736 |
resp.raise_for_status() |
737 | 737 |
assert resp.json()['err'] == 0 |
738 | 738 |
data = diff_rlg(conn, create_data['name_id'], 1, 'test_update_quotient.json', 'quotientList') |
739 | 739 |
assert len(data['RL1']['quotientList']) == 3 |
740 | ||
741 |
# test read-family with reference year |
|
742 |
url = conn + '/read-family?NameID=%s&income_year=%s' % (create_data['name_id'], '2020') |
|
743 |
resp = requests.get(url) |
|
744 |
resp.raise_for_status() |
|
745 |
res = resp.json() |
|
746 |
assert res['err'] == 0 |
|
747 |
return len(res['data']['RL1']['quotientList']) == 1 |
passerelle/contrib/toulouse_maelis/models.py | ||
---|---|---|
115 | 115 |
return key |
116 | 116 | |
117 | 117 |
def get_link(self, NameID): |
118 | 118 |
try: |
119 | 119 |
return self.link_set.get(name_id=NameID) |
120 | 120 |
except Link.DoesNotExist: |
121 | 121 |
raise APIError('User not linked to family', err_code='not-linked') |
122 | 122 | |
123 |
def get_family_raw(self, family_id): |
|
124 |
response = self.call('Family', 'readFamily', dossierNumber=family_id) |
|
123 |
def get_family_raw(self, family_id, **kwargs):
|
|
124 |
response = self.call('Family', 'readFamily', dossierNumber=family_id, **kwargs)
|
|
125 | 125 |
data = serialize_object(response) |
126 | 126 |
return data |
127 | 127 | |
128 |
def get_rl_raw(self, family_id, rl_id): |
|
129 |
data = self.get_family_raw(family_id) |
|
128 |
def get_rl_raw(self, family_id, rl_id, **kwargs):
|
|
129 |
data = self.get_family_raw(family_id, **kwargs)
|
|
130 | 130 |
if data['RL1']['num'] == rl_id: |
131 | 131 |
return data['RL1'] |
132 | 132 |
elif data['RL2'] and data['RL2']['num'] == rl_id: |
133 | 133 |
return data['RL2'] |
134 | 134 |
raise APIError("no '%s' RL on '%s' family" % (rl_id, family_id), err_code='not-found') |
135 | 135 | |
136 | 136 |
def get_person_raw(self, family_id, person_id): |
137 | 137 |
data = self.get_family_raw(family_id) |
... | ... | |
218 | 218 |
self.add_text_value_to_child(data) |
219 | 219 |
return data |
220 | 220 | |
221 | 221 |
def get_person(self, family_id, person_id): |
222 | 222 |
data = self.get_person_raw(family_id, person_id) |
223 | 223 |
self.add_text_value_to_person(data) |
224 | 224 |
return data |
225 | 225 | |
226 |
def get_rl(self, family_id, rl_id): |
|
227 |
data = self.get_rl_raw(family_id, rl_id) |
|
226 |
def get_rl(self, family_id, rl_id, **kwargs):
|
|
227 |
data = self.get_rl_raw(family_id, rl_id, **kwargs)
|
|
228 | 228 |
self.add_text_value_to_rl(data) |
229 | 229 |
return data |
230 | 230 | |
231 |
def get_family(self, family_id): |
|
232 |
data = self.get_family_raw(family_id) |
|
231 |
def get_family(self, family_id, **kwargs):
|
|
232 |
data = self.get_family_raw(family_id, **kwargs)
|
|
233 | 233 |
self.add_text_value_to_family(data) |
234 | 234 |
return data |
235 | 235 | |
236 | 236 |
def assert_key_in_referential(self, referential_name, key_value, keys_text, required=True): |
237 | 237 |
if not key_value: |
238 | 238 |
if required: |
239 | 239 |
raise APIError("%s is required and could not be None" % keys_text, err_code='field-required') |
240 | 240 |
return |
... | ... | |
498 | 498 |
link.delete() |
499 | 499 |
return {'data': 'ok'} |
500 | 500 | |
501 | 501 |
@endpoint( |
502 | 502 |
display_category='Famille', |
503 | 503 |
description='Informations sur la famille', |
504 | 504 |
perm='can_access', |
505 | 505 |
name='read-family', |
506 |
parameters={'NameID': {'description': 'Publik NameID'}}, |
|
506 |
parameters={ |
|
507 |
'NameID': {'description': 'Publik NameID'}, |
|
508 |
'income_year': {'description': 'Année de revenu pour filtrer les quotients'}, |
|
509 |
}, |
|
507 | 510 |
) |
508 |
def read_family(self, request, NameID): |
|
511 |
def read_family(self, request, NameID, income_year=None):
|
|
509 | 512 |
family_id = self.get_link(NameID).family_id |
510 |
data = self.get_family(family_id) |
|
513 |
data = self.get_family(family_id, incomeYear=income_year)
|
|
511 | 514 |
return {'data': data} |
512 | 515 | |
513 | 516 |
@endpoint( |
514 | 517 |
display_category='Famille', |
515 | 518 |
description="Informations sur un responsable légal", |
516 | 519 |
perm='can_access', |
517 | 520 |
name='read-rl', |
518 | 521 |
parameters={ |
519 | 522 |
'NameID': {'description': 'Publik NameID'}, |
520 | 523 |
'rl_id': {'description': 'Numéro du représentant légal'}, |
524 |
'income_year': {'description': 'Année de revenu pour filtrer les quotients'}, |
|
521 | 525 |
}, |
522 | 526 |
) |
523 |
def read_rl(self, request, NameID, rl_id): |
|
527 |
def read_rl(self, request, NameID, rl_id, income_year=None):
|
|
524 | 528 |
family_id = self.get_link(NameID).family_id |
525 |
data = self.get_rl(family_id, rl_id) |
|
529 |
data = self.get_rl(family_id, rl_id, incomeYear=income_year)
|
|
526 | 530 |
return {'data': data} |
527 | 531 | |
528 | 532 |
@endpoint( |
529 | 533 |
display_category='Famille', |
530 | 534 |
description="Informations sur une personne autorisée à récupérer les enfants ou à prévenir en cas d'urgence", |
531 | 535 |
perm='can_access', |
532 | 536 |
name='read-person', |
533 | 537 |
parameters={ |
tests/data/toulouse_maelis/R_read_family_with_quotients.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_quotients.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 |
READ_CATEGORIES = FakedResponse(content=get_xml_file('R_read_category_list.xml'), status_code=200) |
49 | 52 |
READ_CIVILITIES = FakedResponse(content=get_xml_file('R_read_civility_list.xml'), status_code=200) |
50 | 53 |
READ_CSP = FakedResponse(content=get_xml_file('R_read_csp_list.xml'), status_code=200) |
51 | 54 |
READ_DIETCODE = FakedResponse(content=get_xml_file('R_read_dietcode_list.xml'), status_code=200) |
52 | 55 |
READ_ORGAN = FakedResponse(content=get_xml_file('R_read_organ_list.xml'), status_code=200) |
53 | 56 |
READ_PAI = FakedResponse(content=get_xml_file('R_read_pai_list.xml'), status_code=200) |
54 | 57 |
READ_QUALITIES = FakedResponse(content=get_xml_file('R_read_quality_list.xml'), status_code=200) |
... | ... | |
770 | 773 |
url = get_endpoint('read-rl') |
771 | 774 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
772 | 775 | |
773 | 776 |
resp = app.get(url + '?NameID=local&rl_id=613878') |
774 | 777 |
assert resp.json['err'] == 0 |
775 | 778 |
assert resp.json['data']['firstname'] == 'JHON' |
776 | 779 | |
777 | 780 | |
781 |
@mock.patch('passerelle.utils.Request.get') |
|
782 |
@mock.patch('passerelle.utils.Request.post') |
|
783 |
def test_read_rl1_with_quotients(mocked_post, mocked_get, con, app): |
|
784 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
785 |
mocked_post.side_effect = [ |
|
786 |
READ_FAMILY_QUOTIENT, |
|
787 |
READ_CIVILITIES, |
|
788 |
READ_QUALITIES, |
|
789 |
READ_QUOTIENT, |
|
790 |
] |
|
791 |
url = get_endpoint('read-rl') |
|
792 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
793 | ||
794 |
resp = app.get(url + '?NameID=local&rl_id=613878&income_year=2020') |
|
795 |
assert resp.json['err'] == 0 |
|
796 |
assert resp.json['data']['quotientList'] == [ |
|
797 |
{ |
|
798 |
'yearRev': 2020, |
|
799 |
'dateStart': '2021-01-01T00:00:00+01:00', |
|
800 |
'dateEnd': '2021-12-31T00:00:00+01:00', |
|
801 |
'mtt': 1500.33, |
|
802 |
'cdquo': 'QS', |
|
803 |
'cdquo_text': 'QUOTIENT SCOLAIRE', |
|
804 |
'codeUti': None, |
|
805 |
} |
|
806 |
] |
|
807 | ||
808 | ||
778 | 809 |
@mock.patch('passerelle.utils.Request.get') |
779 | 810 |
@mock.patch('passerelle.utils.Request.post') |
780 | 811 |
def test_read_rl2(mocked_post, mocked_get, con, app): |
781 | 812 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
782 | 813 |
mocked_post.side_effect = [ |
783 | 814 |
READ_FAMILY, |
784 | 815 |
READ_CIVILITIES, |
785 | 816 |
READ_QUALITIES, |
786 |
- |