From d3699aec0682d117a8c459d8bc4d281c849a1249 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Thu, 9 Jan 2020 16:24:11 +0100
Subject: [PATCH 4/5] toulouse_axel: some values are not editable (#38543)

and it will be NOT sent by w.c.s.
---
 functests/toulouse_axel/test_toulouse_axel.py |   7 +-
 passerelle/contrib/toulouse_axel/models.py    |  30 +-
 .../flat_update_family_info.json              |  15 -
 .../toulouse_axel/update_family_info.json     |  15 -
 tests/test_toulouse_axel.py                   | 258 +++++++++++++-----
 5 files changed, 220 insertions(+), 105 deletions(-)

diff --git a/functests/toulouse_axel/test_toulouse_axel.py b/functests/toulouse_axel/test_toulouse_axel.py
index 7a416da3..e7c43f04 100644
--- a/functests/toulouse_axel/test_toulouse_axel.py
+++ b/functests/toulouse_axel/test_toulouse_axel.py
@@ -38,7 +38,12 @@ def test_link(conn, user):
     # remove non editable fields
     for key in ['SITUATIONFAMILIALE', 'NBENFANTACTIF', 'NBRLACTIF', 'IDDUI', 'CODEMISEAJOUR']:
         payload.pop(key)
-    for key in ['MONTANTTOTAL', 'DATEVALIDITE', 'SFI', 'IREVENUS', 'RNF']:
+    for key in ['IDPERSONNE', 'NOM', 'PRENOM', 'NOMJEUNEFILLE', 'DATENAISSANCE', 'CIVILITE', 'INDICATEURRL']:
+        if 'RL1' in payload:
+            payload['RL1'].pop(key)
+        if 'RL2' in payload:
+            payload['RL2'].pop(key)
+    for key in ['MONTANTTOTAL', 'DATEVALIDITE', 'SFI', 'IREVENUS', 'RNF', 'NBENFANTSACHARGE']:
         payload['REVENUS'].pop(key, None)
     for enfant in payload['ENFANT']:
         for key in ['NOM', 'DATENAISSANCE', 'SEXE', 'PRENOMPERE', 'PRENOMMERE', 'NOMPERE', 'NOMMERE', 'RATTACHEAUTREDUI', 'PRENOM']:
diff --git a/passerelle/contrib/toulouse_axel/models.py b/passerelle/contrib/toulouse_axel/models.py
index f6f3137d..e6d0d147 100644
--- a/passerelle/contrib/toulouse_axel/models.py
+++ b/passerelle/contrib/toulouse_axel/models.py
@@ -312,6 +312,14 @@ class ToulouseAxel(BaseResource):
     UPDATE_FAMILY_SCHEMA['required'].remove('IDDUI')
     UPDATE_FAMILY_SCHEMA['required'].remove('DATEDEMANDE')
     UPDATE_FAMILY_SCHEMA['required'].remove('QUIACTUALISEDUI')
+    for key in ['IDPERSONNE', 'NOM', 'PRENOM', 'NOMJEUNEFILLE', 'DATENAISSANCE', 'CIVILITE', 'INDICATEURRL']:
+        UPDATE_FAMILY_SCHEMA['properties']['RL1']['properties'].pop(key)
+        UPDATE_FAMILY_SCHEMA['properties']['RL1']['required'].remove(key)
+        UPDATE_FAMILY_SCHEMA['properties']['RL2']['properties'].pop(key)
+        UPDATE_FAMILY_SCHEMA['properties']['RL2']['required'].remove(key)
+    UPDATE_FAMILY_SCHEMA['properties']['REVENUS']['properties'].pop('NBENFANTSACHARGE')
+    UPDATE_FAMILY_SCHEMA['properties']['REVENUS']['required'].remove('NBENFANTSACHARGE')
+
     handicap_fields = [
         'AUTREDIFFICULTE',
         'ECOLESPECIALISEE',
@@ -612,6 +620,23 @@ class ToulouseAxel(BaseResource):
                 })
             child['SANITAIRE']['ALLERGIE'] = new_allergie
 
+        # retrieve RL not posted fields
+        for rl in ['RL1', 'RL2']:
+            if rl not in post_data:
+                continue
+            if family_data is None:
+                family_data = self.get_family_data(name_id)
+            # fill missing fields
+            for key in ['IDPERSONNE', 'NOM', 'PRENOM', 'NOMJEUNEFILLE', 'DATENAISSANCE', 'CIVILITE']:
+                post_data[rl][key] = family_data[rl][key]
+            post_data[rl]['INDICATEURRL'] = '1' if rl == 'RL1' else '2'
+
+        # fill NBENFANTSACHARGE
+        if 'REVENUS' in post_data:
+            if family_data is None:
+                family_data = self.get_family_data(name_id)
+            post_data['REVENUS']['NBENFANTSACHARGE'] = family_data.get('REVENUS', {}).get('NBENFANTSACHARGE')
+
         # transform ENFANT dict to a list back
         post_data['ENFANT'] = post_data['ENFANT'].values()
 
