Projet

Général

Profil

0001-toulouse_axel-add-labels-to-explain-some-values-3929.patch

Lauréline Guérin, 27 janvier 2020 15:41

Télécharger (9,89 ko)

Voir les différences:

Subject: [PATCH] toulouse_axel: add labels to explain some values (#39291)

 functests/toulouse_axel/test_toulouse_axel.py |  8 ++-
 passerelle/contrib/toulouse_axel/models.py    | 30 +++++++--
 passerelle/contrib/toulouse_axel/utils.py     | 61 +++++++++++++++++++
 tests/data/toulouse_axel/family_info.xml      |  4 +-
 tests/test_toulouse_axel.py                   | 18 ++++++
 5 files changed, 111 insertions(+), 10 deletions(-)
 create mode 100644 passerelle/contrib/toulouse_axel/utils.py
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

  
......
540 541
        })
541 542
    def family_info(self, request, NameID):
542 543
        family_data = self.get_family_data(NameID)
544
        family_data['SITUATIONFAMILIALE_label'] = utils.get_label(utils.situation_familiale_mapping, family_data['SITUATIONFAMILIALE'])
545
        for key in ['RL1', 'RL2']:
546
            if key not in family_data:
547
                continue
548
            rl = family_data[key]
549
            rl['CSP_label'] = utils.get_label(utils.csp_mapping, rl['CSP'])
550
        for child in family_data.get('ENFANT', []):
551
            for contact in child.get('CONTACT', []):
552
                contact['LIENPARENTE_label'] = utils.get_label(utils.lien_parente_mapping, contact['LIENPARENTE'])
553
        if 'REVENUS' in family_data:
554
            family_data['REVENUS']['TYPEREGIME_label'] = utils.get_label(utils.type_regime_mapping, family_data['REVENUS']['TYPEREGIME'])
543 555
        return {'data': family_data}
544 556

  
557
    def get_child_data(self, name_id, child_id):
558
        family_data = self.get_family_data(name_id)
559

  
560
        for child in family_data['ENFANT']:
561
            if child['IDPERSONNE'] == child_id:
562
                return child
563

  
564
        raise APIError('Child not found', err_code='not-found')
565

  
545 566
    @endpoint(
546 567
        description=_("Get information about a child"),
547 568
        perm='can_access',
......
550 571
            'idpersonne': {'description': _('Child ID')},
551 572
        })
552 573
    def child_info(self, request, idpersonne, NameID):
553
        family_data = self.get_family_data(NameID)
574
        child_data = self.get_child_data(NameID, idpersonne)
554 575

  
555
        for child in family_data['ENFANT']:
556
            if child['IDPERSONNE'] == idpersonne:
557
                return {'data': child}
576
        for contact in child_data.get('CONTACT', []):
577
            contact['LIENPARENTE_label'] = utils.get_label(utils.lien_parente_mapping, contact['LIENPARENTE'])
558 578

  
559
        raise APIError('Child not found', err_code='not-found')
579
        return {'data': child_data}
560 580

  
561 581
    def pre_sanitize_update_family_data(self, post_data):
562 582
        # 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
situation_familiale_mapping = {
19
    'C': u'Célibataire',
20
    'D': u'Divorcé (e)',
21
    'M': u'Marié (e)',
22
    'S': u'Séparé (e)',
23
    'V': 'Veuf (ve)',
24
    'VM': 'Vie Maritale',
25
    'P': 'Pacs',
26
}
27

  
28
csp_mapping = {
29
    'OUV': 'OUVRIER',
30
    'EMP': 'EMPLOYES',
31
    'ETU': 'ETUDIANT',
32
    'RET': 'RETRAITES',
33
    'STA': 'PERSONNE EN STAGE',
34
    'AGEX': 'AGRICULTEURS EXPLOITANTS',
35
    'ARCO': 'ARTISANS COMMERCANTS CHEFS ENTREPRISE',
36
    'CADP': 'CADRES PROFESSIONS INTELLECTUELLES SUPERIEURES',
37
    'PRIN': 'PROFESSIONS INTERMEDIAIRES',
38
    'SACT': 'AUTRES PERSONNES SANS ACTIVITE PROFESSIONNELLE',
39
    'REC': 'RECHERCHE EMPLOI',
40
}
41

  
42
lien_parente_mapping = {
43
    'GRP1': 'Grands-parents paternels',
44
    'GRP2': 'Grands-parents maternels',
45
    'VOI': 'Voisin',
46
    'FRE': "Frère de l'enfant",
47
    'SOE': "Soeur de l'enfant",
48
    'AMI': 'Ami (e)',
49
    'FAMI': 'Membre de la famille',
50
    'BABY': 'Baby sitter',
51
}
52

  
53
type_regime_mapping = {
54
    'GENE': 'REGIME GENERAL',
55
    'ZAU': 'AUTRE',
56
    'MSA': 'MSA',
57
}
58

  
59

  
60
def get_label(mapping, code):
61
    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
#
......
604 605
        'RL1',
605 606
        'RL2',
606 607
        'SITUATIONFAMILIALE',
608
        'SITUATIONFAMILIALE_label',
607 609
        'TELFIXE',
608 610
    ])
611
    assert resp.json['data']['SITUATIONFAMILIALE'] == 'S'
612
    assert resp.json['data']['SITUATIONFAMILIALE_label'] == u'Séparé (e)'
613
    assert resp.json['data']['RL1']['CSP'] == 'ETU'
614
    assert resp.json['data']['RL1']['CSP_label'] == 'ETUDIANT'
615
    assert resp.json['data']['RL2']['CSP'] == 'EMP'
616
    assert resp.json['data']['RL2']['CSP_label'] == 'EMPLOYES'
617
    assert resp.json['data']['ENFANT'][0]['CONTACT'][0]['LIENPARENTE'] == 'GRP1'
618
    assert resp.json['data']['ENFANT'][0]['CONTACT'][0]['LIENPARENTE_label'] == 'Grands-parents paternels'
619
    assert resp.json['data']['ENFANT'][0]['CONTACT'][1]['LIENPARENTE'] is None
620
    assert resp.json['data']['ENFANT'][0]['CONTACT'][1]['LIENPARENTE_label'] is None
621
    assert resp.json['data']['REVENUS']['TYPEREGIME'] == 'GENE'
622
    assert resp.json['data']['REVENUS']['TYPEREGIME_label'] == 'REGIME GENERAL'
609 623

  
610 624

  
611 625
def test_child_info_endpoint_axel_error(app, resource):
......
655 669
        'SANITAIRE',
656 670
        'SEXE',
657 671
    ])
672
    assert resp.json['data']['CONTACT'][0]['LIENPARENTE'] == 'GRP1'
673
    assert resp.json['data']['CONTACT'][0]['LIENPARENTE_label'] == 'Grands-parents paternels'
674
    assert resp.json['data']['CONTACT'][1]['LIENPARENTE'] is None
675
    assert resp.json['data']['CONTACT'][1]['LIENPARENTE_label'] is None
658 676

  
659 677

  
660 678
def test_update_family_info_endpoint_axel_error(app, resource, update_params, family_data):
661
-