From b28bd6a6a52902fc209f7803c740ded975fb8445 Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Wed, 5 Oct 2022 17:53:10 +0200
Subject: [PATCH] toulouse-maelis: manage sex field on persons (#69926)

---
 passerelle/contrib/toulouse_maelis/models.py         | 1 +
 passerelle/contrib/toulouse_maelis/schemas.py        | 4 ++++
 tests/data/toulouse_maelis/Q_create_child_person.xml | 1 +
 tests/data/toulouse_maelis/Q_create_person.xml       | 1 +
 tests/data/toulouse_maelis/Q_update_child_person.xml | 1 +
 tests/data/toulouse_maelis/Q_update_person.xml       | 1 +
 tests/test_toulouse_maelis.py                        | 9 +++++++++
 7 files changed, 18 insertions(+)

diff --git a/passerelle/contrib/toulouse_maelis/models.py b/passerelle/contrib/toulouse_maelis/models.py
index 028ce8f5..bcf0ffaa 100644
--- a/passerelle/contrib/toulouse_maelis/models.py
+++ b/passerelle/contrib/toulouse_maelis/models.py
@@ -192,16 +192,17 @@ class ToulouseMaelis(BaseResource, HTTPResource):
                 'flImage',
             ):
                 data['fsl'][key] = bool(data['fsl'][key] == 'O')
         return data
 
     def add_text_value_to_person(self, data):
         self.add_text_value('Civility', data, ['civility'])
         self.add_text_value('Quality', data, ['quality'])
+        self.add_text_value('Sex', data, ['sexe'])
 
     def add_text_value_to_rl(self, data):
         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('CSP', data, ['profession', 'codeCSP'])
 
     def add_text_value_to_family(self, data):
diff --git a/passerelle/contrib/toulouse_maelis/schemas.py b/passerelle/contrib/toulouse_maelis/schemas.py
index 9ce7d9a3..c59c9cab 100644
--- a/passerelle/contrib/toulouse_maelis/schemas.py
+++ b/passerelle/contrib/toulouse_maelis/schemas.py
@@ -552,16 +552,20 @@ FAMILYPERSON_SCHEMA = {
         'civility': {
             'description': 'civilité (depuis référenciel)',
             'oneOf': [{'type': 'null'}, {'type': 'string'}],
         },
         'quality': {
             'description': 'Qualité',
             'oneOf': [{'type': 'null'}, {'type': 'string'}],
         },
+        'sexe': {
+            'description': 'Sexe',
+            'oneOf': [{'type': 'null'}, {'type': 'string'}],
+        },
         'contact': CONTACTLIGHT_SCHEMA,
     },
     'unflatten': True,
 }
 FAMILYPERSON_SCHEMA['properties'].update(ID_PROPERTIES)
 
 AUTHORIZEDPERSON_SCHEMA = {
     '$schema': 'http://json-schema.org/draft-04/schema#',
diff --git a/tests/data/toulouse_maelis/Q_create_child_person.xml b/tests/data/toulouse_maelis/Q_create_child_person.xml
index 7ac29068..098a503a 100644
--- a/tests/data/toulouse_maelis/Q_create_child_person.xml
+++ b/tests/data/toulouse_maelis/Q_create_child_person.xml
@@ -32,16 +32,17 @@
           </personQuality>
         </personList>
         <personList>
           <personInfo>
             <civility>MME</civility>
             <lastname>Ross</lastname>
             <firstname>Diana</firstname>
             <dateBirth>1944-03-26</dateBirth>
+            <sexe>F</sexe>
             <contact>
               <phone>0199999999</phone>
               <mobile>0723456789</mobile>
               <mail>dross@example.org</mail>
             </contact>
           </personInfo>
           <personQuality>
             <code>TUTEUR</code>
diff --git a/tests/data/toulouse_maelis/Q_create_person.xml b/tests/data/toulouse_maelis/Q_create_person.xml
index 87883b58..1fd5e83f 100644
--- a/tests/data/toulouse_maelis/Q_create_person.xml
+++ b/tests/data/toulouse_maelis/Q_create_person.xml
@@ -28,16 +28,17 @@
             <mail>pueblo@example.org</mail>
           </contact>
         </personList>
         <personList>
           <civility/>
           <firstname>Mathias</firstname>
           <lastname>Cassel</lastname>
           <dateBirth>1972-01-01</dateBirth>
+          <sexe>M</sexe>
           <quality>O</quality>
           <contact>
             <phone/>
             <mobile>0623456789</mobile>
             <mail/>
           </contact>
         </personList>
       </emergencyPersonList>
diff --git a/tests/data/toulouse_maelis/Q_update_child_person.xml b/tests/data/toulouse_maelis/Q_update_child_person.xml
index 717a5a1a..4ee2bf42 100644
--- a/tests/data/toulouse_maelis/Q_update_child_person.xml
+++ b/tests/data/toulouse_maelis/Q_update_child_person.xml
@@ -14,16 +14,17 @@
         <numPerson>613880</numPerson>
         <personList>
           <personInfo>
             <num>614719</num>
             <civility>M.</civility>
             <lastname>Bent</lastname>
             <firstname>Angelo</firstname>
             <dateBirth>1985-06-22</dateBirth>
+            <sexe>M</sexe>
             <contact>
               <phone>0102030405</phone>
               <mobile/>
               <mail/>
             </contact>
           </personInfo>
           <personQuality>
             <code>O</code>
diff --git a/tests/data/toulouse_maelis/Q_update_person.xml b/tests/data/toulouse_maelis/Q_update_person.xml
index ea48b4a0..9312c7f3 100644
--- a/tests/data/toulouse_maelis/Q_update_person.xml
+++ b/tests/data/toulouse_maelis/Q_update_person.xml
@@ -17,16 +17,17 @@
       <nbChild>2</nbChild>
       <emergencyPersonList>
         <personList>
           <numPerson>614059</numPerson>
           <civility/>
           <firstname>Mathias</firstname>
           <lastname>Cassel</lastname>
           <dateBirth>1972-01-01</dateBirth>
+          <sexe>M</sexe>
           <quality>O</quality>
           <contact>
             <phone/>
             <mobile>0623456789</mobile>
             <mail/>
           </contact>
         </personList>
       </emergencyPersonList>
diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py
index 2635248e..0ddc11e1 100644
--- a/tests/test_toulouse_maelis.py
+++ b/tests/test_toulouse_maelis.py
@@ -1654,16 +1654,17 @@ 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,
         'firstname': 'Mathias',
         'lastname': 'Cassel',
         'quality': 'O',
+        'sexe': 'M',
         'dateBirth': '1972-01-01',
         'contact/phone': None,
         'contact/mobile': '0623456789',
         'contact/mail': None,
     }
 
     Link.objects.create(resource=con, family_id='1312', name_id='local')
     resp = app.post_json(url + '?NameID=local', params=params)
