From f1879d498eab8dbe35e55e865c48a4acd80ca815 Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Fri, 25 Nov 2022 15:58:36 +0100
Subject: [PATCH 1/2] toulouse-maelis: add endpoint to create or update
 quotients (#71698)

---
 functests/toulouse_maelis/conftest.py         |  1 +
 .../data/test_update_quotient.json            | 29 ++++++
 functests/toulouse_maelis/test_family.py      | 46 +++++++++
 passerelle/contrib/toulouse_maelis/models.py  | 25 +++++
 passerelle/contrib/toulouse_maelis/schemas.py | 36 +++++++
 .../Q_create_update_quotient.xml              | 23 +++++
 .../R_create_update_quotient.xml              |  5 +
 .../R_create_update_quotient_soap_error.xml   | 13 +++
 tests/data/toulouse_maelis/R_read_family.xml  | 14 +++
 .../toulouse_maelis/R_read_family_relax.xml   | 14 +++
 .../R_read_family_reordered.xml               | 14 +++
 tests/test_toulouse_maelis.py                 | 98 ++++++++++++++++++-
 12 files changed, 317 insertions(+), 1 deletion(-)
 create mode 100644 functests/toulouse_maelis/data/test_update_quotient.json
 create mode 100644 tests/data/toulouse_maelis/Q_create_update_quotient.xml
 create mode 100644 tests/data/toulouse_maelis/R_create_update_quotient.xml
 create mode 100644 tests/data/toulouse_maelis/R_create_update_quotient_soap_error.xml

diff --git a/functests/toulouse_maelis/conftest.py b/functests/toulouse_maelis/conftest.py
index 26cc3da3..b039f4a5 100644
--- a/functests/toulouse_maelis/conftest.py
+++ b/functests/toulouse_maelis/conftest.py
@@ -371,16 +371,17 @@ def create_data(request, conn, referentials):
     assert create_result['err'] == 0
     print('\ncreate DUI: %s' % str(create_result['data']['number']))
     data = diff_family(conn, name_id, 'test_create_family.json')
 
     return {
         'name_id': name_id,  # linked
         'family_id': str(create_result['data']['number']),
         'lastname': lastname,
+        'rl1_num': data['RL1']['num'],
         'family_payload': create_family_payload,
         'data': data,
     }
 
 
 @pytest.fixture(scope='session')
 def update_data(request, conn, referentials):
     name_id = request.config.getoption('--nameid')
diff --git a/functests/toulouse_maelis/data/test_update_quotient.json b/functests/toulouse_maelis/data/test_update_quotient.json
new file mode 100644
index 00000000..a257f05a
--- /dev/null
+++ b/functests/toulouse_maelis/data/test_update_quotient.json
@@ -0,0 +1,29 @@
+[
+  {
+    "yearRev": 2021,
+    "dateStart": "2022-01-02T00:00:00+01:00",
+    "dateEnd": "2022-12-31T00:00:00+01:00",
+    "mtt": 1500.33,
+    "cdquo": "QS",
+    "codeUti": null,
+    "cdquo_text": "QUOTIENT SCOLAIRE"
+  },
+  {
+    "yearRev": 2020,
+    "dateStart": "2022-01-02T00:00:00+01:00",
+    "dateEnd": "2022-12-31T00:00:00+01:00",
+    "mtt": 1500.33,
+    "cdquo": "QS",
+    "codeUti": null,
+    "cdquo_text": "QUOTIENT SCOLAIRE"
+  },
+  {
+    "yearRev": 2021,
+    "dateStart": "2022-01-01T00:00:00+01:00",
+    "dateEnd": "2022-01-01T00:00:00+01:00",
+    "mtt": 1500.33,
+    "cdquo": "QS",
+    "codeUti": null,
+    "cdquo_text": "QUOTIENT SCOLAIRE"
+  }
+]
diff --git a/functests/toulouse_maelis/test_family.py b/functests/toulouse_maelis/test_family.py
index a8e331b8..f561a1d7 100644
--- a/functests/toulouse_maelis/test_family.py
+++ b/functests/toulouse_maelis/test_family.py
@@ -747,8 +747,54 @@ def test_update_child_indicator(conn, update_data):
     assert diff_child(conn, update_data['name_id'], 0, 'test_child_indicator.json', key='indicatorList')
 
     # restore Bart indicators
     payload = {'indicatorList': update_data['family_payload']['childList'][0]['indicatorList']}
     resp = requests.post(url, json=payload)
     resp.raise_for_status()
     assert resp.json()['err'] == 0
     assert diff_family(conn, update_data['name_id'], 'test_update_family.json')
+
+
+def test_update_quotient(conn, create_data):
+    unlink(conn, create_data['name_id'])
+    link(conn, create_data)
+
+    # add quotient
+    url = conn + '/update-quotient?NameID=%s&rl_id=%s' % (create_data['name_id'], create_data['rl1_num'])
+    payload = {
+        'yearRev': '2021',
+        'dateStart': '2022-01-01',
+        'dateEnd': '2022-12-31',
+        'mtt': '1500.33',
+        'cdquo': 'QS',
+    }
+    resp = requests.post(url, json=payload)
+    resp.raise_for_status()
+    assert resp.json()['err'] == 0
+    data = read_family(conn, create_data['name_id'])
+    assert data['RL1']['quotientList'] == [
+        {
+            'yearRev': 2021,
+            'dateStart': '2022-01-01T00:00:00+01:00',
+            'dateEnd': '2022-12-31T00:00:00+01:00',
+            'mtt': 1500.33,
+            'cdquo': 'QS',
+            'codeUti': None,
+            'cdquo_text': 'QUOTIENT SCOLAIRE',
+        }
+    ]
+
+    # add quotient
+    payload['dateStart'] = '2022-01-02'
+    resp = requests.post(url, json=payload)
+    resp.raise_for_status()
+    assert resp.json()['err'] == 0
+    data = read_family(conn, create_data['name_id'])
+    assert len(data['RL1']['quotientList']) == 2
+
+    # add quotient on another income year
+    payload['yearRev'] = '2020'
+    resp = requests.post(url, json=payload)
+    resp.raise_for_status()
+    assert resp.json()['err'] == 0
+    data = diff_rlg(conn, create_data['name_id'], 1, 'test_update_quotient.json', 'quotientList')
+    assert len(data['RL1']['quotientList']) == 3
diff --git a/passerelle/contrib/toulouse_maelis/models.py b/passerelle/contrib/toulouse_maelis/models.py
index b44e60b9..68a95203 100644
--- a/passerelle/contrib/toulouse_maelis/models.py
+++ b/passerelle/contrib/toulouse_maelis/models.py
@@ -270,16 +270,18 @@ class ToulouseMaelis(BaseResource, HTTPResource):
         self.add_text_value('Civility', data, ['civility'])
         self.add_text_value('Quality', data, ['quality'])
         self.add_text_value('Complement', data, ['adresse', 'numComp'])
         self.add_text_value('Street', data, ['adresse', 'idStreet'])
         self.add_text_value('CSP', data, ['profession', 'codeCSP'])
         self.add_text_value('Organ', data, ['CAFInfo', 'organ'])
         for indicator in data['indicatorList']:
             self.add_text_value_to_rl_indicator(indicator)
+        for quotient in data['quotientList']:
+            self.add_text_value('Quotient', quotient, ['cdquo'])
 
         # sort indicators
         if data['indicatorList']:
             data['indicatorList'].sort(key=lambda x: x['code'])
 
     def add_text_value_to_family(self, data):
         self.add_text_value('Category', data, ['category'])
         self.add_text_value('Situation', data, ['situation'])
@@ -1081,16 +1083,39 @@ class ToulouseMaelis(BaseResource, HTTPResource):
     )
     def update_rl_indicator(self, request, NameID, rl_id, post_data):
         self.get_link(NameID)
         self.assert_update_indicator_payload_in_referential('RLIndicator', post_data)
 
         self.call('Family', 'updatePersonIndicatorList', numPerson=rl_id, **post_data)
         return {'data': 'ok'}
 
