0001-toulouse_axel-add-labels-to-explain-some-values-3929.patch
functests/toulouse_axel/test_toulouse_axel.py | ||
---|---|---|
45 | 45 |
payload['DROITALIMAGE'] = 'NON' |
46 | 46 |
payload['REVENUS']['CHOIXREVENU'] = '' |
47 | 47 |
# remove non editable fields |
48 |
for key in ['SITUATIONFAMILIALE', 'NBENFANTACTIF', 'NBRLACTIF', 'IDDUI', 'CODEMISEAJOUR']: |
|
48 |
for key in ['SITUATIONFAMILIALE', 'SITUATIONFAMILIALE_label', 'NBENFANTACTIF', 'NBRLACTIF', 'IDDUI', 'CODEMISEAJOUR']:
|
|
49 | 49 |
payload.pop(key) |
50 |
for key in ['IDPERSONNE', 'NOM', 'PRENOM', 'NOMJEUNEFILLE', 'DATENAISSANCE', 'CIVILITE', 'INDICATEURRL']: |
|
50 |
for key in ['IDPERSONNE', 'NOM', 'PRENOM', 'NOMJEUNEFILLE', 'DATENAISSANCE', 'CIVILITE', 'INDICATEURRL', 'CSP_label']:
|
|
51 | 51 |
if 'RL1' in payload: |
52 | 52 |
payload['RL1'].pop(key) |
53 | 53 |
if 'RL2' in payload: |
54 | 54 |
payload['RL2'].pop(key) |
55 |
for key in ['MONTANTTOTAL', 'DATEVALIDITE', 'SFI', 'IREVENUS', 'RNF', 'NBENFANTSACHARGE']: |
|
55 |
for key in ['MONTANTTOTAL', 'DATEVALIDITE', 'SFI', 'IREVENUS', 'RNF', 'NBENFANTSACHARGE', 'TYPEREGIME_label']:
|
|
56 | 56 |
payload['REVENUS'].pop(key, None) |
57 | 57 |
for enfant in payload['ENFANT']: |
58 | 58 |
for key in ['NOM', 'DATENAISSANCE', 'SEXE', 'PRENOMPERE', 'PRENOMMERE', 'NOMPERE', 'NOMMERE', 'RATTACHEAUTREDUI', 'PRENOM']: |
59 | 59 |
enfant.pop(key) |
60 | 60 |
enfant['AUTORISATIONURGENCEMEDICALE'] = 'OUI' |
61 |
for contact in enfant.get('CONTACT', []): |
|
62 |
contact.pop('LIENPARENTE_label') |
|
61 | 63 |
if 'SANITAIRE' not in enfant: |
62 | 64 |
continue |
63 | 65 |
# manage handicap data (not the same schema) |
passerelle/contrib/toulouse_axel/models.py | ||
---|---|---|
36 | 36 |
from passerelle.utils.api import endpoint |
37 | 37 |
from passerelle.utils.jsonresponse import APIError |
38 | 38 |
from passerelle.utils.xml import JSONSchemaFromXMLSchema |
39 |
from . import utils |
|
39 | 40 | |
40 | 41 |
logger = logging.getLogger('passerelle.contrib.toulouse_axel') |
41 | 42 | |
... | ... | |
520 | 521 |
link.delete() |
521 | 522 |
return {'link': link_id, 'deleted': True, 'dui': link.dui} |
522 | 523 | |
524 |
@endpoint( |
|
525 |
description=_("Get a referential"), |
|
526 |
perm='can_access', |
|
527 |
pattern=r'^(?P<code>[\w-]+)/?$', |
|
528 |
example_pattern='csp', |
|
529 |
parameters={ |
|
530 |
'code': {'description': _('Referential code. Possible values: situation_familiale, csp, lien_parente, type_regime')}, |
|
531 |
}) |
|
532 |
def referential(self, request, code): |
|
533 |
if code not in ['situation_familiale', 'csp', 'lien_parente', 'type_regime']: |
|
534 |
raise APIError('Referential not found', err_code='not-found') |
|
535 |
references = getattr(utils, '{}_mapping'.format(code)) |
|
536 |
if references is None: |
|
537 |
raise APIError('Referential not found', err_code='not-found', http_status=404) |
|
538 |
return {'data': [{'id': key, 'text': val} for key, val in references.items()]} |
|
539 | ||
523 | 540 |
def get_family_data(self, name_id): |
524 | 541 |
link = self.get_link(name_id) |
525 | 542 |
try: |
... | ... | |
540 | 557 |
}) |
541 | 558 |
def family_info(self, request, NameID): |
542 | 559 |
family_data = self.get_family_data(NameID) |
560 |
family_data['SITUATIONFAMILIALE_label'] = utils.get_label(utils.situation_familiale_mapping, family_data['SITUATIONFAMILIALE']) |
|
561 |
for key in ['RL1', 'RL2']: |
|
562 |
if key not in family_data: |
|
563 |
continue |
|
564 |
rl = family_data[key] |
|
565 |
rl['CSP_label'] = utils.get_label(utils.csp_mapping, rl['CSP']) |
|
566 |
for child in family_data.get('ENFANT', []): |
|
567 |
for contact in child.get('CONTACT', []): |
|
568 |
contact['LIENPARENTE_label'] = utils.get_label(utils.lien_parente_mapping, contact['LIENPARENTE']) |
|
569 |
if 'REVENUS' in family_data: |
|
570 |
family_data['REVENUS']['TYPEREGIME_label'] = utils.get_label(utils.type_regime_mapping, family_data['REVENUS']['TYPEREGIME']) |
|
543 | 571 |
return {'data': family_data} |
544 | 572 | |
573 |
def get_child_data(self, name_id, child_id): |
|
574 |
family_data = self.get_family_data(name_id) |
|
575 | ||
576 |
for child in family_data['ENFANT']: |
|
577 |
if child['IDPERSONNE'] == child_id: |
|
578 |
return child |
|
579 | ||
580 |
raise APIError('Child not found', err_code='not-found') |
|
581 | ||
545 | 582 |
@endpoint( |
546 | 583 |
description=_("Get information about a child"), |
547 | 584 |
perm='can_access', |
... | ... | |
550 | 587 |
'idpersonne': {'description': _('Child ID')}, |
551 | 588 |
}) |
552 | 589 |
def child_info(self, request, idpersonne, NameID): |
553 |
family_data = self.get_family_data(NameID)
|
|
590 |
child_data = self.get_child_data(NameID, idpersonne)
|
|
554 | 591 | |
555 |
for child in family_data['ENFANT']: |
|
556 |
if child['IDPERSONNE'] == idpersonne: |
|
557 |
return {'data': child} |
|
592 |
for contact in child_data.get('CONTACT', []): |
|
593 |
contact['LIENPARENTE_label'] = utils.get_label(utils.lien_parente_mapping, contact['LIENPARENTE']) |
|
558 | 594 | |
559 |
raise APIError('Child not found', err_code='not-found')
|
|
595 |
return {'data': child_data}
|
|
560 | 596 | |
561 | 597 |
def pre_sanitize_update_family_data(self, post_data): |
562 | 598 |
# before json payload validation, check maj fields and remove empty blocks |
passerelle/contrib/toulouse_axel/utils.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# passerelle - uniform access to multiple data sources and services |
|
3 |
# Copyright (C) 2020 Entr'ouvert |
|
4 |
# |
|
5 |
# This program is free software: you can redistribute it and/or modify it |
|
6 |
# under the terms of the GNU Affero General Public License as published |
|
7 |
# by the Free Software Foundation, either version 3 of the License, or |
|
8 |
# (at your option) any later version. |
|
9 |
# |
|
10 |
# This program is distributed in the hope that it will be useful, |
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
# GNU Affero General Public License for more details. |
|
14 |
# |
|
15 |
# You should have received a copy of the GNU Affero General Public License |
|
16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 | ||
18 |
from __future__ import unicode_literals |
|
19 | ||
20 |
from collections import OrderedDict |
|
21 | ||
22 | ||
23 |
situation_familiale_mapping = OrderedDict([ |
|
24 |
('C', 'Célibataire'), |
|
25 |
('D', 'Divorcé (e)'), |
|
26 |
('M', 'Marié (e)'), |
|
27 |
('S', 'Séparé (e)'), |
|
28 |
('V', 'Veuf (ve)'), |
|
29 |
('VM', 'Vie Maritale'), |
|
30 |
('P', 'Pacs'), |
|
31 |
]) |
|
32 | ||
33 |
csp_mapping = OrderedDict([ |
|
34 |
('OUV', 'Ouvriers'), |
|
35 |
('EMP', 'Employés'), |
|
36 |
('ETU', 'Etudiants'), |
|
37 |
('RET', 'Retraités'), |
|
38 |
('STA', 'Personnes en stage'), |
|
39 |
('AGEX', 'Agriculteurs exploitants'), |
|
40 |
('ARCO', 'Artisans commercants chefs entreprise'), |
|
41 |
('CADP', 'Cadres professions intellectuelles supérieures'), |
|
42 |
('PRIN', 'Professions intermediaires'), |
|
43 |
('SACT', 'Autres personnes sans activité professionnelle'), |
|
44 |
('REC', 'Recherche emploi'), |
|
45 |
]) |
|
46 | ||
47 |
lien_parente_mapping = OrderedDict([ |
|
48 |
('GRP1', 'Grands-parents paternels'), |
|
49 |
('GRP2', 'Grands-parents maternels'), |
|
50 |
('VOI', 'Voisin'), |
|
51 |
('FRE', "Frère de l'enfant"), |
|
52 |
('SOE', "Soeur de l'enfant"), |
|
53 |
('AMI', 'Ami (e)'), |
|
54 |
('FAMI', 'Membre de la famille'), |
|
55 |
('BABY', 'Baby sitter'), |
|
56 |
]) |
|
57 | ||
58 |
type_regime_mapping = OrderedDict([ |
|
59 |
('GENE', 'Régime général'), |
|
60 |
('ZAU', 'Autre'), |
|
61 |
('MSA', 'MSA'), |
|
62 |
]) |
|
63 | ||
64 | ||
65 |
def get_label(mapping, code): |
|
66 |
return mapping.get(code, code) |
tests/data/toulouse_axel/family_info.xml | ||
---|---|---|
4 | 4 |
<CODEMISEAJOUR>19</CODEMISEAJOUR> |
5 | 5 |
<NBRLACTIF>2</NBRLACTIF> |
6 | 6 |
<NBENFANTACTIF>2</NBENFANTACTIF> |
7 |
<SITUATIONFAMILIALE>P</SITUATIONFAMILIALE>
|
|
7 |
<SITUATIONFAMILIALE>S</SITUATIONFAMILIALE>
|
|
8 | 8 |
<REACTUALISATIONENLIGNE>NON</REACTUALISATIONENLIGNE> |
9 | 9 |
<DEMATFACTURES>NON</DEMATFACTURES> |
10 | 10 |
<ADRESSE> |
... | ... | |
131 | 131 |
<CONTACT> |
132 | 132 |
<NOM>foo</NOM> |
133 | 133 |
<PRENOM>foo</PRENOM> |
134 |
<LIENPARENTE/>
|
|
134 |
<LIENPARENTE>GRP1</LIENPARENTE>
|
|
135 | 135 |
<ENCASURGENCE>OUI</ENCASURGENCE> |
136 | 136 |
<CHERCHERLENFANT>OUI</CHERCHERLENFANT> |
137 | 137 |
<TELFIXE>0505050505</TELFIXE> |
tests/test_toulouse_axel.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
1 | 2 |
# passerelle - uniform access to multiple data sources and services |
2 | 3 |
# Copyright (C) 2019 Entr'ouvert |
3 | 4 |
# |
... | ... | |
14 | 15 |
# You should have received a copy of the GNU Affero General Public License |
15 | 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 17 | |
18 |
from __future__ import unicode_literals |
|
19 | ||
17 | 20 |
from contextlib import contextmanager |
18 | 21 |
import copy |
19 | 22 |
import datetime |
... | ... | |
41 | 44 |
ref_facture_pdf, |
42 | 45 |
ref_verif_dui, |
43 | 46 |
) |
47 |
from passerelle.contrib.toulouse_axel.utils import ( |
|
48 |
situation_familiale_mapping, |
|
49 |
csp_mapping, |
|
50 |
lien_parente_mapping, |
|
51 |
type_regime_mapping, |
|
52 |
) |
|
44 | 53 |
from passerelle.utils.jsonresponse import APIError |
45 | 54 |
import utils |
46 | 55 | |
... | ... | |
568 | 577 |
assert resp.json['deleted'] is True |
569 | 578 | |
570 | 579 | |
580 |
def test_refetential_endpoint_no_result(app, resource): |
|
581 |
resp = app.get('/toulouse-axel/test/referential/foo/') |
|
582 |
assert resp.json['err_desc'] == "Referential not found" |
|
583 |
assert resp.json['err'] == 'not-found' |
|
584 | ||
585 | ||
586 |
@pytest.mark.parametrize('code, mapping', [ |
|
587 |
('situation_familiale', situation_familiale_mapping), |
|
588 |
('csp', csp_mapping), |
|
589 |
('lien_parente', lien_parente_mapping), |
|
590 |
('type_regime', type_regime_mapping), |
|
591 |
]) |
|
592 |
def test_refetential_endpoint(app, resource, code, mapping): |
|
593 |
resp = app.get('/toulouse-axel/test/referential/%s/' % code) |
|
594 |
expected = [{'id': k, 'text': v} for k, v in mapping.items()] |
|
595 |
assert dict(resp.json['data']) == dict(expected) |
|
596 | ||
597 | ||
571 | 598 |
def test_family_info_endpoint_axel_error(app, resource): |
572 | 599 |
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
573 | 600 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ref_famille_dui') as operation: |
... | ... | |
604 | 631 |
'RL1', |
605 | 632 |
'RL2', |
606 | 633 |
'SITUATIONFAMILIALE', |
634 |
'SITUATIONFAMILIALE_label', |
|
607 | 635 |
'TELFIXE', |
608 | 636 |
]) |
637 |
assert resp.json['data']['SITUATIONFAMILIALE'] == 'S' |
|
638 |
assert resp.json['data']['SITUATIONFAMILIALE_label'] == 'Séparé (e)' |
|
639 |
assert resp.json['data']['RL1']['CSP'] == 'ETU' |
|
640 |
assert resp.json['data']['RL1']['CSP_label'] == 'Etudiants' |
|
641 |
assert resp.json['data']['RL2']['CSP'] == 'EMP' |
|
642 |
assert resp.json['data']['RL2']['CSP_label'] == 'Employés' |
|
643 |
assert resp.json['data']['ENFANT'][0]['CONTACT'][0]['LIENPARENTE'] == 'GRP1' |
|
644 |
assert resp.json['data']['ENFANT'][0]['CONTACT'][0]['LIENPARENTE_label'] == 'Grands-parents paternels' |
|
645 |
assert resp.json['data']['ENFANT'][0]['CONTACT'][1]['LIENPARENTE'] is None |
|
646 |
assert resp.json['data']['ENFANT'][0]['CONTACT'][1]['LIENPARENTE_label'] is None |
|
647 |
assert resp.json['data']['REVENUS']['TYPEREGIME'] == 'GENE' |
|
648 |
assert resp.json['data']['REVENUS']['TYPEREGIME_label'] == 'Régime général' |
|
609 | 649 | |
610 | 650 | |
611 | 651 |
def test_child_info_endpoint_axel_error(app, resource): |
... | ... | |
655 | 695 |
'SANITAIRE', |
656 | 696 |
'SEXE', |
657 | 697 |
]) |
698 |
assert resp.json['data']['CONTACT'][0]['LIENPARENTE'] == 'GRP1' |
|
699 |
assert resp.json['data']['CONTACT'][0]['LIENPARENTE_label'] == 'Grands-parents paternels' |
|
700 |
assert resp.json['data']['CONTACT'][1]['LIENPARENTE'] is None |
|
701 |
assert resp.json['data']['CONTACT'][1]['LIENPARENTE_label'] is None |
|
658 | 702 | |
659 | 703 | |
660 | 704 |
def test_update_family_info_endpoint_axel_error(app, resource, update_params, family_data): |
661 |
- |