toulouse-axel: upperize data sent for DUI update (#41159)

This commit is contained in:
Lauréline Guérin 2020-03-30 14:25:39 +02:00
parent 3d4807485d
commit 26a2732e05
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
5 changed files with 134 additions and 97 deletions

View File

@ -45,7 +45,7 @@ def test_link(conn, user):
payload['DROITALIMAGE'] = 'NON'
payload['REVENUS']['CHOIXREVENU'] = ''
# remove non editable fields
for key in ['SITUATIONFAMILIALE', 'SITUATIONFAMILIALE_label', 'NBENFANTACTIF', 'NBRLACTIF', 'IDDUI', 'CODEMISEAJOUR']:
for key in ['SITUATIONFAMILIALE', 'SITUATIONFAMILIALE_label', 'NBENFANTACTIF', 'NBRLACTIF', 'IDDUI', 'CODEMISEAJOUR', 'management_dates']:
payload.pop(key)
for key in ['IDPERSONNE', 'NOM', 'PRENOM', 'NOMJEUNEFILLE', 'DATENAISSANCE', 'CIVILITE', 'INDICATEURRL', 'CSP_label']:
if 'RL1' in payload:

View File

@ -686,6 +686,8 @@ class ToulouseAxel(BaseResource):
if not post_data['ENFANT']:
post_data.pop('ENFANT')
utils.upperize(post_data)
UPDATE_FAMILY_SCHEMA['pre_process'] = pre_sanitize_update_family_data
def sanitize_update_family_data(self, dui, post_data):

View File

@ -19,8 +19,11 @@ from __future__ import unicode_literals
from collections import OrderedDict
import datetime
import unicodedata
import xml.etree.ElementTree as ET
from django.utils.six import string_types
boolean_type = {
'oneOf': [
@ -139,6 +142,18 @@ def encode_datetime(obj):
return obj
def upperize(data):
if isinstance(data, dict):
for key, val in data.items():
data[key] = upperize(val)
if isinstance(data, list):
for i, val in enumerate(data):
data[i] = upperize(val)
if isinstance(data, string_types):
data = unicodedata.normalize('NFKD', data).encode('ascii', 'ignore').decode('ascii').upper()
return data
def normalize_invoice(invoice, dui, historical=False, vendor_base=None):
vendor = vendor_base or {}
vendor.update(invoice)

View File

@ -7,11 +7,11 @@
"COMPLEMENTVOIE": null,
"NUMEROSTI": "1234",
"NUMVOIE": "42",
"VILLE": "TOULOUSE",
"VOIE": "RUE bar"
"VILLE": "toulouse",
"VOIE": "rue bar"
},
"DEMATFACTURES": "NON",
"DROITALIMAGE": "NON",
"DEMATFACTURES": "non",
"DROITALIMAGE": "non",
"ENFANT": [
{
"ASSURANCE": {
@ -19,21 +19,21 @@
"NOM": "foo",
"NUMERO": "1234"
},
"AUTORISATIONURGENCEMEDICALE": "OUI",
"AUTORISATIONURGENCEMEDICALE": "oui",
"CONTACT": [
{
"CHERCHERLENFANT": "OUI",
"ENCASURGENCE": "OUI",
"LIENPARENTE": "VOI",
"CHERCHERLENFANT": "oui",
"ENCASURGENCE": "oui",
"LIENPARENTE": "voi",
"NOM": "foo",
"PRENOM": "foo",
"TELFIXE": "0505050505",
"TELPORTABLE": "0606060606"
},
{
"CHERCHERLENFANT": "OUI",
"ENCASURGENCE": "OUI",
"LIENPARENTE": "VOI",
"CHERCHERLENFANT": "oui",
"ENCASURGENCE": "oui",
"LIENPARENTE": "voi",
"NOM": "foo",
"PRENOM": "foo",
"TELFIXE": "0505050505",
@ -52,21 +52,21 @@
"IDPERSONNE": "4242",
"SANITAIRE": {
"ALLERGIE": {
"ASTHME": "OUI",
"MEDICAMENTEUSES": "OUI",
"ALIMENTAIRES": "OUI",
"ASTHME": "oui",
"MEDICAMENTEUSES": "oui",
"ALIMENTAIRES": "oui",
"AUTRES": null
},
"DATEFINVALIDITE": "2020-12-31",
"HANDICAP": {
"AUTREDIFFICULTE": null,
"ECOLESPECIALISEE": null,
"INDICATEURAUXILIAIREVS": "NON",
"INDICATEURECOLE": "NON",
"INDICATEURHANDICAP": "NON",
"INDICATEURNOTIFMDPH": "NON"
"INDICATEURAUXILIAIREVS": "non",
"INDICATEURECOLE": "non",
"INDICATEURHANDICAP": "non",
"INDICATEURNOTIFMDPH": "non"
},
"INDICATEURPAI": "NON",
"INDICATEURPAI": "non",
"INFOUTILES": null,
"MEDECIN": {
"NOM": "foo",
@ -93,25 +93,25 @@
"NOM": "foo",
"NUMERO": "1234"
},
"AUTORISATIONURGENCEMEDICALE": "OUI",
"AUTORISATIONURGENCEMEDICALE": "oui",
"IDPERSONNE": "3535",
"SANITAIRE": {
"ALLERGIE": {
"ASTHME": "OUI",
"MEDICAMENTEUSES": "OUI",
"ALIMENTAIRES": "OUI",
"ASTHME": "oui",
"MEDICAMENTEUSES": "oui",
"ALIMENTAIRES": "oui",
"AUTRES": null
},
"DATEFINVALIDITE": "2020-12-31",
"HANDICAP": {
"AUTREDIFFICULTE": null,
"ECOLESPECIALISEE": null,
"INDICATEURAUXILIAIREVS": "NON",
"INDICATEURECOLE": "NON",
"INDICATEURHANDICAP": "NON",
"INDICATEURNOTIFMDPH": "NON"
"INDICATEURAUXILIAIREVS": "non",
"INDICATEURECOLE": "non",
"INDICATEURHANDICAP": "non",
"INDICATEURNOTIFMDPH": "non"
},
"INDICATEURPAI": "NON",
"INDICATEURPAI": "non",
"INFOUTILES": null,
"MEDECIN": {
"NOM": "foo",
@ -120,26 +120,26 @@
"VACCIN": {
"AUTRE": null,
"BCGAJOUR": null,
"COQAJOUR": "OUI",
"DAJOUR": "OUI",
"HBAJOUR": "OUI",
"HIBAJOUR": "OUI",
"IIPAJOUR": "OUI",
"MENINAJOUR": "OUI",
"PAJOUR": "OUI",
"RORAJOUR": "OUI",
"TAJOUR": "OUI"
"COQAJOUR": "oui",
"DAJOUR": "oui",
"HBAJOUR": "oui",
"HIBAJOUR": "oui",
"IIPAJOUR": "oui",
"MENINAJOUR": "oui",
"PAJOUR": "oui",
"RORAJOUR": "oui",
"TAJOUR": "oui"
}
}
}
],
"N0TELEDOSSIER": "42",
"REACTUALISATIONENLIGNE": "NON",
"REACTUALISATIONENLIGNE": "non",
"REVENUS": {
"ALLOCATAIRE": "2",
"CHOIXREVENU": "",
"NUMEROCAF": "1234",
"TYPEREGIME": "GENE"
"TYPEREGIME": "gene"
},
"RL1": {
"ADREMPLOYEUR": {
@ -154,9 +154,9 @@
"VOIE": null
},
"COURRIEL": "foo@bar.com",
"CSP": "ETU",
"CSP": "etu",
"NOMEMPLOYEUR": "foo",
"PROFESSION": "ETUDIANT",
"PROFESSION": "etudiant",
"TELPORTABLE": "0606060606"
},
"RL2": {
@ -172,64 +172,64 @@
"VOIE": null
},
"COURRIEL": "foo@bar.com",
"CSP": "EMP",
"CSP": "emp",
"NOMEMPLOYEUR": "foo",
"PROFESSION": "foo",
"TELPORTABLE": "0606060606"
},
"TELFIXE": null,
"maj:adresse": "OUI",
"maj:enfant_0": "OUI",
"maj:enfant_0_assurance": "OUI",
"maj:enfant_0_contact": "OUI",
"maj:enfant_0_sanitaire": "OUI",
"maj:enfant_0_sanitaire_allergie": "OUI",
"maj:enfant_0_sanitaire_medecin": "OUI",
"maj:enfant_0_sanitaire_vaccin": "OUI",
"maj:enfant_0_sanitaire_handicap": "OUI",
"maj:enfant_1": "OUI",
"maj:enfant_1_assurance": "OUI",
"maj:enfant_1_contact": "OUI",
"maj:enfant_1_sanitaire": "OUI",
"maj:enfant_1_sanitaire_allergie": "OUI",
"maj:enfant_1_sanitaire_medecin": "OUI",
"maj:enfant_1_sanitaire_vaccin": "OUI",
"maj:enfant_1_sanitaire_handicap": "OUI",
"maj:enfant_2": "OUI",
"maj:enfant_2_assurance": "OUI",
"maj:enfant_2_contact": "OUI",
"maj:enfant_2_sanitaire": "OUI",
"maj:enfant_2_sanitaire_allergie": "OUI",
"maj:enfant_2_sanitaire_medecin": "OUI",
"maj:enfant_2_sanitaire_vaccin": "OUI",
"maj:enfant_2_sanitaire_handicap": "OUI",
"maj:enfant_3": "OUI",
"maj:enfant_3_assurance": "OUI",
"maj:enfant_3_contact": "OUI",
"maj:enfant_3_sanitaire": "OUI",
"maj:enfant_3_sanitaire_allergie": "OUI",
"maj:enfant_3_sanitaire_medecin": "OUI",
"maj:enfant_3_sanitaire_vaccin": "OUI",
"maj:enfant_3_sanitaire_handicap": "OUI",
"maj:enfant_4": "OUI",
"maj:enfant_4_assurance": "OUI",
"maj:enfant_4_contact": "OUI",
"maj:enfant_4_sanitaire": "OUI",
"maj:enfant_4_sanitaire_allergie": "OUI",
"maj:enfant_4_sanitaire_medecin": "OUI",
"maj:enfant_4_sanitaire_vaccin": "OUI",
"maj:enfant_4_sanitaire_handicap": "OUI",
"maj:enfant_5": "OUI",
"maj:enfant_5_assurance": "OUI",
"maj:enfant_5_contact": "OUI",
"maj:enfant_5_sanitaire": "OUI",
"maj:enfant_5_sanitaire_allergie": "OUI",
"maj:enfant_5_sanitaire_medecin": "OUI",
"maj:enfant_5_sanitaire_vaccin": "OUI",
"maj:enfant_5_sanitaire_handicap": "OUI",
"maj:revenus": "OUI",
"maj:rl1": "OUI",
"maj:rl1_adresse_employeur": "OUI",
"maj:rl2": "OUI",
"maj:rl2_adresse_employeur": "OUI"
"maj:adresse": "oui",
"maj:enfant_0": "oui",
"maj:enfant_0_assurance": "oui",
"maj:enfant_0_contact": "oui",
"maj:enfant_0_sanitaire": "oui",
"maj:enfant_0_sanitaire_allergie": "oui",
"maj:enfant_0_sanitaire_medecin": "oui",
"maj:enfant_0_sanitaire_vaccin": "oui",
"maj:enfant_0_sanitaire_handicap": "oui",
"maj:enfant_1": "oui",
"maj:enfant_1_assurance": "oui",
"maj:enfant_1_contact": "oui",
"maj:enfant_1_sanitaire": "oui",
"maj:enfant_1_sanitaire_allergie": "oui",
"maj:enfant_1_sanitaire_medecin": "oui",
"maj:enfant_1_sanitaire_vaccin": "oui",
"maj:enfant_1_sanitaire_handicap": "oui",
"maj:enfant_2": "oui",
"maj:enfant_2_assurance": "oui",
"maj:enfant_2_contact": "oui",
"maj:enfant_2_sanitaire": "oui",
"maj:enfant_2_sanitaire_allergie": "oui",
"maj:enfant_2_sanitaire_medecin": "oui",
"maj:enfant_2_sanitaire_vaccin": "oui",
"maj:enfant_2_sanitaire_handicap": "oui",
"maj:enfant_3": "oui",
"maj:enfant_3_assurance": "oui",
"maj:enfant_3_contact": "oui",
"maj:enfant_3_sanitaire": "oui",
"maj:enfant_3_sanitaire_allergie": "oui",
"maj:enfant_3_sanitaire_medecin": "oui",
"maj:enfant_3_sanitaire_vaccin": "oui",
"maj:enfant_3_sanitaire_handicap": "oui",
"maj:enfant_4": "oui",
"maj:enfant_4_assurance": "oui",
"maj:enfant_4_contact": "oui",
"maj:enfant_4_sanitaire": "oui",
"maj:enfant_4_sanitaire_allergie": "oui",
"maj:enfant_4_sanitaire_medecin": "oui",
"maj:enfant_4_sanitaire_vaccin": "oui",
"maj:enfant_4_sanitaire_handicap": "oui",
"maj:enfant_5": "oui",
"maj:enfant_5_assurance": "oui",
"maj:enfant_5_contact": "oui",
"maj:enfant_5_sanitaire": "oui",
"maj:enfant_5_sanitaire_allergie": "oui",
"maj:enfant_5_sanitaire_medecin": "oui",
"maj:enfant_5_sanitaire_vaccin": "oui",
"maj:enfant_5_sanitaire_handicap": "oui",
"maj:revenus": "oui",
"maj:rl1": "oui",
"maj:rl1_adresse_employeur": "oui",
"maj:rl2": "oui",
"maj:rl2_adresse_employeur": "oui"
}

View File

@ -53,6 +53,7 @@ from passerelle.contrib.toulouse_axel.utils import (
lien_parente_mapping,
type_regime_mapping,
get_reference_year_from_date,
upperize,
)
from passerelle.utils.jsonresponse import APIError
import utils
@ -1070,6 +1071,25 @@ def test_sanitize_update_family_data_missing_revenus_fields(app, resource, updat
assert full_update_params['REVENUS']['NBENFANTSACHARGE'] is None
def test_pre_sanitize_update_upperize(app, resource, update_params):
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
def check_upper(data):
if isinstance(data, dict):
for val in data.values():
check_upper(val)
if isinstance(data, list):
for val in data:
check_upper(val)
if isinstance(data, str):
assert data == data.upper()
resource.pre_sanitize_update_family_data(post_data=update_params)
check_upper(update_params)
assert upperize(u'something with an accent é') == u'SOMETHING WITH AN ACCENT E'
def test_pre_sanitize_update_family_data_adresse(app, resource, update_params):
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')