+    @endpoint(
+        display_category='Famille',
+        description="Créer ou mettre à jour un quotient d'un responsable légal",
+        name='update-quotient',
+        perm='can_access',
+        parameters={
+            'NameID': {'description': 'Publik NameID'},
+            'rl_id': {'description': "Numéro du responsable légal"},
+        },
+        post={'request_body': {'schema': {'application/json': schemas.UPDATE_QUOTIENT_SCHEMA}}},
+    )
+    def update_quotient(self, request, NameID, rl_id, post_data):
+        family_id = self.get_link(NameID).family_id
+        self.assert_post_data_in_referential('Quotient', post_data, ['cdquo'])
+
+        payload = {
+            'dossierNumber': family_id,
+            'personNumber': rl_id,
+            'quotient': post_data,
+        }
+        self.call('Family', 'createUpdateQuotient', **payload)
+        return {'data': 'ok'}
+
     @endpoint(
         display_category='Famille',
         description="Création d'une personne à prévenir en cas d'urgence",
         name='create-person',
         perm='can_access',
         parameters={
             'NameID': {'description': 'Publik NameID'},
         },
diff --git a/passerelle/contrib/toulouse_maelis/schemas.py b/passerelle/contrib/toulouse_maelis/schemas.py
index d6573420..03854375 100644
--- a/passerelle/contrib/toulouse_maelis/schemas.py
+++ b/passerelle/contrib/toulouse_maelis/schemas.py
@@ -715,8 +715,44 @@ UPDATE_INDICATOR_SCHEMA = {
             'type': 'array',
             'items': INDICATOR_SCHEMA,
             'minItems': 1,
         }
     },
     'additionalProperties': False,
     'unflatten': True,
 }