@@ -638,13 +663,14 @@ class ToulouseAxel(BaseResource):
         # prepare data
         post_data['IDDUI'] = link.dui
         post_data['DATEDEMANDE'] = datetime.date.today().strftime('%Y-%m-%d')
+
+        self.sanitize_update_family_data(name_id=NameID, post_data=post_data)
+
         if 'RL2' in post_data and post_data['RL2'].get('IDPERSONNE') == link.person_id:
             post_data['QUIACTUALISEDUI'] = '2'
         else:
             post_data['QUIACTUALISEDUI'] = '1'
 
-        self.sanitize_update_family_data(name_id=NameID, post_data=post_data)
-
         try:
             result = form_maj_famille_dui(self, {'PORTAIL': {'DUI': post_data}})
         except AxelError as e:
diff --git a/tests/data/toulouse_axel/flat_update_family_info.json b/tests/data/toulouse_axel/flat_update_family_info.json
index 5db4296c..81a95865 100644
--- a/tests/data/toulouse_axel/flat_update_family_info.json
+++ b/tests/data/toulouse_axel/flat_update_family_info.json
@@ -97,7 +97,6 @@
   "REACTUALISATIONENLIGNE": "NON",
   "REVENUS/ALLOCATAIRE": "2",
   "REVENUS/CHOIXREVENU": "",
-  "REVENUS/NBENFANTSACHARGE": 2,
   "REVENUS/NUMEROCAF": "1234",
   "REVENUS/TYPEREGIME": "GENE",
   "RL1/ADREMPLOYEUR/CODEINSEEVILLE": "",
@@ -109,16 +108,9 @@
   "RL1/ADREMPLOYEUR/NUMVOIE": "",
   "RL1/ADREMPLOYEUR/VILLE": "",
   "RL1/ADREMPLOYEUR/VOIE": "",
-  "RL1/CIVILITE": "M",
   "RL1/COURRIEL": "foo@bar.com",
   "RL1/CSP": "ETU",
-  "RL1/DATENAISSANCE": "1980-01-01",
-  "RL1/IDPERSONNE": "42",
-  "RL1/INDICATEURRL": "1",
-  "RL1/NOM": "foo",
   "RL1/NOMEMPLOYEUR": "foo",
-  "RL1/NOMJEUNEFILLE": "",
-  "RL1/PRENOM": "foo",
   "RL1/PROFESSION": "ETUDIANT",
   "RL1/TELPORTABLE": "0606060606",
   "RL2/ADREMPLOYEUR/CODEINSEEVILLE": "",
@@ -130,16 +122,9 @@
   "RL2/ADREMPLOYEUR/NUMVOIE": "",
   "RL2/ADREMPLOYEUR/VILLE": "",
   "RL2/ADREMPLOYEUR/VOIE": "",
-  "RL2/CIVILITE": "MME",
   "RL2/COURRIEL": "foo@bar.com",
   "RL2/CSP": "EMP",
-  "RL2/DATENAISSANCE": "1980-01-01",
-  "RL2/IDPERSONNE": "35",
-  "RL2/INDICATEURRL": "2",
-  "RL2/NOM": "foo",
   "RL2/NOMEMPLOYEUR": "foo",
-  "RL2/NOMJEUNEFILLE": "",
-  "RL2/PRENOM": "foo",
   "RL2/PROFESSION": "foo",
   "RL2/TELPORTABLE": "0606060606",
   "TELFIXE": "",
diff --git a/tests/data/toulouse_axel/update_family_info.json b/tests/data/toulouse_axel/update_family_info.json
index f02c57e2..b1e498e6 100644
--- a/tests/data/toulouse_axel/update_family_info.json
+++ b/tests/data/toulouse_axel/update_family_info.json
@@ -138,7 +138,6 @@
     "REVENUS": {
         "ALLOCATAIRE": "2",
         "CHOIXREVENU": "",
-        "NBENFANTSACHARGE": 2,
         "NUMEROCAF": "1234",
         "TYPEREGIME": "GENE"
     },
@@ -154,16 +153,9 @@
             "VILLE": null,
             "VOIE": null
         },
-        "CIVILITE": "M",
         "COURRIEL": "foo@bar.com",
         "CSP": "ETU",
-        "DATENAISSANCE": "1980-01-01",
-        "IDPERSONNE": "42",
-        "INDICATEURRL": "1",
-        "NOM": "foo",
         "NOMEMPLOYEUR": "foo",