@@ -1673,16 +1674,17 @@ def test_create_person(mocked_post, mocked_get, con, app):
 
 def test_create_person_not_linked_error(con, app):
     url = get_endpoint('create-person')
     params = {
         'civility': None,
         'firstname': 'Mathias',
         'lastname': 'Cassel',
         'quality': 'O',
+        'sexe': 'M',
         'dateBirth': '1972-01-01',
         'contact/phone': None,
         'contact/mobile': '0623456789',
         'contact/mail': None,
     }
 
     resp = app.post_json(url + '?NameID=local', params=params)
     assert resp.json['err'] == 'not-linked'
@@ -1695,16 +1697,17 @@ def test_update_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('update-person')
     params = {
         'civility': None,
         'firstname': 'Mathias',
         'lastname': 'Cassel',
         'quality': 'O',
+        'sexe': 'M',
         'dateBirth': '1972-01-01',
         'contact/phone': None,
         'contact/mobile': '0623456789',
         'contact/mail': None,
     }
 
     Link.objects.create(resource=con, family_id='1312', name_id='local')
     resp = app.post_json(url + '?NameID=local&person_id=614059', params=params)
@@ -1714,16 +1717,17 @@ def test_update_person(mocked_post, mocked_get, con, app):
 
 def test_update_person_not_linked_error(con, app):
     url = get_endpoint('update-person')
     params = {
         'civility': None,
         'firstname': 'Mathias',
         'lastname': 'Cassel',
         'quality': 'O',
+        'sexe': 'M',
         'dateBirth': '1972-01-01',
         'contact/phone': None,
         'contact/mobile': '0623456789',
         'contact/mail': None,
     }
 
     resp = app.post_json(url + '?NameID=local&person_id=614059', params=params)
     assert resp.json['err'] == 'not-linked'
@@ -1736,16 +1740,17 @@ 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]
     url = get_endpoint('update-person')
     params = {
         'civility': None,
         'firstname': 'Mathias',
         'lastname': 'Cassel',
         'quality': 'O',
+        'sexe': 'M',
         'dateBirth': '1972-01-01',
         'contact/phone': None,
         'contact/mobile': '0623456789',
         'contact/mail': None,
     }
     Link.objects.create(resource=con, family_id='1312', name_id='local')
     resp = app.post_json(url + '?NameID=local&person_id=000000', params=params)
     assert resp.json['err'] == 'not-found'
@@ -1791,16 +1796,17 @@ def test_delete_person_not_found(mocked_post, mocked_get, con, app):
 def test_create_child_person(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
     mocked_post.side_effect = [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',
         'personInfo/contact/mobile': '0723456789',
         'personInfo/contact/mail': 'dross@example.org',
         'personQuality/code': 'TUTEUR',
     }
 
     Link.objects.create(resource=con, family_id='1312', name_id='local')
@@ -1810,16 +1816,17 @@ def test_create_child_person(mocked_post, mocked_get, con, app):
 
 
 def test_create_child_person_not_linked_error(con, app):
     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',
         'personInfo/contact/mobile': '0723456789',
         'personInfo/contact/mail': 'dross@example.org',
         'personQuality/code': 'TUTEUR',
     }
 
     resp = app.post_json(url + '?NameID=local&child_id=613880', params=params)
@@ -1832,16 +1839,17 @@ def test_create_child_person_not_linked_error(con, app):
 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]
     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',
         'personInfo/contact/mobile': '0723456789',
         'personInfo/contact/mail': 'dross@example.org',
         'personQuality/code': 'TUTEUR',
     }
 
     Link.objects.create(resource=con, family_id='1312', name_id='local')
@@ -1855,16 +1863,17 @@ def test_create_child_person_no_child_error(mocked_post, mocked_get, con, app):
 def test_update_child_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('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',
         'personInfo/contact/mobile': None,
         'personInfo/contact/mail': None,
         'personQuality/code': 'O',
     }
 
     Link.objects.create(resource=con, family_id='1312', name_id='local')
-- 
2.30.2