+
+UPDATE_QUOTIENT_SCHEMA = {
+    '$schema': 'http://json-schema.org/draft-04/schema#',
+    'title': 'Family persons',
+    'description': "Mise à jours des quotients sur les responsables légaux",
+    'type': 'object',
+    'required': ['yearRev', 'dateStart', 'dateEnd', 'mtt', 'cdquo'],
+    'properties': {
+        'yearRev': {
+            'description': 'Année de revenu',
+            'type': 'string',
+            'pattern': '^[0-9]{4}$',
+        },
+        'dateStart': {
+            'description': 'Date de début',
+            'type': 'string',
+            'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
+        },
+        'dateEnd': {
+            'description': 'Date de fin',
+            'type': 'string',
+            'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
+        },
+        'mtt': {
+            'description': 'Montant',
+            'type': 'string',
+            'pattern': r'^[0-9]+\.?[0-9]*$',
+        },
+        'cdquo': {
+            'description': 'Code du quotient (depuis référentiel)',
+            'type': 'string',
+            'pattern': '.+',
+        },
+    },
+    'additionalProperties': False,
+}
diff --git a/tests/data/toulouse_maelis/Q_create_update_quotient.xml b/tests/data/toulouse_maelis/Q_create_update_quotient.xml
new file mode 100644
index 00000000..0d519a11
--- /dev/null
+++ b/tests/data/toulouse_maelis/Q_create_update_quotient.xml
@@ -0,0 +1,23 @@
+<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
+  <soap-env:Header>
+    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+      <wsse:UsernameToken>
+        <wsse:Username>maelis-webservice</wsse:Username>
+        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password>
+      </wsse:UsernameToken>
+    </wsse:Security>
+  </soap-env:Header>
+  <soap-env:Body>
+    <ns0:createUpdateQuotient xmlns:ns0="family.ws.maelis.sigec.com">
+      <dossierNumber>1312</dossierNumber>
+      <personNumber>613878</personNumber>
+      <quotient>
+        <yearRev>2021</yearRev>
+        <dateStart>2022-10-01</dateStart>
+        <dateEnd>2023-01-31</dateEnd>
+        <mtt>1500.33</mtt>
+        <cdquo>QS</cdquo>
+      </quotient>
+    </ns0:createUpdateQuotient>
+  </soap-env:Body>
+</soap-env:Envelope>
diff --git a/tests/data/toulouse_maelis/R_create_update_quotient.xml b/tests/data/toulouse_maelis/R_create_update_quotient.xml
new file mode 100644
index 00000000..76428f17
--- /dev/null
+++ b/tests/data/toulouse_maelis/R_create_update_quotient.xml
@@ -0,0 +1,5 @@
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+  <soap:Body>
+    <ns2:createUpdateQuotientResponse xmlns:ns2="family.ws.maelis.sigec.com"/>
+  </soap:Body>
+</soap:Envelope>
diff --git a/tests/data/toulouse_maelis/R_create_update_quotient_soap_error.xml b/tests/data/toulouse_maelis/R_create_update_quotient_soap_error.xml
new file mode 100644
index 00000000..1e86f858
--- /dev/null
+++ b/tests/data/toulouse_maelis/R_create_update_quotient_soap_error.xml
@@ -0,0 +1,13 @@
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+  <soap:Body>
+    <soap:Fault>
+      <faultcode>soap:Server</faultcode>
+      <faultstring>E07 : Il existe d&#233;j&#224; un quotient post&#233;rieur pour cette p&#233;riode</faultstring>
+      <detail>
+        <ns1:MaelisFamilyException xmlns:ns1="family.ws.maelis.sigec.com">
+          <message xmlns:ns2="family.ws.maelis.sigec.com">E07 : Il existe d&#233;j&#224; un quotient post&#233;rieur pour cette p&#233;riode</message>
+        </ns1:MaelisFamilyException>
+      </detail>
+    </soap:Fault>
+  </soap:Body>
+</soap:Envelope>
diff --git a/tests/data/toulouse_maelis/R_read_family.xml b/tests/data/toulouse_maelis/R_read_family.xml
index 705a02cc..b23d33cd 100644
--- a/tests/data/toulouse_maelis/R_read_family.xml
+++ b/tests/data/toulouse_maelis/R_read_family.xml
@@ -40,16 +40,30 @@
             <code>ETABSPEC</code>
             <label>Etablissement sp&#233;cialis&#233;</label>
             <note>SNPP</note>
           </indicatorList>
           <indicatorList>
             <code>AVL</code>
             <label>Auxiliaire de Vie loisirs</label>
           </indicatorList>