-        "NOMJEUNEFILLE": null,
-        "PRENOM": "foo",
         "PROFESSION": "ETUDIANT",
         "TELPORTABLE": "0606060606"
     },
@@ -179,16 +171,9 @@
             "VILLE": null,
             "VOIE": null
         },
-        "CIVILITE": "MME",
         "COURRIEL": "foo@bar.com",
         "CSP": "EMP",
-        "DATENAISSANCE": "1980-01-01",
-        "IDPERSONNE": "35",
-        "INDICATEURRL": "2",
-        "NOM": "foo",
         "NOMEMPLOYEUR": "foo",
-        "NOMJEUNEFILLE": null,
-        "PRENOM": "foo",
         "PROFESSION": "foo",
         "TELPORTABLE": "0606060606"
     },
diff --git a/tests/test_toulouse_axel.py b/tests/test_toulouse_axel.py
index efe528f5..a263c33c 100644
--- a/tests/test_toulouse_axel.py
+++ b/tests/test_toulouse_axel.py
@@ -20,6 +20,7 @@ import datetime
 import json
 import mock
 import os
+import xml.etree.ElementTree as ET
 
 import pytest
 import xmlschema
@@ -66,6 +67,28 @@ def update_params():
     return json.loads(content)
 
 
+@pytest.fixture
+def family_data():
+    filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/family_info.xml')
+    with open(filepath) as xml:
+        content = xml.read()
+    resp = '''
+    <?xml version="1.0"?>
+    <PORTAILSERVICE>
+      <RESULTAT>
+        <TYPE>RefFamilleDui</TYPE>
+        <STATUS>OK</STATUS>
+        <DATE>10/10/2010 10:10:01</DATE>
+        <COMMENTAIRES><![CDATA[]]></COMMENTAIRES>
+      </RESULTAT>
+      <DATA>
+        %s
+      </DATA>
+    </PORTAILSERVICE>
+    '''.strip() % content
+    return ref_famille_dui.response_converter.decode(ET.fromstring(resp))['DATA']['PORTAIL']['DUI']
+
+
 @pytest.fixture
 def flat_update_params():
     filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/flat_update_family_info.json')
@@ -564,11 +587,13 @@ def test_child_info_endpoint(app, resource):
     ])
 
 
