From a9e6846bf8b4ac5847e0b1ad8c99264bbaca69f3 Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Wed, 7 Dec 2022 15:12:52 +0100
Subject: [PATCH 3/7] toulouse-maelis: check WS payload first (#70982)

---
 passerelle/contrib/toulouse_maelis/models.py | 18 +++++-----
 tests/test_toulouse_maelis.py                | 38 ++++++++++----------
 2 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/passerelle/contrib/toulouse_maelis/models.py b/passerelle/contrib/toulouse_maelis/models.py
index 1478ca20..3d8cdfcd 100644
--- a/passerelle/contrib/toulouse_maelis/models.py
+++ b/passerelle/contrib/toulouse_maelis/models.py
@@ -717,19 +717,19 @@ class ToulouseMaelis(BaseResource, HTTPResource):
         description='Modification du RL1',
         name='update-rl1',
         perm='can_access',
         parameters={'NameID': {'description': 'Publik NameID'}},
         post={'request_body': {'schema': {'application/json': schemas.UPDATE_RL1_SCHEMA}}},
     )
     def update_rl1(self, request, NameID, post_data):
         family_id = self.get_link(NameID).family_id
-        family = self.get_family_raw(family_id)
         self.assert_rl_payload_in_referential(post_data)
         self.replace_null_values(post_data)
+        family = self.get_family_raw(family_id)
 
         rl1 = post_data
         rl1['adresse'] = family['RL1']['adresse']
         payload = {
             'dossierNumber': family_id,
             'category': family['category'],
             'situation': family['situation'],
             'flagCom': family['flagCom'],
@@ -746,20 +746,20 @@ class ToulouseMaelis(BaseResource, HTTPResource):
         description='Création du RL2',
         name='create-rl2',
         perm='can_access',
         parameters={'NameID': {'description': 'Publik NameID'}},
         post={'request_body': {'schema': {'application/json': schemas.CREATE_RL2_SCHEMA}}},
     )
     def create_rl2(self, request, NameID, post_data):
         family_id = self.get_link(NameID).family_id
+        self.assert_rl_payload_in_referential(post_data)
         family = self.get_family_raw(family_id)
         if family['RL2']:
             raise APIError('RL2 already defined on family', err_code='already-rl2')
-        self.assert_rl_payload_in_referential(post_data)
 
         payload = {
             'dossierNumber': family_id,
             'category': family['category'],
             'situation': family['situation'],
             'flagCom': family['flagCom'],
             'nbChild': family['nbChild'],
             'nbTotalChild': family['nbTotalChild'],
@@ -774,21 +774,21 @@ class ToulouseMaelis(BaseResource, HTTPResource):
         description='Modification du RL2',
         name='update-rl2',
         perm='can_access',
         parameters={'NameID': {'description': 'Publik NameID'}},
         post={'request_body': {'schema': {'application/json': schemas.UPDATE_RL2_SCHEMA}}},
     )
     def update_rl2(self, request, NameID, post_data):
         family_id = self.get_link(NameID).family_id
+        self.assert_rl_payload_in_referential(post_data)
+        self.replace_null_values(post_data)
         family = self.get_family_raw(family_id)
         if not family['RL2']:
             raise APIError('No RL2 to update on family', err_code='no-rl2')
-        self.assert_rl_payload_in_referential(post_data)
-        self.replace_null_values(post_data)
 
         rl2 = post_data
         rl2['adresse'] = family['RL2']['adresse']
         payload = {
             'dossierNumber': family_id,
             'category': family['category'],
             'situation': family['situation'],
             'flagCom': family['flagCom'],
@@ -840,19 +840,19 @@ class ToulouseMaelis(BaseResource, HTTPResource):
         parameters={
             'NameID': {'description': 'Publik NameID'},
             'child_id': {'description': "Numéro de l'enfant"},
         },
         post={'request_body': {'schema': {'application/json': schemas.UPDATE_CHILD_SCHEMA}}},
     )
     def update_child(self, request, NameID, child_id, post_data):
         family_id = self.get_link(NameID).family_id
-        family = self.get_family_raw(family_id)
         self.assert_child_payload_in_referential(post_data)
         self.replace_null_values(post_data)