+          <quotientList>
+            <yearRev>2020</yearRev>
+            <dateStart>2021-01-01T00:00:00+01:00</dateStart>
+            <dateEnd>2021-12-31T00:00:00+01:00</dateEnd>
+            <mtt>1500.33</mtt>
+            <cdquo>QS</cdquo>
+          </quotientList>
+          <quotientList>
+            <yearRev>2021</yearRev>
+            <dateStart>2022-01-01T00:00:00+01:00</dateStart>
+            <dateEnd>2022-12-31T00:00:00+01:00</dateEnd>
+            <mtt>1500.44</mtt>
+            <cdquo>MOY ECO</cdquo>
+          </quotientList>
         </RL1>
         <RL2>
           <num>613879</num>
           <lastname>DOE</lastname>
           <firstname>JANE</firstname>
           <maidenName>SMITH</maidenName>
           <quality>MERE</quality>
           <civility>MME</civility>
diff --git a/tests/data/toulouse_maelis/R_read_family_relax.xml b/tests/data/toulouse_maelis/R_read_family_relax.xml
index 1463719e..37f9e649 100644
--- a/tests/data/toulouse_maelis/R_read_family_relax.xml
+++ b/tests/data/toulouse_maelis/R_read_family_relax.xml
@@ -40,16 +40,30 @@
             <code>ETABSPEC</code>
             <label>Etablissement sp&#233;cialis&#233;</label>
             <note>SNPP</note>
           </indicatorList>
           <indicatorList>
             <code>AVL</code>
             <label>Auxiliaire de Vie loisirs</label>
           </indicatorList>
+          <quotientList>
+            <yearRev>2020</yearRev>
+            <dateStart>2021-01-01T00:00:00+01:00</dateStart>
+            <dateEnd>2021-12-31T00:00:00+01:00</dateEnd>
+            <mtt>1500.33</mtt>
+            <cdquo>QS</cdquo>
+          </quotientList>
+          <quotientList>
+            <yearRev>2021</yearRev>
+            <dateStart>2022-01-01T00:00:00+01:00</dateStart>
+            <dateEnd>2022-12-31T00:00:00+01:00</dateEnd>
+            <mtt>1500.44</mtt>
+            <cdquo>MOY ECO</cdquo>
+          </quotientList>
         </RL1>
         <RL2>
           <num>613879</num>
           <lastname>DOE</lastname>
           <firstname>JANE</firstname>
           <maidenName>SMITH</maidenName>
           <quality>MERE</quality>
           <civility>MME</civility>
