0001-toulouse_maelis-add-webservices-to-manage-persons-67.patch
passerelle/contrib/toulouse_maelis/models.py | ||
---|---|---|
108 | 108 |
return key |
109 | 109 | |
110 | 110 |
def get_link(self, NameID): |
111 | 111 |
try: |
112 | 112 |
return self.link_set.get(name_id=NameID) |
113 | 113 |
except Link.DoesNotExist: |
114 | 114 |
raise APIError('User not linked to family', err_code='not-linked') |
115 | 115 | |
116 |
def get_family(self, family_id): |
|
116 |
def get_family_raw(self, family_id):
|
|
117 | 117 |
response = self.call('Family', 'readFamily', dossierNumber=family_id) |
118 | 118 |
data = serialize_object(response) |
119 | 119 | |
120 |
# make emergencyPersonList keys egal to authorizedPersonList |
|
121 |
for person in data['emergencyPersonList']: |
|
122 |
person['numPerson'] = person['num'] |
|
123 |
person['dateBirth'] = '1970-01-01' # I need a date |
|
124 |
del person['num'] |
|
125 |
del person['id'] |
|
126 |
return data |
|
127 | ||
128 |
def get_family(self, family_id): |
|
129 |
data = self.get_family_raw(family_id) |
|
130 | ||
120 | 131 |
def add_text_value(referential_name, data, keys): |
121 | 132 |
last_key = keys.pop() |
122 | 133 |
for key in keys: |
123 | 134 |
if not isinstance(data, dict) or not key in data: |
124 | 135 |
return |
125 | 136 |
data = data[key] |
126 | 137 |
if isinstance(data, dict) and last_key in data and data[last_key] is not None: |
127 | 138 |
data[last_key + '_text'] = self.get_referential_value(referential_name, data[last_key]) |
... | ... | |
131 | 142 |
add_text_value('Situation', data, ['situation']) |
132 | 143 |
for rlg in 'RL1', 'RL2': |
133 | 144 |
add_text_value('Civility', data, [rlg, 'civility']) |
134 | 145 |
add_text_value('Quality', data, [rlg, 'quality']) |
135 | 146 |
add_text_value('Complement', data, [rlg, 'adresse', 'numComp']) |
136 | 147 |
add_text_value('CSP', data, [rlg, 'profession', 'codeCSP']) |
137 | 148 |
for child in data['childList']: |
138 | 149 |
add_text_value('Sex', child, ['sexe']) |
150 |
for kind in ('authorized', 'emergency'): |
|
151 |
for person in data[kind + 'PersonList']: |
|
152 |
add_text_value('Civility', person, ['civility']) |
|
153 |
add_text_value('Quality', person, ['quality']) |
|
139 | 154 |
return data |
140 | 155 | |
141 | 156 |
def replace_null_values(self, dico): |
142 | 157 |
'''send null fields as empty SOAP tag to tell maelis to empty the value''' |
143 | 158 |
for key, value in dico.items(): |
144 | 159 |
if isinstance(value, dict): |
145 | 160 |
self.replace_null_values(value) |
146 | 161 |
if value is None: |
... | ... | |
280 | 295 |
if data['RL1']['num'] == rl_id: |
281 | 296 |
data = data['RL1'] |
282 | 297 |
elif data['RL2'] and data['RL2']['num'] == rl_id: |
283 | 298 |
data = data['RL2'] |
284 | 299 |
else: |
285 | 300 |
raise APIError("no '%s' RL on '%s' family" % (rl_id, family_id), err_code='not-found') |
286 | 301 |
return {'data': data} |
287 | 302 | |
303 |
@endpoint( |
|
304 |
display_category=_('Family'), |
|
305 |
description="Informations une personne authorisée à récupérer les enfants ou à prévenir en cas d'urgence", |
|
306 |
perm='can_access', |
|
307 |
name='read-person', |
|
308 |
parameters={ |
|
309 |
'NameID': {'description': _('Publik ID')}, |
|
310 |
'person_id': {'description': 'Numéro de la personne'}, |
|
311 |
'kind': {'description': "'authorized' (par defaut) ou 'emergency'"}, |
|
312 |
}, |
|
313 |
) |
|
314 |
def read_person(self, request, NameID, person_id, kind='authorized'): |
|
315 |
if kind not in ('authorized', 'emergency'): |
|
316 |
raise APIError("wrong '%s' value for kind parameter" % kind) |
|
317 |
family_id = self.get_link(NameID).family_id |
|
318 |
data = self.get_family(family_id) |
|
319 |
for person in data[kind + 'PersonList']: |
|
320 |
if str(person['numPerson']) == person_id: |
|
321 |
break |
|
322 |
else: |
|
323 |
raise APIError( |
|
324 |
"no '%s' %s person on '%s' family" % (person_id, kind, family_id), err_code='not-found' |
|
325 |
) |
|
326 |
return {'data': person} |
|
327 | ||
288 | 328 |
@endpoint( |
289 | 329 |
display_category=_('Family'), |
290 | 330 |
description="Vérifier qu'un responsable légal existe en base", |
291 | 331 |
perm='can_access', |
292 | 332 |
name='is-rl-exists', |
293 | 333 |
post={'request_body': {'schema': {'application/json': schemas.ISRLEXISTS_SCHEMA}}}, |
294 | 334 |
) |
295 | 335 |
def is_rl_exists(self, request, post_data): |
... | ... | |
353 | 393 |
) |
354 | 394 |
def update_coordinate(self, request, NameID, rl_id, post_data): |
355 | 395 |
family_id = self.get_link(NameID).family_id |
356 | 396 |
self.replace_null_values(post_data) |
357 | 397 | |
358 | 398 |
self.call('Family', 'updateCoordinate', numDossier=family_id, numPerson=rl_id, **post_data) |
359 | 399 |
return {'data': 'ok'} |
360 | 400 | |
401 |
@endpoint( |
|
402 |
display_category=_('Family'), |
|
403 |
description="Création d'une personne authorisée à récupérer les enfants ou à prévenir en cas d'urgence", |
|
404 |
name='create-person', |
|
405 |
perm='can_access', |
|
406 |
parameters={ |
|
407 |
'NameID': {'description': _('Publik ID')}, |
|
408 |
'kind': {'description': "'authorized' (par defaut) ou 'emergency'"}, |
|
409 |
}, |
|
410 |
post={'request_body': {'schema': {'application/json': schemas.FAMILYPERSON_SCHEMA}}}, |
|
411 |
) |
|
412 |
def create_person(self, request, NameID, post_data, kind='authorized'): |
|
413 |
if kind not in ('authorized', 'emergency'): |
|
414 |
raise APIError("wrong '%s' value for kind parameter" % kind) |
|
415 |
family_id = self.get_link(NameID).family_id |
|
416 |
family = self.get_family_raw(family_id) |
|
417 |
self.replace_null_values(post_data) |
|
418 | ||
419 |
personList = family[kind + 'PersonList'] |
|
420 |
personList.append(post_data) |
|
421 |
payload = { |
|
422 |
'dossierNumber': family_id, |
|
423 |
'categorie': family['category'], |
|
424 |
'situation': family['situation'], |
|
425 |
kind + 'PersonList': [{'personList': personList}], |
|
426 |
} |
|
427 |
self.call('Family', 'updateFamily', **payload) |
|
428 |
return {'data': 'ok'} |
|
429 | ||
430 |
@endpoint( |
|
431 |
display_category=_('Family'), |
|
432 |
description="Mise à jour d'une personne authorisée à récupérer les enfants ou à prévenir en cas d'urgence", |
|
433 |
name='update-person', |
|
434 |
perm='can_access', |
|
435 |
parameters={ |
|
436 |
'NameID': {'description': _('Publik ID')}, |
|
437 |
'person_id': {'description': 'Numéro de la personne'}, |
|
438 |
'kind': {'description': "'authorized' (par defaut) ou 'emergency'"}, |
|
439 |
}, |
|
440 |
post={'request_body': {'schema': {'application/json': schemas.FAMILYPERSON_SCHEMA}}}, |
|
441 |
) |
|
442 |
def update_person(self, request, NameID, person_id, post_data, kind='authorized'): |
|
443 |
if kind not in ('authorized', 'emergency'): |
|
444 |
raise APIError("wrong '%s' value for kind parameter" % kind) |
|
445 |
family_id = self.get_link(NameID).family_id |
|
446 |
family = self.get_family_raw(family_id) |
|
447 |
self.replace_null_values(post_data) |
|
448 | ||
449 |
personList = family[kind + 'PersonList'] |
|
450 |
for i, person in enumerate(personList): |
|
451 |
if str(person['numPerson']) == person_id: |
|
452 |
personList[i] = post_data |
|
453 |
personList[i]['numPerson'] = person_id |
|
454 |
break |
|
455 |
else: |
|
456 |
raise APIError( |
|
457 |
"no '%s' authorized person on '%s' family" % (person_id, family_id), err_code='not-found' |
|
458 |
) |
|
459 |
payload = { |
|
460 |
'dossierNumber': family_id, |
|
461 |
'categorie': family['category'], |
|
462 |
'situation': family['situation'], |
|
463 |
kind + 'PersonList': [{'personList': personList}], |
|
464 |
} |
|
465 |
self.call('Family', 'updateFamily', **payload) |
|
466 |
return {'data': 'ok'} |
|
467 | ||
468 |
@endpoint( |
|
469 |
display_category=_('Family'), |
|
470 |
description="Suppression d'une personne authorisée à récupérer les enfants ou à prévenir en cas d'urgence", |
|
471 |
name='delete-person', |
|
472 |
perm='can_access', |
|
473 |
parameters={ |
|
474 |
'NameID': {'description': _('Publik ID')}, |
|
475 |
'person_id': {'description': 'Numéro de la personne'}, |
|
476 |
'kind': {'description': "'authorized' (par defaut) ou 'emergency'"}, |
|
477 |
}, |
|
478 |
methods=['post'], |
|
479 |
) |
|
480 |
def delete_person(self, request, NameID, person_id, kind='authorized'): |
|
481 |
if kind not in ('authorized', 'emergency'): |
|
482 |
raise APIError("wrong '%s' value for kind parameter" % kind) |
|
483 |
family_id = self.get_link(NameID).family_id |
|
484 |
family = self.get_family_raw(family_id) |
|
485 | ||
486 |
personList = family[kind + 'PersonList'] |
|
487 |
for i, person in enumerate(personList): |
|
488 |
if str(person['numPerson']) == person_id: |
|
489 |
del personList[i] |
|
490 |
break |
|
491 |
else: |
|
492 |
raise APIError( |
|
493 |
"no '%s' authorized person on '%s' family" % (person_id, family_id), err_code='not-found' |
|
494 |
) |
|
495 |
payload = { |
|
496 |
'dossierNumber': family_id, |
|
497 |
'categorie': family['category'], |
|
498 |
'situation': family['situation'], |
|
499 |
kind + 'PersonList': [{'personList': personList}], |
|
500 |
} |
|
501 |
self.call('Family', 'updateFamily', **payload) |
|
502 |
return {'data': 'ok'} |
|
503 | ||
361 | 504 | |
362 | 505 |
class Link(models.Model): |
363 | 506 |
resource = models.ForeignKey(ToulouseMaelis, on_delete=models.CASCADE) |
364 | 507 |
name_id = models.CharField(blank=False, max_length=256) |
365 | 508 |
family_id = models.CharField(blank=False, max_length=128) |
366 | 509 |
created = models.DateTimeField(auto_now_add=True) |
367 | 510 |
updated = models.DateTimeField(auto_now=True) |
368 | 511 |
passerelle/contrib/toulouse_maelis/schemas.py | ||
---|---|---|
259 | 259 |
'adresse': ADDRESS_SCHEMA, |
260 | 260 |
'contact': CONTACT_SCHEMA, |
261 | 261 |
'profession': PROFESSION_SCHEMA, |
262 | 262 |
'CAFInfo': CAFINFO_SCHEMA, |
263 | 263 |
}, |
264 | 264 |
} |
265 | 265 | |
266 | 266 | |
267 |
CONTACTLIGHT_SCHEMA = { |
|
268 |
'$schema': 'http://json-schema.org/draft-04/schema#', |
|
269 |
'title': 'Contact', |
|
270 |
'description': "Informations de contact pour les personnes authorisées à récupérer les enfants ou à prévenir en cas d'urgence", |
|
271 |
'oneOf': [ |
|
272 |
{'type': 'null'}, |
|
273 |
{ |
|
274 |
'type': 'object', |
|
275 |
'properties': { |
|
276 |
'phone': { |
|
277 |
'description': 'Téléphone', |
|
278 |
'oneOf': [{'type': 'null'}, {'type': 'string'}], |
|
279 |
}, |
|
280 |
'mobile': { |
|
281 |
'description': 'Portable', |
|
282 |
'oneOf': [{'type': 'null'}, {'type': 'string'}], |
|
283 |
}, |
|
284 |
'mail': { |
|
285 |
'description': 'Mail', |
|
286 |
'oneOf': [{'type': 'null'}, {'type': 'string'}], |
|
287 |
}, |
|
288 |
}, |
|
289 |
}, |
|
290 |
], |
|
291 |
} |
|
292 | ||
293 |
FAMILYPERSON_SCHEMA = { |
|
294 |
'$schema': 'http://json-schema.org/draft-04/schema#', |
|
295 |
'title': 'Family', |
|
296 |
'description': "Informations sur les personnes autorisées à venir chercher les enfants ou à prévenir en cas d'urgence", |
|
297 |
'type': 'object', |
|
298 |
'required': ['firstname', 'lastname', 'dateBirth'], |
|
299 |
'properties': { |
|
300 |
'civility': { |
|
301 |
'description': 'civilité (depuis référenciel)', |
|
302 |
'oneOf': [{'type': 'null'}, {'type': 'string'}], |
|
303 |
}, |
|
304 |
'firstname': { |
|
305 |
'description': 'Prénom', |
|
306 |
'type': 'string', |
|
307 |
}, |
|
308 |
'lastname': { |
|
309 |
'description': 'Nom', |
|
310 |
'type': 'string', |
|
311 |
}, |
|
312 |
'quality': { |
|
313 |
'description': 'Qualité', |
|
314 |
'oneOf': [{'type': 'null'}, {'type': 'string'}], |
|
315 |
}, |
|
316 |
'dateBirth': { |
|
317 |
'description': 'Date de naissance', |
|
318 |
'type': 'string', |
|
319 |
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$', |
|
320 |
}, |
|
321 |
'contact': CONTACTLIGHT_SCHEMA, |
|
322 |
}, |
|
323 |
'unflatten': True, |
|
324 |
} |
|
325 | ||
326 |
AUTHORIZEDPERSON_SCHEMA = { |
|
327 |
'$schema': 'http://json-schema.org/draft-04/schema#', |
|
328 |
'title': 'Family', |
|
329 |
'description': "Informations sur les personnes autorisées à venir chercher les enfants ou à prévenir en cas d'urgence", |
|
330 |
'type': 'object', |
|
331 |
'properties': { |
|
332 |
'personList': { |
|
333 |
'oneOf': [ |
|
334 |
{'type': 'null'}, |
|
335 |
{ |
|
336 |
'type': 'array', |
|
337 |
'items': FAMILYPERSON_SCHEMA, |
|
338 |
}, |
|
339 |
], |
|
340 |
}, |
|
341 |
}, |
|
342 |
} |
|
343 | ||
267 | 344 |
FAMILY_SCHEMA = { |
268 | 345 |
'$schema': 'http://json-schema.org/draft-04/schema#', |
269 | 346 |
'title': 'Family', |
270 | 347 |
'description': 'Informations pour créer ou mettre à jour une famille', |
271 | 348 |
'type': 'object', |
272 | 349 |
'required': ['categorie', 'situation'], |
273 | 350 |
'properties': { |
274 | 351 |
'categorie': { |
... | ... | |
292 | 369 |
'oneOf': [{'type': 'null'}, {'type': 'string'}], |
293 | 370 |
}, |
294 | 371 |
'nbAES': { |
295 | 372 |
'description': "Nombre d'AES", |
296 | 373 |
'oneOf': [{'type': 'null'}, {'type': 'string'}], |
297 | 374 |
}, |
298 | 375 |
'rl1': RLINFO_SCHEMA, |
299 | 376 |
'rl2': RLINFO_SCHEMA, |
377 |
'authorizedPersonList': { |
|
378 |
'oneOf': [ |
|
379 |
{'type': 'null'}, |
|
380 |
{ |
|
381 |
'type': 'array', |
|
382 |
'items': AUTHORIZEDPERSON_SCHEMA, |
|
383 |
}, |
|
384 |
], |
|
385 |
}, |
|
386 |
'emergencyPersonList': { |
|
387 |
'oneOf': [ |
|
388 |
{'type': 'null'}, |
|
389 |
{ |
|
390 |
'type': 'array', |
|
391 |
'items': AUTHORIZEDPERSON_SCHEMA, |
|
392 |
}, |
|
393 |
], |
|
394 |
}, |
|
300 | 395 |
}, |
301 | 396 |
'unflatten': True, |
302 | 397 |
} |
303 | 398 | |
304 | 399 |
"""Schemas below describe parameters of Maelis wrapper around updateFamily endpoint""" |
305 | 400 | |
306 | 401 |
UPDATE_COORDINATE_SCHEMA = { |
307 | 402 |
'$schema': 'http://json-schema.org/draft-04/schema#', |
tests/data/toulouse_maelis/Q_create_person.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> |
|
3 |
<soap-env:Header> |
|
4 |
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> |
|
5 |
<wsse:UsernameToken> |
|
6 |
<wsse:Username>maelis-webservice</wsse:Username> |
|
7 |
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password> |
|
8 |
</wsse:UsernameToken> |
|
9 |
</wsse:Security> |
|
10 |
</soap-env:Header> |
|
11 |
<soap-env:Body> |
|
12 |
<ns0:updateFamily xmlns:ns0="family.ws.maelis.sigec.com"> |
|
13 |
<dossierNumber>1312</dossierNumber> |
|
14 |
<categorie>BI</categorie> |
|
15 |
<situation>M</situation> |
|
16 |
<emergencyPersonList> |
|
17 |
<personList> |
|
18 |
<numPerson>614059</numPerson> |
|
19 |
<firstname>KENY</firstname> |
|
20 |
<lastname>ARKANA</lastname> |
|
21 |
<dateBirth>1970-01-01</dateBirth> |
|
22 |
<quality>MERE</quality> |
|
23 |
<contact> |
|
24 |
<phone>0123456789</phone> |
|
25 |
</contact> |
|
26 |
</personList> |
|
27 |
<personList> |
|
28 |
<civility/> |
|
29 |
<firstname>Mathias</firstname> |
|
30 |
<lastname>Cassel</lastname> |
|
31 |
<dateBirth>1972-01-01</dateBirth> |
|
32 |
<quality>PERE</quality> |
|
33 |
<contact> |
|
34 |
<phone/> |
|
35 |
<mobile>0623456789</mobile> |
|
36 |
<mail/> |
|
37 |
</contact> |
|
38 |
</personList> |
|
39 |
</emergencyPersonList> |
|
40 |
</ns0:updateFamily> |
|
41 |
</soap-env:Body> |
|
42 |
</soap-env:Envelope> |
tests/data/toulouse_maelis/Q_delete_person.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> |
|
3 |
<soap-env:Header> |
|
4 |
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> |
|
5 |
<wsse:UsernameToken> |
|
6 |
<wsse:Username>maelis-webservice</wsse:Username> |
|
7 |
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password> |
|
8 |
</wsse:UsernameToken> |
|
9 |
</wsse:Security> |
|
10 |
</soap-env:Header> |
|
11 |
<soap-env:Body> |
|
12 |
<ns0:updateFamily xmlns:ns0="family.ws.maelis.sigec.com"> |
|
13 |
<dossierNumber>1312</dossierNumber> |
|
14 |
<categorie>BI</categorie> |
|
15 |
<situation>M</situation> |
|
16 |
<emergencyPersonList/> |
|
17 |
</ns0:updateFamily> |
|
18 |
</soap-env:Body> |
|
19 |
</soap-env:Envelope> |
tests/data/toulouse_maelis/Q_update_person.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> |
|
3 |
<soap-env:Header> |
|
4 |
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> |
|
5 |
<wsse:UsernameToken> |
|
6 |
<wsse:Username>maelis-webservice</wsse:Username> |
|
7 |
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password> |
|
8 |
</wsse:UsernameToken> |
|
9 |
</wsse:Security> |
|
10 |
</soap-env:Header> |
|
11 |
<soap-env:Body> |
|
12 |
<ns0:updateFamily xmlns:ns0="family.ws.maelis.sigec.com"> |
|
13 |
<dossierNumber>1312</dossierNumber> |
|
14 |
<categorie>BI</categorie> |
|
15 |
<situation>M</situation> |
|
16 |
<emergencyPersonList> |
|
17 |
<personList> |
|
18 |
<numPerson>614059</numPerson> |
|
19 |
<civility/> |
|
20 |
<firstname>Mathias</firstname> |
|
21 |
<lastname>Cassel</lastname> |
|
22 |
<dateBirth>1972-01-01</dateBirth> |
|
23 |
<quality>PERE</quality> |
|
24 |
<contact> |
|
25 |
<phone/> |
|
26 |
<mobile>0623456789</mobile> |
|
27 |
<mail/> |
|
28 |
</contact> |
|
29 |
</personList> |
|
30 |
</emergencyPersonList> |
|
31 |
</ns0:updateFamily> |
|
32 |
</soap-env:Body> |
|
33 |
</soap-env:Envelope> |
tests/data/toulouse_maelis/R_read_family.xml | ||
---|---|---|
54 | 54 |
<isContactMail>false</isContactMail> |
55 | 55 |
<isContactSms>false</isContactSms> |
56 | 56 |
<isInvoicePdf>false</isInvoicePdf> |
57 | 57 |
</contact> |
58 | 58 |
<CAFInfo> |
59 | 59 |
<number>51</number> |
60 | 60 |
</CAFInfo> |
61 | 61 |
</RL2> |
62 |
<emergencyPersonList> |
|
63 |
<num>614059</num> |
|
64 |
<id>S10032140599</id> |
|
65 |
<firstname>KENY</firstname> |
|
66 |
<lastname>ARKANA</lastname> |
|
67 |
<quality>MERE</quality> |
|
68 |
<contact> |
|
69 |
<phone>0123456789</phone> |
|
70 |
</contact> |
|
71 |
</emergencyPersonList> |
|
72 |
<authorizedPersonList> |
|
73 |
<numPerson>614058</numPerson> |
|
74 |
<firstname>CATHY</firstname> |
|
75 |
<lastname>PALENNE</lastname> |
|
76 |
<dateBirth>1975-06-28T00:00:00+01:00</dateBirth> |
|
77 |
<quality>PERE</quality> |
|
78 |
<contact> |
|
79 |
<phone>0123456789</phone> |
|
80 |
</contact> |
|
81 |
</authorizedPersonList> |
|
62 | 82 |
<childList> |
63 | 83 |
<num>613880</num> |
64 | 84 |
<lastname>COSTANZE</lastname> |
65 | 85 |
<firstname>CASSANDRA</firstname> |
66 | 86 |
<sexe>F</sexe> |
67 | 87 |
<birth> |
68 | 88 |
<dateBirth>2021-06-22T00:00:00+02:00</dateBirth> |
69 | 89 |
</birth> |
tests/test_toulouse_maelis.py | ||
---|---|---|
445 | 445 |
'medicalRecord': None, |
446 | 446 |
'subscribeSchoolList': [], |
447 | 447 |
'mother': None, |
448 | 448 |
'father': None, |
449 | 449 |
'rl': None, |
450 | 450 |
'subscribeActivityList': [], |
451 | 451 |
'paiInfoBean': None, |
452 | 452 |
} |
453 |
assert resp.json['data']['emergencyPersonList'][0] == { |
|
454 |
'firstname': 'KENY', |
|
455 |
'lastname': 'ARKANA', |
|
456 |
'quality': 'MERE', |
|
457 |
'civility': None, |
|
458 |
'contact': {'phone': '0123456789', 'mobile': None, 'mail': None}, |
|
459 |
'numPerson': 614059, |
|
460 |
'dateBirth': '1970-01-01', |
|
461 |
'quality_text': 'MERE', |
|
462 |
} |
|
453 | 463 | |
454 | 464 | |
455 | 465 |
def test_read_family_not_linked_error(con, app): |
456 | 466 |
url = get_endpoint('read-family') |
457 | 467 | |
458 | 468 |
resp = app.get(url + '?NameID=') |
459 | 469 |
assert resp.json['err'] == 'not-linked' |
460 | 470 |
assert resp.json['err_desc'] == 'User not linked to family' |
... | ... | |
530 | 540 |
url = get_endpoint('read-rl') |
531 | 541 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
532 | 542 | |
533 | 543 |
resp = app.get(url + '?NameID=local&rl_id=000000') |
534 | 544 |
assert resp.json['err'] == 'not-found' |
535 | 545 |
assert resp.json['err_desc'] == "no '000000' RL on '1312' family" |
536 | 546 | |
537 | 547 | |
548 |
@mock.patch('passerelle.utils.Request.get') |
|
549 |
@mock.patch('passerelle.utils.Request.post') |
|
550 |
def test_read_person(mocked_post, mocked_get, con, app): |
|
551 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
552 |
mocked_post.side_effect = [READ_FAMILY, READ_CATEGORIES, READ_SITUATIONS, READ_CIVILITIES, READ_QUALITIES] |
|
553 |
url = get_endpoint('read-person') |
|
554 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
555 | ||
556 |
resp = app.get(url + '?NameID=local&person_id=614059&kind=emergency') |
|
557 |
assert resp.json['err'] == 0 |
|
558 |
assert resp.json['data']['firstname'] == 'KENY' |
|
559 | ||
560 | ||
561 |
def test_read_person_wrong_parameter(con, app): |
|
562 |
url = get_endpoint('read-person') |
|
563 | ||
564 |
resp = app.get(url + '?NameID=local&person_id=000000&kind=baby-sitter') |
|
565 |
assert resp.json['err'] == 1 |
|
566 |
assert resp.json['err_desc'] == "wrong 'baby-sitter' value for kind parameter" |
|
567 | ||
568 | ||
569 |
def test_read_person_not_linked_error(con, app): |
|
570 |
url = get_endpoint('read-person') |
|
571 | ||
572 |
resp = app.get(url + '?NameID=local&person_id=614059') |
|
573 |
assert resp.json['err'] == 'not-linked' |
|
574 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
575 | ||
576 | ||
577 |
@mock.patch('passerelle.utils.Request.get') |
|
578 |
@mock.patch('passerelle.utils.Request.post') |
|
579 |
def test_read_person_not_found(mocked_post, mocked_get, con, app): |
|
580 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
581 |
mocked_post.side_effect = [READ_FAMILY, READ_CATEGORIES, READ_SITUATIONS, READ_CIVILITIES, READ_QUALITIES] |
|
582 |
url = get_endpoint('read-person') |
|
583 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
584 | ||
585 |
resp = app.get(url + '?NameID=local&person_id=000000&kind=emergency') |
|
586 |
assert resp.json['err'] == 'not-found' |
|
587 |
assert resp.json['err_desc'] == "no '000000' emergency person on '1312' family" |
|
588 | ||
589 | ||
538 | 590 |
@pytest.mark.parametrize( |
539 | 591 |
'post_response, result', |
540 | 592 |
[ |
541 | 593 |
(IS_RL_EXISTS_TRUE, True), |
542 | 594 |
(IS_RL_EXISTS_FALSE, False), |
543 | 595 |
], |
544 | 596 |
) |
545 | 597 |
@mock.patch('passerelle.utils.Request.get') |
... | ... | |
766 | 818 |
url = get_endpoint('update-coordinate') |
767 | 819 |
params = { |
768 | 820 |
'contact/isContactMail': 'true more text', |
769 | 821 |
} |
770 | 822 | |
771 | 823 |
resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params, status=400) |
772 | 824 |
assert resp.json['err'] == 1 |
773 | 825 |
assert resp.json['err_desc'] == "'true more text' is not of type 'boolean'" |
826 | ||
827 | ||
828 |
@mock.patch('passerelle.utils.Request.get') |
|
829 |
@mock.patch('passerelle.utils.Request.post') |
|
830 |
def test_create_person(mocked_post, mocked_get, con, app): |
|
831 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
832 |
mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY] |
|
833 |
url = get_endpoint('create-person') |
|
834 |
params = { |
|
835 |
'civility': None, |
|
836 |
'firstname': 'Mathias', |
|
837 |
'lastname': 'Cassel', |
|
838 |
'quality': 'PERE', |
|
839 |
'dateBirth': '1972-01-01', |
|
840 |
'contact/phone': None, |
|
841 |
'contact/mobile': '0623456789', |
|
842 |
'contact/mail': None, |
|
843 |
} |
|
844 | ||
845 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
846 |
resp = app.post_json(url + '?NameID=local&kind=emergency', params=params) |
|
847 |
assert_sent_payload(mocked_post, 'Q_create_person.xml') |
|
848 |
assert resp.json['err'] == 0 |
|
849 | ||
850 | ||
851 |
def test_create_person_wrong_parameter(con, app): |
|
852 |
url = get_endpoint('create-person') |
|
853 |
params = { |
|
854 |
'civility': None, |
|
855 |
'firstname': 'Mathias', |
|
856 |
'lastname': 'Cassel', |
|
857 |
'quality': 'PERE', |
|
858 |
'dateBirth': '1972-01-01', |
|
859 |
'contact/phone': None, |
|
860 |
'contact/mobile': '0623456789', |
|
861 |
'contact/mail': None, |
|
862 |
} |
|
863 | ||
864 |
resp = app.post_json(url + '?NameID=local&kind=baby-sitter', params=params) |
|
865 |
assert resp.json['err'] == 1 |
|
866 |
assert resp.json['err_desc'] == "wrong 'baby-sitter' value for kind parameter" |
|
867 | ||
868 | ||
869 |
def test_create_person_not_linked_error(con, app): |
|
870 |
url = get_endpoint('create-person') |
|
871 |
params = { |
|
872 |
'civility': None, |
|
873 |
'firstname': 'Mathias', |
|
874 |
'lastname': 'Cassel', |
|
875 |
'quality': 'PERE', |
|
876 |
'dateBirth': '1972-01-01', |
|
877 |
'contact/phone': None, |
|
878 |
'contact/mobile': '0623456789', |
|
879 |
'contact/mail': None, |
|
880 |
} |
|
881 | ||
882 |
resp = app.post_json(url + '?NameID=local&kind=emergency', params=params) |
|
883 |
assert resp.json['err'] == 'not-linked' |
|
884 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
885 | ||
886 | ||
887 |
@mock.patch('passerelle.utils.Request.get') |
|
888 |
@mock.patch('passerelle.utils.Request.post') |
|
889 |
def test_update_person(mocked_post, mocked_get, con, app): |
|
890 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
891 |
mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY] |
|
892 |
url = get_endpoint('update-person') |
|
893 |
params = { |
|
894 |
'civility': None, |
|
895 |
'firstname': 'Mathias', |
|
896 |
'lastname': 'Cassel', |
|
897 |
'quality': 'PERE', |
|
898 |
'dateBirth': '1972-01-01', |
|
899 |
'contact/phone': None, |
|
900 |
'contact/mobile': '0623456789', |
|
901 |
'contact/mail': None, |
|
902 |
} |
|
903 | ||
904 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
905 |
resp = app.post_json(url + '?NameID=local&person_id=614059&kind=emergency', params=params) |
|
906 |
assert_sent_payload(mocked_post, 'Q_update_person.xml') |
|
907 |
assert resp.json['err'] == 0 |
|
908 | ||
909 | ||
910 |
def test_update_person_wrong_parameter(con, app): |
|
911 |
url = get_endpoint('update-person') |
|
912 |
params = { |
|
913 |
'civility': None, |
|
914 |
'firstname': 'Mathias', |
|
915 |
'lastname': 'Cassel', |
|
916 |
'quality': 'PERE', |
|
917 |
'dateBirth': '1972-01-01', |
|
918 |
'contact/phone': None, |
|
919 |
'contact/mobile': '0623456789', |
|
920 |
'contact/mail': None, |
|
921 |
} |
|
922 | ||
923 |
resp = app.post_json(url + '?NameID=local&person_id=614059&kind=baby-sitter', params=params) |
|
924 |
assert resp.json['err'] == 1 |
|
925 |
assert resp.json['err_desc'] == "wrong 'baby-sitter' value for kind parameter" |
|
926 | ||
927 | ||
928 |
def test_update_person_not_linked_error(con, app): |
|
929 |
url = get_endpoint('update-person') |
|
930 |
params = { |
|
931 |
'civility': None, |
|
932 |
'firstname': 'Mathias', |
|
933 |
'lastname': 'Cassel', |
|
934 |
'quality': 'PERE', |
|
935 |
'dateBirth': '1972-01-01', |
|
936 |
'contact/phone': None, |
|
937 |
'contact/mobile': '0623456789', |
|
938 |
'contact/mail': None, |
|
939 |
} |
|
940 | ||
941 |
resp = app.post_json(url + '?NameID=local&person_id=614059&kind=emergency', params=params) |
|
942 |
assert resp.json['err'] == 'not-linked' |
|
943 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
944 | ||
945 | ||
946 |
@mock.patch('passerelle.utils.Request.get') |
|
947 |
@mock.patch('passerelle.utils.Request.post') |
|
948 |
def test_update_person_not_found(mocked_post, mocked_get, con, app): |
|
949 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
950 |
mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY] |
|
951 |
url = get_endpoint('update-person') |
|
952 |
params = { |
|
953 |
'civility': None, |
|
954 |
'firstname': 'Mathias', |
|
955 |
'lastname': 'Cassel', |
|
956 |
'quality': 'PERE', |
|
957 |
'dateBirth': '1972-01-01', |
|
958 |
'contact/phone': None, |
|
959 |
'contact/mobile': '0623456789', |
|
960 |
'contact/mail': None, |
|
961 |
} |
|
962 | ||
963 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
964 |
resp = app.post_json(url + '?NameID=local&person_id=000000&kind=emergency', params=params) |
|
965 |
assert resp.json['err'] == 'not-found' |
|
966 |
assert resp.json['err_desc'] == "no '000000' authorized person on '1312' family" |
|
967 | ||
968 | ||
969 |
@mock.patch('passerelle.utils.Request.get') |
|
970 |
@mock.patch('passerelle.utils.Request.post') |
|
971 |
def test_delete_person(mocked_post, mocked_get, con, app): |
|
972 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
973 |
mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY] |
|
974 |
url = get_endpoint('delete-person') |
|
975 |
params = { |
|
976 |
'civility': None, |
|
977 |
'firstname': 'Mathias', |
|
978 |
'lastname': 'Cassel', |
|
979 |
'quality': 'PERE', |
|
980 |
'dateBirth': '1972-01-01', |
|
981 |
'contact/phone': None, |
|
982 |
'contact/mobile': '0623456789', |
|
983 |
'contact/mail': None, |
|
984 |
} |
|
985 | ||
986 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
987 |
resp = app.post_json(url + '?NameID=local&person_id=614059&kind=emergency', params=params) |
|
988 |
assert_sent_payload(mocked_post, 'Q_delete_person.xml') |
|
989 |
assert resp.json['err'] == 0 |
|
990 | ||
991 | ||
992 |
def test_delete_person_wrong_parameter(con, app): |
|
993 |
url = get_endpoint('delete-person') |
|
994 |
params = { |
|
995 |
'civility': None, |
|
996 |
'firstname': 'Mathias', |
|
997 |
'lastname': 'Cassel', |
|
998 |
'quality': 'PERE', |
|
999 |
'dateBirth': '1972-01-01', |
|
1000 |
'contact/phone': None, |
|
1001 |
'contact/mobile': '0623456789', |
|
1002 |
'contact/mail': None, |
|
1003 |
} |
|
1004 | ||
1005 |
resp = app.post_json(url + '?NameID=local&person_id=614059&kind=baby-sitter', params=params) |
|
1006 |
assert resp.json['err'] == 1 |
|
1007 |
assert resp.json['err_desc'] == "wrong 'baby-sitter' value for kind parameter" |
|
1008 | ||
1009 | ||
1010 |
def test_delete_person_not_linked_error(con, app): |
|
1011 |
url = get_endpoint('delete-person') |
|
1012 |
params = { |
|
1013 |
'civility': None, |
|
1014 |
'firstname': 'Mathias', |
|
1015 |
'lastname': 'Cassel', |
|
1016 |
'quality': 'PERE', |
|
1017 |
'dateBirth': '1972-01-01', |
|
1018 |
'contact/phone': None, |
|
1019 |
'contact/mobile': '0623456789', |
|
1020 |
'contact/mail': None, |
|
1021 |
} |
|
1022 | ||
1023 |
resp = app.post_json(url + '?NameID=local&person_id=614059&kind=emergency', params=params) |
|
1024 |
assert resp.json['err'] == 'not-linked' |
|
1025 |
assert resp.json['err_desc'] == 'User not linked to family' |
|
1026 | ||
1027 | ||
1028 |
@mock.patch('passerelle.utils.Request.get') |
|
1029 |
@mock.patch('passerelle.utils.Request.post') |
|
1030 |
def test_delete_person_not_found(mocked_post, mocked_get, con, app): |
|
1031 |
mocked_get.return_value = FAMILY_SERVICE_WSDL |
|
1032 |
mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY] |
|
1033 |
url = get_endpoint('delete-person') |
|
1034 |
params = { |
|
1035 |
'civility': None, |
|
1036 |
'firstname': 'Mathias', |
|
1037 |
'lastname': 'Cassel', |
|
1038 |
'quality': 'PERE', |
|
1039 |
'dateBirth': '1972-01-01', |
|
1040 |
'contact/phone': None, |
|
1041 |
'contact/mobile': '0623456789', |
|
1042 |
'contact/mail': None, |
|
1043 |
} |
|
1044 | ||
1045 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
|
1046 |
resp = app.post_json(url + '?NameID=local&person_id=000000&kind=emergency', params=params) |
|
1047 |
assert resp.json['err'] == 'not-found' |
|
1048 |
assert resp.json['err_desc'] == "no '000000' authorized person on '1312' family" |
|
774 |
- |