+        family = self.get_family_raw(family_id)
 
         child = post_data
         child['num'] = child_id
         for known_child in family['childList']:
             if str(known_child['num']) == child_id:
                 child['authorizedPersonList'] = known_child['authorizedPersonList']
                 break
         else:
@@ -896,18 +896,18 @@ class ToulouseMaelis(BaseResource, HTTPResource):
         perm='can_access',
         parameters={
             'NameID': {'description': 'Publik NameID'},
         },
         post={'request_body': {'schema': {'application/json': schemas.EMERGENCY_PERSON_SCHEMA}}},
     )
     def create_person(self, request, NameID, post_data):
         family_id = self.get_link(NameID).family_id
-        family = self.get_family_raw(family_id)
         self.assert_person_payload_in_referential(post_data)
+        family = self.get_family_raw(family_id)
 
         personList = family['emergencyPersonList']
         personList.append(post_data)
         payload = {
             'dossierNumber': family_id,
             'category': family['category'],
             'situation': family['situation'],
             'flagCom': family['flagCom'],
@@ -927,18 +927,18 @@ class ToulouseMaelis(BaseResource, HTTPResource):
         parameters={
             'NameID': {'description': 'Publik NameID'},
             'person_id': {'description': 'Numéro de la personne'},
         },
         post={'request_body': {'schema': {'application/json': schemas.EMERGENCY_PERSON_SCHEMA}}},
     )
     def update_person(self, request, NameID, person_id, post_data):
         family_id = self.get_link(NameID).family_id
-        family = self.get_family_raw(family_id)
         self.assert_person_payload_in_referential(post_data)
+        family = self.get_family_raw(family_id)
 
         personList = family['emergencyPersonList']
         for i, person in enumerate(personList):
             if str(person['numPerson']) == person_id:
                 personList[i] = post_data
                 personList[i]['numPerson'] = person_id
                 break
         else:
@@ -1003,18 +1003,18 @@ class ToulouseMaelis(BaseResource, HTTPResource):
         parameters={
             'NameID': {'description': 'Publik NameID'},
             'child_id': {'description': "Numéro de l'enfant"},
         },
         post={'request_body': {'schema': {'application/json': schemas.AUTHORIZED_PERSON_SCHEMA}}},
     )
     def create_child_person(self, request, NameID, child_id, post_data):
         family_id = self.get_link(NameID).family_id
-        child = self.get_child_raw(family_id, child_id)
         self.assert_child_person_payload_in_referential(post_data)
+        child = self.get_child_raw(family_id, child_id)
 
         personList = child['authorizedPersonList']
         personList.append(post_data)
         req = {
             'numFamily': family_id,
             'numPerson': child_id,
             'bLeaveAlone': child['bLeaveAlone'],
             'bPhoto': child['bPhoto'],
@@ -1032,18 +1032,18 @@ class ToulouseMaelis(BaseResource, HTTPResource):
             'NameID': {'description': 'Publik NameID'},
             'child_id': {'description': "Numéro de l'enfant"},
             'person_id': {'description': 'Numéro de la personne'},
         },
         post={'request_body': {'schema': {'application/json': schemas.AUTHORIZED_PERSON_SCHEMA}}},
     )
     def update_child_person(self, request, NameID, child_id, person_id, post_data):
         family_id = self.get_link(NameID).family_id
-        child = self.get_child_raw(family_id, child_id)
         self.assert_child_person_payload_in_referential(post_data)
+        child = self.get_child_raw(family_id, child_id)
 
         personList = child['authorizedPersonList']
         for i, person in enumerate(personList):
             if str(person['personInfo']['num']) == person_id:
                 personList[i] = post_data
                 personList[i]['personInfo']['num'] = person_id
                 break
         else:
diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py
index 5328b89d..0907c98f 100644
--- a/tests/test_toulouse_maelis.py
+++ b/tests/test_toulouse_maelis.py
@@ -1641,17 +1641,17 @@ def test_create_rl1_maelis_error(mocked_post, mocked_get, con, app):
     assert resp.json['err'] == 'already-rl1'
     assert 'Il existe déjà' in resp.json['err_desc']
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_update_rl1(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_RL1_FAMILY, READ_CIVILITIES, READ_QUALITIES, UPDATE_FAMILY]
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES, READ_RL1_FAMILY, UPDATE_FAMILY]
     url = get_endpoint('update-rl1')
     params = {
         'civility': 'M.',
         'firstname': 'Jhonny',
         'lastname': 'Doe',
         'quality': 'PERE',
         'birth/dateBirth': '1943-06-15',
     }
@@ -1696,17 +1696,17 @@ def test_update_rl1_connection_error(mocked_post, mocked_get, con, app):
     assert resp.json['err']
     assert resp.json['err_desc'] == 'No address associated with hostname'
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_update_rl1_wrong_referential_key_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY, READ_CIVILITIES, READ_QUALITIES]
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES]
     url = get_endpoint('update-rl1')
     params = {
         'civility': 'M.',
         'firstname': 'Jhonny',
         'lastname': 'Doe',
         'quality': 'plop',
         'birth/dateBirth': '1943-06-15',
     }
