Projet

Général

Profil

0001-toulouse-axel-upperize-data-sent-for-DUI-update-4115.patch

Lauréline Guérin, 30 mars 2020 14:34

Télécharger (14,5 ko)

Voir les différences:

Subject: [PATCH] toulouse-axel: upperize data sent for DUI update (#41159)

 functests/toulouse_axel/test_toulouse_axel.py |   2 +-
 passerelle/contrib/toulouse_axel/models.py    |   2 +
 passerelle/contrib/toulouse_axel/utils.py     |  13 ++
 .../toulouse_axel/update_family_info.json     | 192 +++++++++---------
 tests/test_toulouse_axel.py                   |  20 ++
 5 files changed, 132 insertions(+), 97 deletions(-)
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', 'SITUATIONFAMILIALE_label', 'NBENFANTACTIF', 'NBRLACTIF', 'IDDUI', 'CODEMISEAJOUR']:
48
    for key in ['SITUATIONFAMILIALE', 'SITUATIONFAMILIALE_label', 'NBENFANTACTIF', 'NBRLACTIF', 'IDDUI', 'CODEMISEAJOUR', 'management_dates']:
49 49
        payload.pop(key)
50 50
    for key in ['IDPERSONNE', 'NOM', 'PRENOM', 'NOMJEUNEFILLE', 'DATENAISSANCE', 'CIVILITE', 'INDICATEURRL', 'CSP_label']:
51 51
        if 'RL1' in payload:
passerelle/contrib/toulouse_axel/models.py
686 686
        if not post_data['ENFANT']:
687 687
            post_data.pop('ENFANT')
688 688

  
689
        utils.upperize(post_data)
690

  
689 691
    UPDATE_FAMILY_SCHEMA['pre_process'] = pre_sanitize_update_family_data
690 692

  
691 693
    def sanitize_update_family_data(self, dui, post_data):
passerelle/contrib/toulouse_axel/utils.py
19 19

  
20 20
from collections import OrderedDict
21 21
import datetime
22
import unicodedata
22 23
import xml.etree.ElementTree as ET
23 24

  
24 25

  
......
139 140
        return obj
140 141

  
141 142

  
143
def upperize(data):
144
    if isinstance(data, dict):
145
        for key, val in data.items():
146
            data[key] = upperize(val)
147
    if isinstance(data, list):
148
        for i, val in enumerate(data):
149
            data[i] = upperize(val)
150
    if isinstance(data, str):
151
        data = unicodedata.normalize('NFKD', data).encode('ascii', 'ignore').decode('ascii').upper()
152
    return data
153

  
154

  
142 155
def normalize_invoice(invoice, dui, historical=False, vendor_base=None):
143 156
    vendor = vendor_base or {}
144 157
    vendor.update(invoice)
tests/data/toulouse_axel/update_family_info.json
7 7
        "COMPLEMENTVOIE": null,
8 8
        "NUMEROSTI": "1234",
9 9
        "NUMVOIE": "42",
10
        "VILLE": "TOULOUSE",
11
        "VOIE": "RUE bar"
10
        "VILLE": "toulouse",
11
        "VOIE": "rue bar"
12 12
    },
13
    "DEMATFACTURES": "NON",
14
    "DROITALIMAGE": "NON",
13
    "DEMATFACTURES": "non",
14
    "DROITALIMAGE": "non",