-def test_update_family_info_endpoint_axel_error(app, resource, update_params):
+def test_update_family_info_endpoint_axel_error(app, resource, update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
+
     with mock.patch('passerelle.contrib.toulouse_axel.models.form_maj_famille_dui') as operation:
         operation.side_effect = AxelError('FooBar')
-        resp = app.post_json('/toulouse-axel/test/update_family_info?NameID=yyy', params=update_params)
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+            resp = app.post_json('/toulouse-axel/test/update_family_info?NameID=yyy', params=update_params)
     assert resp.json['err_desc'] == "Axel error: FooBar"
     assert resp.json['err'] == 'error'
     assert 'error_post_data' in resp.json['data']
@@ -580,11 +605,13 @@ def test_update_family_info_endpoint_no_result(app, resource, update_params):
     assert resp.json['err'] == 'not-found'
 
 
-def test_update_family_info_endpoint(app, resource, update_params):
+def test_update_family_info_endpoint(app, resource, update_params, family_data):
     link = Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
+
     content = "<PORTAIL/>"
     with mock_getdata(content, 'FormMajFamilleDui'):
-        resp = app.post_json('/toulouse-axel/test/update_family_info?NameID=yyy', params=update_params)
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+            resp = app.post_json('/toulouse-axel/test/update_family_info?NameID=yyy', params=update_params)
     assert resp.json['err'] == 0
     assert resp.json['dui'] == 'XXX'
     assert resp.json['updated'] is True
@@ -594,7 +621,8 @@ def test_update_family_info_endpoint(app, resource, update_params):
 
     with mock.patch('passerelle.contrib.toulouse_axel.models.form_maj_famille_dui') as operation:
         operation.return_value = OperationResult(json_response={}, xml_request='', xml_response='')
-        resp = app.post_json('/toulouse-axel/test/update_family_info?NameID=yyy', params=update_params)
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+            resp = app.post_json('/toulouse-axel/test/update_family_info?NameID=yyy', params=update_params)
     assert operation.call_args_list[0][0][1]['PORTAIL']['DUI']['IDDUI'] == 'XXX'
     assert operation.call_args_list[0][0][1]['PORTAIL']['DUI']['DATEDEMANDE'] == datetime.date.today().strftime('%Y-%m-%d')
     assert operation.call_args_list[0][0][1]['PORTAIL']['DUI']['QUIACTUALISEDUI'] == '1'
@@ -603,17 +631,19 @@ def test_update_family_info_endpoint(app, resource, update_params):
     link.save()
     with mock.patch('passerelle.contrib.toulouse_axel.models.form_maj_famille_dui') as operation:
         operation.return_value = OperationResult(json_response={}, xml_request='', xml_response='')
-        resp = app.post_json('/toulouse-axel/test/update_family_info?NameID=yyy', params=update_params)
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+            resp = app.post_json('/toulouse-axel/test/update_family_info?NameID=yyy', params=update_params)
     assert operation.call_args_list[0][0][1]['PORTAIL']['DUI']['IDDUI'] == 'XXX'
     assert operation.call_args_list[0][0][1]['PORTAIL']['DUI']['DATEDEMANDE'] == datetime.date.today().strftime('%Y-%m-%d')
     assert operation.call_args_list[0][0][1]['PORTAIL']['DUI']['QUIACTUALISEDUI'] == '2'
 
 
-def test_update_family_info_flat_endpoint(app, resource, flat_update_params):
+def test_update_family_info_flat_endpoint(app, resource, flat_update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
     content = "<PORTAIL/>"
     with mock_getdata(content, 'FormMajFamilleDui'):
-        resp = app.post_json('/toulouse-axel/test/update_family_info?NameID=yyy', params=flat_update_params)
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+            resp = app.post_json('/toulouse-axel/test/update_family_info?NameID=yyy', params=flat_update_params)
     assert resp.json['err'] == 0
     assert resp.json['dui'] == 'XXX'
     assert resp.json['updated'] is True
@@ -622,7 +652,42 @@ def test_update_family_info_flat_endpoint(app, resource, flat_update_params):
     assert 'xml_response' in resp.json['data']
 
 
-def test_sanitize_update_family_data_adresse(app, resource, update_params):
+def test_sanitize_update_family_data_missing_rl_fields(app, resource, update_params, family_data):
+    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
+
+    full_update_params = copy.deepcopy(update_params)
+    for key in ['IDPERSONNE', 'NOM', 'PRENOM', 'NOMJEUNEFILLE', 'DATENAISSANCE', 'CIVILITE']:
+        assert key not in full_update_params['RL1']
+        assert key not in full_update_params['RL2']
+
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=full_update_params)
+    for key in ['IDPERSONNE', 'NOM', 'PRENOM', 'NOMJEUNEFILLE', 'DATENAISSANCE', 'CIVILITE']:
+        assert full_update_params['RL1'][key] == family_data['RL1'][key]
+        assert full_update_params['RL2'][key] == family_data['RL2'][key]
+    assert full_update_params['RL1']['INDICATEURRL'] == '1'
+    assert full_update_params['RL2']['INDICATEURRL'] == '2'
+
+
+def test_sanitize_update_family_data_missing_revenus_fields(app, resource, update_params, family_data):
+    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
+
+    full_update_params = copy.deepcopy(update_params)
+    assert 'NBENFANTSACHARGE' not in update_params['REVENUS']
+
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=full_update_params)
+    assert full_update_params['REVENUS']['NBENFANTSACHARGE'] == family_data['REVENUS']['NBENFANTSACHARGE']
+
+    # if revenus are not set in Axel
+    full_update_params = copy.deepcopy(update_params)
+    family_data.pop('REVENUS')
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=full_update_params)
+    assert full_update_params['REVENUS']['NBENFANTSACHARGE'] is None
+
+
+def test_sanitize_update_family_data_adresse(app, resource, update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
 
     # test maj:adresse
@@ -630,12 +695,13 @@ def test_sanitize_update_family_data_adresse(app, resource, update_params):
     partial_update_params['maj:adresse'] = False
     for key in partial_update_params['ADRESSE'].keys():
         partial_update_params['ADRESSE'][key] = None  # reset fields
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     for value in partial_update_params['ADRESSE'].values():
         assert value is None
 
 
-def test_sanitize_update_family_data_revenus(app, resource, update_params):
+def test_sanitize_update_family_data_revenus(app, resource, update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
 
     # test maj:revenus
@@ -643,11 +709,12 @@ def test_sanitize_update_family_data_revenus(app, resource, update_params):
     partial_update_params['maj:revenus'] = False
     for key in partial_update_params['REVENUS'].keys():
         partial_update_params['REVENUS'][key] = None  # reset fields
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'REVENUS' not in partial_update_params
 
 
-def test_sanitize_update_family_data_rln(app, resource, update_params):
+def test_sanitize_update_family_data_rln(app, resource, update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
 
     # test maj:rln
@@ -655,17 +722,19 @@ def test_sanitize_update_family_data_rln(app, resource, update_params):
     partial_update_params['maj:rl1'] = False
     for key in partial_update_params['RL1'].keys():
         partial_update_params['RL1'][key] = None  # reset fields
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'RL1' not in partial_update_params
     partial_update_params = copy.deepcopy(update_params)
     partial_update_params['maj:rl2'] = False
     for key in partial_update_params['RL2'].keys():
         partial_update_params['RL2'][key] = None  # reset fields
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'RL2' not in partial_update_params
 
 
-def test_sanitize_update_family_data_rln_adresse_employeur(app, resource, update_params):
+def test_sanitize_update_family_data_rln_adresse_employeur(app, resource, update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
 
     # test maj:rln_adresse_employeur
@@ -673,39 +742,45 @@ def test_sanitize_update_family_data_rln_adresse_employeur(app, resource, update
     partial_update_params['maj:rl1_adresse_employeur'] = False
     for key in partial_update_params['RL1']['ADREMPLOYEUR'].keys():
         partial_update_params['RL1']['ADREMPLOYEUR'][key] = None  # reset fields
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'ADREMPLOYEUR' not in partial_update_params['RL1']
     partial_update_params = copy.deepcopy(update_params)
     partial_update_params['maj:rl2_adresse_employeur'] = False
     for key in partial_update_params['RL2']['ADREMPLOYEUR'].keys():
         partial_update_params['RL2']['ADREMPLOYEUR'][key] = None  # reset fields
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'ADREMPLOYEUR' not in partial_update_params['RL2']
     # combine with maj:rln
     partial_update_params = copy.deepcopy(update_params)
     partial_update_params['maj:rl1'] = False
     partial_update_params['maj:rl1_adresse_employeur'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'RL1' not in partial_update_params
     partial_update_params = copy.deepcopy(update_params)
     partial_update_params['maj:rl2'] = False
     partial_update_params['maj:rl2_adresse_employeur'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'RL2' not in partial_update_params
 
     # test maj:rln_adresse_employeur not set
     for val in [None, '']:
         partial_update_params = copy.deepcopy(update_params)
         partial_update_params['maj:rl1_adresse_employeur'] = val
-        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+            resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
         assert 'ADREMPLOYEUR' not in partial_update_params['RL1']
         partial_update_params = copy.deepcopy(update_params)
         partial_update_params['maj:rl2_adresse_employeur'] = val
-        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+            resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
         assert 'ADREMPLOYEUR' not in partial_update_params['RL2']
 
 
-def test_sanitize_update_family_data_enfant_n(app, resource, update_params):
+def test_sanitize_update_family_data_enfant_n(app, resource, update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
 
     # test maj:enfant_n
@@ -715,7 +790,8 @@ def test_sanitize_update_family_data_enfant_n(app, resource, update_params):
         if key == 'IDPERSONNE':
             continue
         partial_update_params['ENFANT'][0][key] = None  # reset fields
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "3535"
 
@@ -725,7 +801,8 @@ def test_sanitize_update_family_data_enfant_n(app, resource, update_params):
         if key == 'IDPERSONNE':
             continue
         partial_update_params['ENFANT'][1][key] = None  # reset fields
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "4242"
 
@@ -734,7 +811,8 @@ def test_sanitize_update_family_data_enfant_n(app, resource, update_params):
     partial_update_params['maj:enfant_1'] = False
     for key in partial_update_params['ENFANT'][1].keys():
         partial_update_params['ENFANT'][1][key] = None  # reset fields
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "4242"
 
@@ -742,17 +820,19 @@ def test_sanitize_update_family_data_enfant_n(app, resource, update_params):
     partial_update_params = copy.deepcopy(update_params)
     partial_update_params['maj:enfant_0'] = False
     partial_update_params['maj:enfant_1'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'ENFANT' not in partial_update_params
 
     # unknown child
     partial_update_params = copy.deepcopy(update_params)
     partial_update_params['maj:enfant_5'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 2
 
 
-def test_sanitize_update_family_data_enfant_n_assurance(app, resource, update_params):
+def test_sanitize_update_family_data_enfant_n_assurance(app, resource, update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
 
     # test maj:enfant_n_assurance
@@ -761,7 +841,8 @@ def test_sanitize_update_family_data_enfant_n_assurance(app, resource, update_pa
     for key in partial_update_params['ENFANT'][1]['ASSURANCE'].keys():
         partial_update_params['ENFANT'][1]['ASSURANCE'][key] = None  # reset fields
     partial_update_params['maj:enfant_0'] = False  # check that ordering is not a problem
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "3535"
     assert 'ASSURANCE' not in partial_update_params['ENFANT'][0]
@@ -770,7 +851,8 @@ def test_sanitize_update_family_data_enfant_n_assurance(app, resource, update_pa
     partial_update_params['maj:enfant_1'] = False
     partial_update_params['maj:enfant_1_assurance'] = False
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'ENFANT' not in partial_update_params
 
     # test maj:enfant_n_assurance not set
@@ -778,11 +860,12 @@ def test_sanitize_update_family_data_enfant_n_assurance(app, resource, update_pa
         partial_update_params = copy.deepcopy(update_params)
         partial_update_params['maj:enfant_1_assurance'] = val
         partial_update_params['maj:enfant_0'] = False
-        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+            resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
         assert 'ASSURANCE' not in partial_update_params['ENFANT'][0]
 
 
-def test_sanitize_update_family_data_enfant_n_contact(app, resource, update_params):
+def test_sanitize_update_family_data_enfant_n_contact(app, resource, update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
 
     # test maj:enfant_n_contact
@@ -792,7 +875,8 @@ def test_sanitize_update_family_data_enfant_n_contact(app, resource, update_para
         for key in contact.keys():
             partial_update_params['ENFANT'][0]['CONTACT'][i][key] = None  # reset fields
     partial_update_params['maj:enfant_1'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "4242"
     assert 'CONTACT' not in partial_update_params['ENFANT'][0]
@@ -801,7 +885,8 @@ def test_sanitize_update_family_data_enfant_n_contact(app, resource, update_para
     partial_update_params['maj:enfant_1'] = False
     partial_update_params['maj:enfant_1_contact'] = False
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'ENFANT' not in partial_update_params
 
     # test maj:enfant_n_contact not set
@@ -809,11 +894,12 @@ def test_sanitize_update_family_data_enfant_n_contact(app, resource, update_para
         partial_update_params = copy.deepcopy(update_params)
         partial_update_params['maj:enfant_0_contact'] = val
         partial_update_params['maj:enfant_1'] = False
-        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+            resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
         assert 'CONTACT' not in partial_update_params['ENFANT'][0]
 
 
-def test_sanitize_update_family_data_enfant_n_sanitaire(app, resource, update_params):
+def test_sanitize_update_family_data_enfant_n_sanitaire(app, resource, update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
 
     # test maj:enfant_n_sanitaire
@@ -822,7 +908,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire(app, resource, update_pa
     for key in partial_update_params['ENFANT'][1]['SANITAIRE'].keys():
         partial_update_params['ENFANT'][1]['SANITAIRE'][key] = None  # reset fields
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "3535"
     assert 'SANITAIRE' not in partial_update_params['ENFANT'][0]
@@ -831,7 +918,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire(app, resource, update_pa
     partial_update_params['maj:enfant_1'] = False
     partial_update_params['maj:enfant_1_sanitaire'] = False
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'ENFANT' not in partial_update_params
 
     # test maj:enfant_n_sanitaire not set
@@ -839,12 +927,13 @@ def test_sanitize_update_family_data_enfant_n_sanitaire(app, resource, update_pa
         partial_update_params = copy.deepcopy(update_params)
         partial_update_params['maj:enfant_0_sanitaire'] = val
         partial_update_params['maj:enfant_1_sanitaire'] = val
-        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+            resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
         assert 'SANITAIRE' not in partial_update_params['ENFANT'][0]
         assert 'SANITAIRE' not in partial_update_params['ENFANT'][1]
 
 
-def test_sanitize_update_family_data_enfant_n_sanitaire_allergie(app, resource, update_params):
+def test_sanitize_update_family_data_enfant_n_sanitaire_allergie(app, resource, update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
 
     # test maj:enfant_n_sanitaire_allergie
@@ -853,7 +942,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_allergie(app, resource,
     for key in partial_update_params['ENFANT'][0]['SANITAIRE']['ALLERGIE'].keys():
         partial_update_params['ENFANT'][0]['SANITAIRE']['ALLERGIE'][key] = None  # reset fields
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "3535"
     assert 'ALLERGIE' not in partial_update_params['ENFANT'][0]['SANITAIRE']
@@ -862,7 +952,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_allergie(app, resource,
     partial_update_params['maj:enfant_1_sanitaire'] = False
     partial_update_params['maj:enfant_1_sanitaire_allergie'] = False
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "3535"
     assert 'SANITAIRE' not in partial_update_params['ENFANT'][0]
@@ -871,7 +962,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_allergie(app, resource,
     partial_update_params['maj:enfant_1'] = False
     partial_update_params['maj:enfant_1_sanitaire_allergie'] = False
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'ENFANT' not in partial_update_params
 
     # test maj:enfant_n_sanitaire_allergie not set
@@ -879,7 +971,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_allergie(app, resource,
         partial_update_params = copy.deepcopy(update_params)
         partial_update_params['maj:enfant_0_sanitaire_allergie'] = val
         partial_update_params['maj:enfant_1_sanitaire_allergie'] = val
-        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+            resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
         assert 'ALLERGIE' not in partial_update_params['ENFANT'][0]['SANITAIRE']
         assert 'ALLERGIE' not in partial_update_params['ENFANT'][1]['SANITAIRE']
 
@@ -890,7 +983,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_allergie(app, resource,
     partial_update_params['ENFANT'][0]['SANITAIRE']['ALLERGIE']['MEDICAMENTEUSES'] = 'NON'
     partial_update_params['ENFANT'][0]['SANITAIRE']['ALLERGIE']['ALIMENTAIRES'] = 'NON'
     partial_update_params['ENFANT'][0]['SANITAIRE']['ALLERGIE']['AUTRES'] = ''
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert partial_update_params['ENFANT'][0]['SANITAIRE']['ALLERGIE'] == [
         {'TYPE': 'ASTHME', 'ALLERGIQUE': 'NON', 'NOMALLERGIE': None},
         {'TYPE': 'MEDICAMENTEUSES', 'ALLERGIQUE': 'NON', 'NOMALLERGIE': None},
@@ -903,7 +997,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_allergie(app, resource,
     partial_update_params['ENFANT'][0]['SANITAIRE']['ALLERGIE']['MEDICAMENTEUSES'] = 'OUI'
     partial_update_params['ENFANT'][0]['SANITAIRE']['ALLERGIE']['ALIMENTAIRES'] = 'OUI'
     partial_update_params['ENFANT'][0]['SANITAIRE']['ALLERGIE']['AUTRES'] = 'accariens'
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert partial_update_params['ENFANT'][0]['SANITAIRE']['ALLERGIE'] == [
         {'TYPE': 'ASTHME', 'ALLERGIQUE': 'OUI', 'NOMALLERGIE': None},
         {'TYPE': 'MEDICAMENTEUSES', 'ALLERGIQUE': 'OUI', 'NOMALLERGIE': None},
@@ -912,7 +1007,7 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_allergie(app, resource,
     ]
 
 
-def test_sanitize_update_family_data_enfant_n_sanitaire_medecin(app, resource, update_params):
+def test_sanitize_update_family_data_enfant_n_sanitaire_medecin(app, resource, update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
 
     # test maj:enfant_n_sanitaire_medecin
@@ -921,7 +1016,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_medecin(app, resource, u
     for key in partial_update_params['ENFANT'][1]['SANITAIRE']['MEDECIN'].keys():
         partial_update_params['ENFANT'][1]['SANITAIRE']['MEDECIN'][key] = None  # reset fields
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "3535"
     assert 'MEDECIN' not in partial_update_params['ENFANT'][0]['SANITAIRE']
@@ -930,7 +1026,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_medecin(app, resource, u
     partial_update_params['maj:enfant_1_sanitaire'] = False
     partial_update_params['maj:enfant_1_sanitaire_medecin'] = False
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "3535"
     assert 'SANITAIRE' not in partial_update_params['ENFANT'][0]
@@ -939,7 +1036,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_medecin(app, resource, u
     partial_update_params['maj:enfant_1'] = False
     partial_update_params['maj:enfant_1_sanitaire_medecin'] = False
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'ENFANT' not in partial_update_params
 
     # test maj:enfant_n_sanitaire_medecin not set
@@ -947,12 +1045,13 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_medecin(app, resource, u
         partial_update_params = copy.deepcopy(update_params)
         partial_update_params['maj:enfant_0_sanitaire_medecin'] = val
         partial_update_params['maj:enfant_1_sanitaire_medecin'] = val
-        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+            resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
         assert 'MEDECIN' not in partial_update_params['ENFANT'][0]['SANITAIRE']
         assert 'MEDECIN' not in partial_update_params['ENFANT'][1]['SANITAIRE']
 
 
-def test_sanitize_update_family_data_enfant_n_sanitaire_vaccin(app, resource, update_params):
+def test_sanitize_update_family_data_enfant_n_sanitaire_vaccin(app, resource, update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
 
     # test maj:enfant_n_sanitaire_vaccin
@@ -961,7 +1060,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_vaccin(app, resource, up
     for key in partial_update_params['ENFANT'][1]['SANITAIRE']['VACCIN'].keys():
         partial_update_params['ENFANT'][1]['SANITAIRE']['VACCIN'][key] = None  # reset fields
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "3535"
     assert 'VACCIN' not in partial_update_params['ENFANT'][0]['SANITAIRE']
@@ -970,7 +1070,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_vaccin(app, resource, up
     partial_update_params['maj:enfant_1_sanitaire'] = False
     partial_update_params['maj:enfant_1_sanitaire_vaccin'] = False
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "3535"
     assert 'SANITAIRE' not in partial_update_params['ENFANT'][0]
@@ -979,7 +1080,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_vaccin(app, resource, up
     partial_update_params['maj:enfant_1'] = False
     partial_update_params['maj:enfant_1_sanitaire_vaccin'] = False
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'ENFANT' not in partial_update_params
 
     # test maj:enfant_n_sanitaire_vaccin not set
@@ -987,18 +1089,16 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_vaccin(app, resource, up
         partial_update_params = copy.deepcopy(update_params)
         partial_update_params['maj:enfant_0_sanitaire_vaccin'] = val
         partial_update_params['maj:enfant_1_sanitaire_vaccin'] = val
-        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+            resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
         assert 'VACCIN' not in partial_update_params['ENFANT'][0]['SANITAIRE']
         assert 'VACCIN' not in partial_update_params['ENFANT'][1]['SANITAIRE']
 
 
-def test_sanitize_update_family_data_enfant_n_sanitaire_handicap(app, resource, update_params):
+def test_sanitize_update_family_data_enfant_n_sanitaire_handicap(app, resource, update_params, family_data):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
 
     # test maj:enfant_n_contact
-    filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/family_info.xml')
-    with open(filepath) as xml:
-        content = xml.read()
     partial_update_params = copy.deepcopy(update_params)
     partial_update_params['maj:enfant_0_sanitaire_handicap'] = False
     # reset fields
@@ -1013,21 +1113,21 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_handicap(app, resource,
     for key in handicap_fields:
         partial_update_params['ENFANT'][0]['SANITAIRE']['HANDICAP'][key] = None
     partial_update_params['maj:enfant_1'] = False
-    with mock_getdata(content, 'RefFamilleDui'):
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
         resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
-        original_values = resource.get_family_data(name_id='yyy')['ENFANT'][0]['SANITAIRE']
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "4242"
     # fields were set with origin values found in Axel
     new_values = partial_update_params['ENFANT'][0]['SANITAIRE']
     for key in handicap_fields:
-        assert new_values[key] == original_values[key]
+        assert new_values[key] == family_data['ENFANT'][0]['SANITAIRE'][key]
     # combine with maj:enfant_n_sanitaire
     partial_update_params = copy.deepcopy(update_params)
     partial_update_params['maj:enfant_1_sanitaire'] = False
     partial_update_params['maj:enfant_1_sanitaire_handicap'] = False
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert len(partial_update_params['ENFANT']) == 1
     assert partial_update_params['ENFANT'][0]['IDPERSONNE'] == "3535"
     assert 'SANITAIRE' not in partial_update_params['ENFANT'][0]
@@ -1036,7 +1136,8 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_handicap(app, resource,
     partial_update_params['maj:enfant_1'] = False
     partial_update_params['maj:enfant_1_sanitaire_sanitaire'] = False
     partial_update_params['maj:enfant_0'] = False
-    resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
+    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
+        resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
     assert 'ENFANT' not in partial_update_params
 
     # test maj:enfant_n_sanitaire_handicap not set
@@ -1047,16 +1148,29 @@ def test_sanitize_update_family_data_enfant_n_sanitaire_handicap(app, resource,
         # reset fields
         for key in handicap_fields:
             partial_update_params['ENFANT'][0]['SANITAIRE']['HANDICAP'][key] = None
-        with mock.patch('passerelle.contrib.toulouse_axel.models.ref_famille_dui') as operation:
+        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
             resource.sanitize_update_family_data(name_id='yyy', post_data=partial_update_params)
-        assert operation.call_args_list == [mock.call(resource, {'PORTAIL': {'DUI': {'IDDUI': u'XXX'}}})]
-
-
-def test_sanitize_update_family_data_axel_error(app, resource, update_params):
+        new_values = partial_update_params['ENFANT'][0]['SANITAIRE']
+        for key in handicap_fields:
+            assert new_values[key] == family_data['ENFANT'][0]['SANITAIRE'][key]
+
+
+@pytest.mark.parametrize('flags', [
+    # get family data to fill handicap fields
+    ['maj:enfant_0_sanitaire_handicap', 'maj:revenus', 'maj:rl1', 'maj:rl2'],
+    # get family data to fill revenus fields
+    ['maj:rl1', 'maj:rl2'],
+    # get family data to fill rl1 fields
+    ['maj:revenus', 'maj:rl2'],
+    # get family data to fill rl2 fields
+    ['maj:revenus', 'maj:rl1'],
+])
+def test_sanitize_update_family_data_axel_error(app, resource, update_params, flags):
     Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
 
     partial_update_params = copy.deepcopy(update_params)
-    partial_update_params['maj:enfant_0_sanitaire_handicap'] = False
+    for flag in flags:
+        partial_update_params[flag] = False
     with mock.patch('passerelle.contrib.toulouse_axel.models.ref_famille_dui') as operation:
         operation.side_effect = AxelError('FooBar')
         with pytest.raises(APIError, match='Axel error: FooBar'):
-- 
2.20.1