diff --git a/tests/data/toulouse_maelis/R_read_family_reordered.xml b/tests/data/toulouse_maelis/R_read_family_reordered.xml
index c4318ba7..8186cc29 100644
--- a/tests/data/toulouse_maelis/R_read_family_reordered.xml
+++ b/tests/data/toulouse_maelis/R_read_family_reordered.xml
@@ -40,16 +40,30 @@
             <code>ETABSPEC</code>
             <label>Etablissement sp&#233;cialis&#233;</label>
             <note>SNPP</note>
           </indicatorList>
           <indicatorList>
             <code>AVL</code>
             <label>Auxiliaire de Vie loisirs</label>
           </indicatorList>
+          <quotientList>
+            <yearRev>2020</yearRev>
+            <dateStart>2021-01-01T00:00:00+01:00</dateStart>
+            <dateEnd>2021-12-31T00:00:00+01:00</dateEnd>
+            <mtt>1500.33</mtt>
+            <cdquo>QS</cdquo>
+          </quotientList>
+          <quotientList>
+            <yearRev>2021</yearRev>
+            <dateStart>2022-01-01T00:00:00+01:00</dateStart>
+            <dateEnd>2022-12-31T00:00:00+01:00</dateEnd>
+            <mtt>1500.44</mtt>
+            <cdquo>MOY ECO</cdquo>
+          </quotientList>
         </RL1>
         <RL2>
           <num>613879</num>
           <lastname>DOE</lastname>
           <firstname>JANE</firstname>
           <maidenName>SMITH</maidenName>
           <quality>MERE</quality>
           <civility>MME</civility>
diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py
index 773af074..b37ecc2c 100644
--- a/tests/test_toulouse_maelis.py
+++ b/tests/test_toulouse_maelis.py
@@ -53,16 +53,20 @@ IS_CHILD_EXISTS_FALSE = FakedResponse(
 )
 CREATE_FAMILY = FakedResponse(content=get_xml_file('R_create_family.xml'), status_code=200)
 CREATE_FAMILY_ERR = FakedResponse(content=get_xml_file('R_create_family_error.xml'), status_code=200)
 CREATE_CHILD = FakedResponse(content=get_xml_file('R_create_child.xml'), status_code=200)
 CREATE_CHILD_ERR = FakedResponse(content=get_xml_file('R_create_child_error.xml'), status_code=200)
 UPDATE_FAMILY = FakedResponse(content=get_xml_file('R_update_family.xml'), status_code=200)
 UPDATE_FAMILY_ERR = FakedResponse(content=get_xml_file('R_update_family_error.xml'), status_code=200)
 UPDATE_FAMILY_500 = FakedResponse(content=get_xml_file('R_update_family_soap_error.xml'), status_code=500)
+UPDATE_QUOTIENT = FakedResponse(content=get_xml_file('R_create_update_quotient.xml'), status_code=200)
+UPDATE_QUOTIENT_500 = FakedResponse(
+    content=get_xml_file('R_create_update_quotient_soap_error.xml'), status_code=500
+)
 UPDATE_DIETCODE = FakedResponse(content=get_xml_file('R_update_child_dietcode.xml'), status_code=200)
 UPDATE_PAI = FakedResponse(content=get_xml_file('R_update_child_pai.xml'), status_code=200)
 UPDATE_PAI_500 = FakedResponse(content=get_xml_file('R_update_child_pai_soap_error.xml'), status_code=500)
 UPDATE_MEDICAL = FakedResponse(content=get_xml_file('R_update_child_medical_record.xml'), status_code=200)
 UPDATE_MEDICAL_500 = FakedResponse(
     content=get_xml_file('R_update_child_medical_record_soap_error.xml'), status_code=500
 )
 UPDATE_CHILD_AUTO = FakedResponse(content=get_xml_file('R_update_child_authorization.xml'), status_code=200)
@@ -700,33 +704,52 @@ def test_read_family(mocked_post, mocked_get, read_family, con, app):
             'mail': 'djhon@example.org',
             'isContactMail': True,
             'isContactSms': True,
             'isInvoicePdf': True,
         },
         'CAFInfo': None,
         'civility_text': 'Monsieur',
         'quality_text': 'PERE',
-        'quotientList': [],
         'indicatorList': [
             {
                 'choice': None,
                 'code': 'AVL',
                 'code_text': 'Auxiliaire de Vie loisirs',
                 'label': 'Auxiliaire de Vie loisirs',
                 'note': None,
             },
             {
                 'choice': None,
                 'code': 'ETABSPEC',
                 'code_text': 'Etablissement spécialisé',
                 'label': 'Etablissement spécialisé',
                 'note': 'SNPP',
             },
         ],