15 15
    "ENFANT": [
16 16
        {
17 17
            "ASSURANCE": {
......
19 19
                "NOM": "foo",
20 20
                "NUMERO": "1234"
21 21
            },
22
            "AUTORISATIONURGENCEMEDICALE": "OUI",
22
            "AUTORISATIONURGENCEMEDICALE": "oui",
23 23
            "CONTACT": [
24 24
                {
25
                    "CHERCHERLENFANT": "OUI",
26
                    "ENCASURGENCE": "OUI",
27
                    "LIENPARENTE": "VOI",
25
                    "CHERCHERLENFANT": "oui",
26
                    "ENCASURGENCE": "oui",
27
                    "LIENPARENTE": "voi",
28 28
                    "NOM": "foo",
29 29
                    "PRENOM": "foo",
30 30
                    "TELFIXE": "0505050505",
31 31
                    "TELPORTABLE": "0606060606"
32 32
                },
33 33
                {
34
                    "CHERCHERLENFANT": "OUI",
35
                    "ENCASURGENCE": "OUI",
36
                    "LIENPARENTE": "VOI",
34
                    "CHERCHERLENFANT": "oui",
35
                    "ENCASURGENCE": "oui",
36
                    "LIENPARENTE": "voi",
37 37
                    "NOM": "foo",
38 38
                    "PRENOM": "foo",
39 39
                    "TELFIXE": "0505050505",
......
52 52
            "IDPERSONNE": "4242",
53 53
            "SANITAIRE": {
54 54
                "ALLERGIE": {
55
                    "ASTHME": "OUI",
56
                    "MEDICAMENTEUSES": "OUI",
57
                    "ALIMENTAIRES": "OUI",
55
                    "ASTHME": "oui",
56
                    "MEDICAMENTEUSES": "oui",
57
                    "ALIMENTAIRES": "oui",
58 58
                    "AUTRES": null
59 59
                },
60 60
                "DATEFINVALIDITE": "2020-12-31",
61 61
                "HANDICAP": {
62 62
                    "AUTREDIFFICULTE": null,
63 63
                    "ECOLESPECIALISEE": null,
64
                    "INDICATEURAUXILIAIREVS": "NON",
65
                    "INDICATEURECOLE": "NON",
66
                    "INDICATEURHANDICAP": "NON",
67
                    "INDICATEURNOTIFMDPH": "NON"
64
                    "INDICATEURAUXILIAIREVS": "non",
65
                    "INDICATEURECOLE": "non",
66
                    "INDICATEURHANDICAP": "non",
67
                    "INDICATEURNOTIFMDPH": "non"
68 68
                },
69
                "INDICATEURPAI": "NON",
69
                "INDICATEURPAI": "non",
70 70
                "INFOUTILES": null,
71 71
                "MEDECIN": {
72 72
                    "NOM": "foo",
......
93 93
                "NOM": "foo",
94 94
                "NUMERO": "1234"
95 95
            },
96
            "AUTORISATIONURGENCEMEDICALE": "OUI",
96
            "AUTORISATIONURGENCEMEDICALE": "oui",
97 97
            "IDPERSONNE": "3535",
98 98
            "SANITAIRE": {
99 99
                "ALLERGIE": {
100
                    "ASTHME": "OUI",
101
                    "MEDICAMENTEUSES": "OUI",
102
                    "ALIMENTAIRES": "OUI",
100
                    "ASTHME": "oui",
101
                    "MEDICAMENTEUSES": "oui",
102
                    "ALIMENTAIRES": "oui",
103 103
                    "AUTRES": null
104 104
                },
105 105
                "DATEFINVALIDITE": "2020-12-31",
106 106
                "HANDICAP": {
107 107
                    "AUTREDIFFICULTE": null,
108 108
                    "ECOLESPECIALISEE": null,
109
                    "INDICATEURAUXILIAIREVS": "NON",
110
                    "INDICATEURECOLE": "NON",
111
                    "INDICATEURHANDICAP": "NON",
112
                    "INDICATEURNOTIFMDPH": "NON"
109
                    "INDICATEURAUXILIAIREVS": "non",
110
                    "INDICATEURECOLE": "non",
111
                    "INDICATEURHANDICAP": "non",
112
                    "INDICATEURNOTIFMDPH": "non"
113 113
                },
114
                "INDICATEURPAI": "NON",
114
                "INDICATEURPAI": "non",
115 115
                "INFOUTILES": null,
116 116
                "MEDECIN": {
117 117
                    "NOM": "foo",
......
120 120
                "VACCIN": {
121 121
                    "AUTRE": null,
122 122
                    "BCGAJOUR": null,
123
                    "COQAJOUR": "OUI",
124
                    "DAJOUR": "OUI",
125
                    "HBAJOUR": "OUI",
126
                    "HIBAJOUR": "OUI",
127
                    "IIPAJOUR": "OUI",
128
                    "MENINAJOUR": "OUI",
129
                    "PAJOUR": "OUI",
130
                    "RORAJOUR": "OUI",
131
                    "TAJOUR": "OUI"
123
                    "COQAJOUR": "oui",
124
                    "DAJOUR": "oui",
125
                    "HBAJOUR": "oui",
126
                    "HIBAJOUR": "oui",
127
                    "IIPAJOUR": "oui",
128
                    "MENINAJOUR": "oui",
129
                    "PAJOUR": "oui",
130
                    "RORAJOUR": "oui",
131
                    "TAJOUR": "oui"
132 132
                }
133 133
            }
134 134
        }
135 135
    ],
136 136
    "N0TELEDOSSIER": "42",
137
    "REACTUALISATIONENLIGNE": "NON",
137
    "REACTUALISATIONENLIGNE": "non",
138 138
    "REVENUS": {
139 139
        "ALLOCATAIRE": "2",
140 140
        "CHOIXREVENU": "",
141 141
        "NUMEROCAF": "1234",
142
        "TYPEREGIME": "GENE"
142
        "TYPEREGIME": "gene"
143 143
    },
144 144
    "RL1": {
145 145
        "ADREMPLOYEUR": {
......
154 154
            "VOIE": null
155 155
        },
156 156
        "COURRIEL": "foo@bar.com",
157
        "CSP": "ETU",
157
        "CSP": "etu",
158 158
        "NOMEMPLOYEUR": "foo",
159
        "PROFESSION": "ETUDIANT",
159
        "PROFESSION": "etudiant",
160 160
        "TELPORTABLE": "0606060606"
161 161
    },
162 162
    "RL2": {
......
172 172
            "VOIE": null
173 173
        },
174 174
        "COURRIEL": "foo@bar.com",
175
        "CSP": "EMP",
175
        "CSP": "emp",
176 176
        "NOMEMPLOYEUR": "foo",
177 177
        "PROFESSION": "foo",
178 178
        "TELPORTABLE": "0606060606"
179 179
    },
180 180
    "TELFIXE": null,
181
    "maj:adresse": "OUI",
182
    "maj:enfant_0": "OUI",
183
    "maj:enfant_0_assurance": "OUI",
184
    "maj:enfant_0_contact": "OUI",
185
    "maj:enfant_0_sanitaire": "OUI",
186
    "maj:enfant_0_sanitaire_allergie": "OUI",
187
    "maj:enfant_0_sanitaire_medecin": "OUI",
188
    "maj:enfant_0_sanitaire_vaccin": "OUI",
189
    "maj:enfant_0_sanitaire_handicap": "OUI",
190
    "maj:enfant_1": "OUI",
191
    "maj:enfant_1_assurance": "OUI",
192
    "maj:enfant_1_contact": "OUI",
193
    "maj:enfant_1_sanitaire": "OUI",
194
    "maj:enfant_1_sanitaire_allergie": "OUI",
195
    "maj:enfant_1_sanitaire_medecin": "OUI",
196
    "maj:enfant_1_sanitaire_vaccin": "OUI",
197
    "maj:enfant_1_sanitaire_handicap": "OUI",
198
    "maj:enfant_2": "OUI",
199
    "maj:enfant_2_assurance": "OUI",
200
    "maj:enfant_2_contact": "OUI",
201
    "maj:enfant_2_sanitaire": "OUI",
202
    "maj:enfant_2_sanitaire_allergie": "OUI",
203
    "maj:enfant_2_sanitaire_medecin": "OUI",
204
    "maj:enfant_2_sanitaire_vaccin": "OUI",
205
    "maj:enfant_2_sanitaire_handicap": "OUI",
206
    "maj:enfant_3": "OUI",
207
    "maj:enfant_3_assurance": "OUI",
208
    "maj:enfant_3_contact": "OUI",
209
    "maj:enfant_3_sanitaire": "OUI",
210
    "maj:enfant_3_sanitaire_allergie": "OUI",
211
    "maj:enfant_3_sanitaire_medecin": "OUI",
212
    "maj:enfant_3_sanitaire_vaccin": "OUI",
213
    "maj:enfant_3_sanitaire_handicap": "OUI",
214
    "maj:enfant_4": "OUI",
215
    "maj:enfant_4_assurance": "OUI",
216
    "maj:enfant_4_contact": "OUI",
217
    "maj:enfant_4_sanitaire": "OUI",
218
    "maj:enfant_4_sanitaire_allergie": "OUI",
219
    "maj:enfant_4_sanitaire_medecin": "OUI",
220
    "maj:enfant_4_sanitaire_vaccin": "OUI",
221
    "maj:enfant_4_sanitaire_handicap": "OUI",
222
    "maj:enfant_5": "OUI",
223
    "maj:enfant_5_assurance": "OUI",
224
    "maj:enfant_5_contact": "OUI",
225
    "maj:enfant_5_sanitaire": "OUI",
226
    "maj:enfant_5_sanitaire_allergie": "OUI",
227
    "maj:enfant_5_sanitaire_medecin": "OUI",
228
    "maj:enfant_5_sanitaire_vaccin": "OUI",
229
    "maj:enfant_5_sanitaire_handicap": "OUI",
230
    "maj:revenus": "OUI",
231
    "maj:rl1": "OUI",
232
    "maj:rl1_adresse_employeur": "OUI",
233
    "maj:rl2": "OUI",
234
    "maj:rl2_adresse_employeur": "OUI"
181
    "maj:adresse": "oui",
182
    "maj:enfant_0": "oui",
183
    "maj:enfant_0_assurance": "oui",
184
    "maj:enfant_0_contact": "oui",
185
    "maj:enfant_0_sanitaire": "oui",
186
    "maj:enfant_0_sanitaire_allergie": "oui",
187
    "maj:enfant_0_sanitaire_medecin": "oui",
188
    "maj:enfant_0_sanitaire_vaccin": "oui",
189
    "maj:enfant_0_sanitaire_handicap": "oui",
190
    "maj:enfant_1": "oui",
191
    "maj:enfant_1_assurance": "oui",
192
    "maj:enfant_1_contact": "oui",
193
    "maj:enfant_1_sanitaire": "oui",
194
    "maj:enfant_1_sanitaire_allergie": "oui",
195
    "maj:enfant_1_sanitaire_medecin": "oui",
196
    "maj:enfant_1_sanitaire_vaccin": "oui",
197
    "maj:enfant_1_sanitaire_handicap": "oui",
198
    "maj:enfant_2": "oui",
199
    "maj:enfant_2_assurance": "oui",
200
    "maj:enfant_2_contact": "oui",
201
    "maj:enfant_2_sanitaire": "oui",
202
    "maj:enfant_2_sanitaire_allergie": "oui",
203
    "maj:enfant_2_sanitaire_medecin": "oui",
204
    "maj:enfant_2_sanitaire_vaccin": "oui",
205
    "maj:enfant_2_sanitaire_handicap": "oui",
206
    "maj:enfant_3": "oui",
207
    "maj:enfant_3_assurance": "oui",
208
    "maj:enfant_3_contact": "oui",
209
    "maj:enfant_3_sanitaire": "oui",
210
    "maj:enfant_3_sanitaire_allergie": "oui",
211
    "maj:enfant_3_sanitaire_medecin": "oui",
212
    "maj:enfant_3_sanitaire_vaccin": "oui",
213
    "maj:enfant_3_sanitaire_handicap": "oui",
214
    "maj:enfant_4": "oui",
215
    "maj:enfant_4_assurance": "oui",
216
    "maj:enfant_4_contact": "oui",
217
    "maj:enfant_4_sanitaire": "oui",
218
    "maj:enfant_4_sanitaire_allergie": "oui",
219
    "maj:enfant_4_sanitaire_medecin": "oui",
220
    "maj:enfant_4_sanitaire_vaccin": "oui",
221
    "maj:enfant_4_sanitaire_handicap": "oui",
222
    "maj:enfant_5": "oui",
223
    "maj:enfant_5_assurance": "oui",
224
    "maj:enfant_5_contact": "oui",
225
    "maj:enfant_5_sanitaire": "oui",
226
    "maj:enfant_5_sanitaire_allergie": "oui",
227
    "maj:enfant_5_sanitaire_medecin": "oui",
228
    "maj:enfant_5_sanitaire_vaccin": "oui",
229
    "maj:enfant_5_sanitaire_handicap": "oui",
230
    "maj:revenus": "oui",
231
    "maj:rl1": "oui",
232
    "maj:rl1_adresse_employeur": "oui",
233
    "maj:rl2": "oui",
234
    "maj:rl2_adresse_employeur": "oui"
235 235
}
tests/test_toulouse_axel.py
53 53
    lien_parente_mapping,
54 54
    type_regime_mapping,
55 55
    get_reference_year_from_date,
56
    upperize,
56 57
)
57 58
from passerelle.utils.jsonresponse import APIError
58 59
import utils
......
1070 1071
    assert full_update_params['REVENUS']['NBENFANTSACHARGE'] is None
1071 1072

  
1072 1073

  
1074
def test_pre_sanitize_update_upperize(app, resource, update_params):
1075
    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
1076

  
1077
    def check_upper(data):
1078
        if isinstance(data, dict):
1079
            for val in data.values():
1080
                check_upper(val)
1081
        if isinstance(data, list):
1082
            for val in data:
1083
                check_upper(val)
1084
        if isinstance(data, str):
1085
            assert data == data.upper()
1086

  
1087
    resource.pre_sanitize_update_family_data(post_data=update_params)
1088
    check_upper(update_params)
1089

  
1090
    assert upperize(u'something with an accent é') == u'SOMETHING WITH AN ACCENT E'
1091

  
1092

  
1073 1093
def test_pre_sanitize_update_family_data_adresse(app, resource, update_params):
1074 1094
    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
1075 1095

  
1076
-