@@ -1716,17 +1716,17 @@ def test_update_rl1_wrong_referential_key_error(mocked_post, mocked_get, con, ap
     assert resp.json['err'] == 'wrong-key'
     assert resp.json['err_desc'] == "quality key value 'plop' do not belong to 'Quality' required referential"
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_create_rl2(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_RL1_FAMILY, READ_CIVILITIES, READ_QUALITIES, UPDATE_FAMILY]
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES, READ_RL1_FAMILY, UPDATE_FAMILY]
     url = get_endpoint('create-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
         'maidenName': 'Smith',
         'quality': 'MERE',
         'birth/dateBirth': '1940-06-22',
@@ -1787,17 +1787,17 @@ def test_create_rl2_connection_error(mocked_post, mocked_get, con, app):
     assert resp.json['err']
     assert resp.json['err_desc'] == 'No address associated with hostname'
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_create_rl2_already_exists_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.return_value = READ_FAMILY
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES, READ_FAMILY, READ_FAMILY]
     url = get_endpoint('create-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
         'maidenName': 'Smith',
         'quality': 'MERE',
         'birth/dateBirth': '1940-06-22',
@@ -1812,17 +1812,17 @@ def test_create_rl2_already_exists_error(mocked_post, mocked_get, con, app):
     assert resp.json['err'] == 'already-rl2'
     assert resp.json['err_desc'] == 'RL2 already defined on family'
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_create_rl2_wrong_referential_key_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_RL1_FAMILY, READ_CIVILITIES, READ_QUALITIES]
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES, READ_RL1_FAMILY]
     url = get_endpoint('create-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
         'maidenName': 'Smith',
         'quality': 'plop',
         'birth/dateBirth': '1940-06-22',
@@ -1837,17 +1837,17 @@ def test_create_rl2_wrong_referential_key_error(mocked_post, mocked_get, con, ap
     assert resp.json['err'] == 'wrong-key'
     assert resp.json['err_desc'] == "quality key value 'plop' do not belong to 'Quality' required referential"
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_update_rl2(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY, READ_CIVILITIES, READ_QUALITIES, UPDATE_FAMILY]
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES, READ_FAMILY, UPDATE_FAMILY]
     url = get_endpoint('update-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
         'maidenName': 'Smith',
         'quality': 'MERE',
         'birth/dateBirth': '1940-06-22',
@@ -1895,17 +1895,17 @@ def test_update_rl2_connection_error(mocked_post, mocked_get, con, app):
     assert resp.json['err']
     assert resp.json['err_desc'] == 'No address associated with hostname'
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_update_rl2_not_exists_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.return_value = READ_RL1_FAMILY
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES, READ_RL1_FAMILY]
     url = get_endpoint('update-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
         'maidenName': 'Smith',
         'quality': 'MERE',
         'birth/dateBirth': '1940-06-22',
@@ -1916,17 +1916,17 @@ def test_update_rl2_not_exists_error(mocked_post, mocked_get, con, app):
     assert resp.json['err'] == 'no-rl2'
     assert resp.json['err_desc'] == 'No RL2 to update on family'
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_update_rl2_wrong_referential_key_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY, READ_CIVILITIES, READ_QUALITIES]
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES]
     url = get_endpoint('update-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
         'maidenName': 'Smith',
         'quality': 'plop',
         'birth/dateBirth': '1940-06-22',
@@ -2218,17 +2218,17 @@ def test_update_coordinate_wrong_referential_key_error(mocked_post, mocked_get,
         resp.json['err_desc'] == "adresse/numComp key value 'plop' do not belong to 'Complement' referential"
     )
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_create_person(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY, READ_QUALITIES, UPDATE_FAMILY]
+    mocked_post.side_effect = [READ_QUALITIES, READ_FAMILY, UPDATE_FAMILY]
     url = get_endpoint('create-person')
     params = {
         'civility': None,
         'firstname': 'Mathias',
         'lastname': 'Cassel',
         'quality': 'O',
         'sexe': 'M',
         'dateBirth': '1972-01-01',
@@ -2298,17 +2298,17 @@ def test_create_person_not_linked_error(con, app):
     assert resp.json['err'] == 'not-linked'
     assert resp.json['err_desc'] == 'User not linked to family'
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_create_person_wrong_referential_key_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY, READ_QUALITIES, UPDATE_FAMILY]
+    mocked_post.side_effect = [READ_QUALITIES]
     url = get_endpoint('create-person')
     params = {
         'civility': None,
         'firstname': 'Mathias',
         'lastname': 'Cassel',
         'quality': 'O',
         'sexe': 'plop',
         'dateBirth': '1972-01-01',
@@ -2322,17 +2322,17 @@ def test_create_person_wrong_referential_key_error(mocked_post, mocked_get, con,
     assert resp.json['err'] == 'wrong-key'
     assert resp.json['err_desc'] == "sexe key value 'plop' do not belong to 'Sex' referential"
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_update_person(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY, READ_QUALITIES, UPDATE_FAMILY]
+    mocked_post.side_effect = [READ_QUALITIES, READ_FAMILY, UPDATE_FAMILY]
     url = get_endpoint('update-person')
     params = {
         'civility': None,
         'firstname': 'Mathias',
         'lastname': 'Cassel',
         'quality': 'O',
         'sexe': 'M',
         'dateBirth': '1972-01-01',
@@ -2365,17 +2365,17 @@ def test_update_person_not_linked_error(con, app):
     assert resp.json['err'] == 'not-linked'
     assert resp.json['err_desc'] == 'User not linked to family'
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_update_person_not_found(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY, READ_QUALITIES]
+    mocked_post.side_effect = [READ_QUALITIES, READ_FAMILY]
     url = get_endpoint('update-person')
     params = {
         'civility': None,
         'firstname': 'Mathias',
         'lastname': 'Cassel',
         'quality': 'O',
         'sexe': 'M',
         'dateBirth': '1972-01-01',
@@ -2422,17 +2422,17 @@ def test_delete_person_not_found(mocked_post, mocked_get, con, app):
     assert resp.json['err'] == 'not-found'
     assert resp.json['err_desc'] == "no '000000' authorized person on '1312' family"
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_create_child_person(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY, READ_CIVILITIES, READ_QUALITIES, UPDATE_CHILD_AUTO]
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES, READ_FAMILY, UPDATE_CHILD_AUTO]
     url = get_endpoint('create-child-person')
     params = {
         'personInfo/civility': 'MME',
         'personInfo/firstname': 'Diana',
         'personInfo/lastname': 'Ross',
         'personInfo/sexe': 'F',
         'personInfo/dateBirth': '1944-03-26',
         'personInfo/contact/phone': '0199999999',
@@ -2484,17 +2484,17 @@ def test_create_child_person_not_linked_error(con, app):
     assert resp.json['err'] == 'not-linked'
     assert resp.json['err_desc'] == 'User not linked to family'
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_create_child_person_wrong_referential_key_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY, READ_CIVILITIES]
+    mocked_post.side_effect = [READ_CIVILITIES]
     url = get_endpoint('create-child-person')
     params = {
         'personInfo/civility': 'MME',
         'personInfo/firstname': 'Diana',
         'personInfo/lastname': 'Ross',
         'personInfo/sexe': 'plop',
         'personInfo/dateBirth': '1944-03-26',
         'personInfo/contact/phone': '0199999999',
@@ -2508,17 +2508,17 @@ def test_create_child_person_wrong_referential_key_error(mocked_post, mocked_get
     assert resp.json['err'] == 'wrong-key'
     assert resp.json['err_desc'] == "personInfo/sexe key value 'plop' do not belong to 'Sex' referential"
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_create_child_person_no_child_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY]
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES, READ_FAMILY]
     url = get_endpoint('create-child-person')
     params = {
         'personInfo/civility': 'MME',
         'personInfo/firstname': 'Diana',
         'personInfo/lastname': 'Ross',
         'personInfo/sexe': 'F',
         'personInfo/dateBirth': '1944-03-26',
         'personInfo/contact/phone': '01999999999',
@@ -2532,17 +2532,17 @@ def test_create_child_person_no_child_error(mocked_post, mocked_get, con, app):
     assert resp.json['err'] == 'not-found'
     assert resp.json['err_desc'] == "no '42' child on '1312' family"
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_update_child_person(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY, READ_CIVILITIES, READ_QUALITIES, UPDATE_FAMILY]
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES, READ_FAMILY, UPDATE_FAMILY]
     url = get_endpoint('update-child-person')
     params = {
         'personInfo/civility': 'M.',
         'personInfo/firstname': 'Angelo',
         'personInfo/lastname': 'Bent',
         'personInfo/sexe': 'M',
         'personInfo/dateBirth': '1985-06-22',
         'personInfo/contact/phone': '0102030405',
@@ -2574,17 +2574,17 @@ def test_update_child_person_not_linked_error(con, app):
     assert resp.json['err'] == 'not-linked'
     assert resp.json['err_desc'] == 'User not linked to family'
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_update_child_person_wrong_referential_key_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY, READ_CIVILITIES, READ_QUALITIES, UPDATE_FAMILY]
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES]
     url = get_endpoint('update-child-person')
     params = {
         'personInfo/civility': 'M.',
         'personInfo/firstname': 'Angelo',
         'personInfo/lastname': 'Bent',
         'personInfo/sexe': 'plop',
         'personInfo/dateBirth': '1985-06-22',
         'personInfo/contact/phone': '0102030405',
@@ -2598,17 +2598,17 @@ def test_update_child_person_wrong_referential_key_error(mocked_post, mocked_get
     assert resp.json['err'] == 'wrong-key'
     assert resp.json['err_desc'] == "personInfo/sexe key value 'plop' do not belong to 'Sex' referential"
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_update_child_person_no_child_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY, READ_CIVILITIES, READ_QUALITIES, READ_QUALITIES]
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES, READ_FAMILY]
     url = get_endpoint('update-child-person')
     params = {
         'personInfo/civility': 'M.',
         'personInfo/firstname': 'Angelo',
         'personInfo/lastname': 'Bent',
         'personInfo/dateBirth': '1985-06-22',
         'personInfo/contact/phone': '0102030405',
         'personInfo/contact/mobile': None,
@@ -2621,17 +2621,17 @@ def test_update_child_person_no_child_error(mocked_post, mocked_get, con, app):
     assert resp.json['err'] == 'not-found'
     assert resp.json['err_desc'] == "no '42' child on '1312' family"
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_update_child_person_not_found(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
-    mocked_post.side_effect = [READ_FAMILY, READ_CIVILITIES, READ_QUALITIES, READ_QUALITIES]
+    mocked_post.side_effect = [READ_CIVILITIES, READ_QUALITIES, READ_FAMILY]
     url = get_endpoint('update-child-person')
     params = {
         'personInfo/civility': 'M.',
         'personInfo/firstname': 'Angelo',
         'personInfo/lastname': 'Bent',
         'personInfo/dateBirth': '1985-06-22',
         'personInfo/contact/phone': '0102030405',
         'personInfo/contact/mobile': None,
-- 
2.30.2