+        'quotientList': [
+            {
+                'cdquo': 'QS',
+                'cdquo_text': 'QUOTIENT SCOLAIRE',
+                'codeUti': None,
+                'dateEnd': '2021-12-31T00:00:00+01:00',
+                'dateStart': '2021-01-01T00:00:00+01:00',
+                'mtt': 1500.33,
+                'yearRev': 2020,
+            },
+            {
+                'cdquo': 'MOY ECO',
+                'cdquo_text': 'REVENU MOYEN ( MENSUEL OU ANNUEL)',
+                'codeUti': None,
+                'dateEnd': '2022-12-31T00:00:00+01:00',
+                'dateStart': '2022-01-01T00:00:00+01:00',
+                'mtt': 1500.44,
+                'yearRev': 2021,
+            },
+        ],
         'subscribeActivityList': [],
     }
     data = resp.json['data']['childList'][0]
     del data['medicalRecord']
     del data['authorizedPersonList']
     del data['paiInfoBean']
     del data['indicatorList']
     assert data == {
@@ -2106,16 +2129,89 @@ def test_update_coordinate_wrong_referential_key_error(mocked_post, mocked_get,
     Link.objects.create(resource=con, family_id='1312', name_id='local')
     resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
     assert resp.json['err'] == 'wrong-key'
     assert (
         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_update_quotient(mocked_post, mocked_get, con, app):
+    mocked_get.return_value = FAMILY_SERVICE_WSDL
+    mocked_post.return_value = UPDATE_QUOTIENT
+    url = get_endpoint('update-quotient')
+    params = {
+        'yearRev': '2021',
+        'dateStart': '2022-10-01',
+        'dateEnd': '2023-01-31',
+        'mtt': '1500.33',
+        'cdquo': 'QS',
+    }
+
+    Link.objects.create(resource=con, family_id='1312', name_id='local')
+    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
+    assert_sent_payload(mocked_post, 'Q_create_update_quotient.xml')
+    assert resp.json['err'] == 0
+    assert resp.json['data'] == 'ok'
+
+
+def test_update_quotient_schema_error(con, app):
+    url = get_endpoint('update-quotient')
+    params = {
+        'yearRev': '2021',
+        'dateStart': '2022-10-01',
+        'dateEnd': '2023-01-31',
+        'mtt': '1500,33',
+        'cdquo': 'QS',
+    }
+
+    Link.objects.create(resource=con, family_id='1312', name_id='local')
+    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params, status=400)
+    assert resp.json['err'] == 1
+    assert resp.json['err_desc'] == "mtt: '1500,33' does not match '^[0-9]+\\\\.?[0-9]*$'"
+
+
+@mock.patch('passerelle.utils.Request.get')
+@mock.patch('passerelle.utils.Request.post')
+def test_update_quotient_soap_error(mocked_post, mocked_get, con, app):
+    mocked_get.return_value = FAMILY_SERVICE_WSDL
+    mocked_post.return_value = UPDATE_QUOTIENT_500
+    url = get_endpoint('update-quotient')
+    params = {
+        'yearRev': '2021',
+        'dateStart': '2022-10-01',
+        'dateEnd': '2023-01-31',
+        'mtt': '1500.33',
+        'cdquo': 'QS',
+    }
+
+    Link.objects.create(resource=con, family_id='1312', name_id='local')
+    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
+    assert resp.json['err'] == 'Family-createUpdateQuotient-soap:Server'
+    assert 'E07 : Il existe déjà un quotient postérieur' in resp.json['err_desc']
+
+
+def test_update_quotient_wrong_referential_key_error(con, app):
+    url = get_endpoint('update-quotient')
+    params = {
+        'yearRev': '2021',
+        'dateStart': '2023-10-01',
+        'dateEnd': '2023-01-31',
+        'mtt': '1500.33',
+        'cdquo': 'plop',
+    }
+
+    Link.objects.create(resource=con, family_id='1312', name_id='local')
+    resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
+    assert resp.json['err'] == 'wrong-key'
+    assert resp.json['err_desc'] == "cdquo key value 'plop' do not belong to 'Quotient' required 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, UPDATE_FAMILY]
     url = get_endpoint('create-person')
     params = {
         'civility': None,
-- 
2.30.2

