From f76b14b4112ad54b47a43ae74ed87993be3f0c4f Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Sun, 20 Nov 2022 20:23:13 +0100
Subject: [PATCH 1/5] toulouse-maelis: add maidenName to RL json schema
 (#71642)

---
 passerelle/contrib/toulouse_maelis/schemas.py |  4 ++++
 tests/data/toulouse_maelis/Q_create_rl2.xml   |  1 +
 tests/data/toulouse_maelis/Q_update_rl2.xml   |  1 +
 tests/data/toulouse_maelis/R_read_family.xml  |  1 +
 tests/test_toulouse_maelis.py                 | 12 +++++++++++-
 5 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/passerelle/contrib/toulouse_maelis/schemas.py b/passerelle/contrib/toulouse_maelis/schemas.py
index 98e25be8..c677dd57 100644
--- a/passerelle/contrib/toulouse_maelis/schemas.py
+++ b/passerelle/contrib/toulouse_maelis/schemas.py
@@ -97,16 +97,20 @@ ID_PROPERTIES = {
     'firstname': {
         'description': 'Prénom',
         'type': 'string',
     },
     'lastname': {
         'description': 'Nom',
         'type': 'string',
     },
+    'maidenName': {
+        'description': "Nom de jeune fille ",
+        'oneOf': [{'type': 'string'}, {'type': 'null'}],
+    },
     'birth': BIRTH_SCHEMA,
 }
 
 ADDRESS_SCHEMA = {
     '$schema': 'http://json-schema.org/draft-04/schema#',
     'title': 'Address',
     'description': 'Informations sur une adresse',
     'type': 'object',
diff --git a/tests/data/toulouse_maelis/Q_create_rl2.xml b/tests/data/toulouse_maelis/Q_create_rl2.xml
index 63a71405..076ce6a2 100644
--- a/tests/data/toulouse_maelis/Q_create_rl2.xml
+++ b/tests/data/toulouse_maelis/Q_create_rl2.xml
@@ -12,16 +12,17 @@
       <dossierNumber>1312</dossierNumber>
       <category>BI</category>
       <situation>M</situation>
       <flagCom>true</flagCom>
       <nbChild>2</nbChild>
       <rl2>
         <firstname>JANE</firstname>
         <lastname>DOE</lastname>
+        <maidenName>Smith</maidenName>
         <quality>MERE</quality>
         <civility>MME</civility>
         <birth>
           <dateBirth>1940-06-22</dateBirth>
         </birth>
         <adresse>
           <num>170</num>
           <street1>Chateau d'eau</street1>
diff --git a/tests/data/toulouse_maelis/Q_update_rl2.xml b/tests/data/toulouse_maelis/Q_update_rl2.xml
index 02ad1d47..f75e5a94 100644
--- a/tests/data/toulouse_maelis/Q_update_rl2.xml
+++ b/tests/data/toulouse_maelis/Q_update_rl2.xml
@@ -13,16 +13,17 @@
       <category>BI</category>
       <situation>M</situation>
       <flagCom>true</flagCom>
       <nbChild>2</nbChild>
       <rl2>
         <num>613879</num>
         <firstname>JANE</firstname>
         <lastname>DOE</lastname>
+        <maidenName>Smith</maidenName>
         <quality>MERE</quality>
         <civility>MME</civility>
         <birth>
           <dateBirth>1940-06-22</dateBirth>
         </birth>
         <adresse>
           <num>170</num>
           <street1>Chateau d'eau</street1>
diff --git a/tests/data/toulouse_maelis/R_read_family.xml b/tests/data/toulouse_maelis/R_read_family.xml
index 73887dd0..cc9c3c68 100644
--- a/tests/data/toulouse_maelis/R_read_family.xml
+++ b/tests/data/toulouse_maelis/R_read_family.xml
@@ -36,16 +36,17 @@
           <profession>
             <addressPro/>
           </profession>
         </RL1>
         <RL2>
           <num>613879</num>
           <lastname>DOE</lastname>
           <firstname>JANE</firstname>
+          <maidenName>SMITH</maidenName>
           <quality>MERE</quality>
           <civility>MME</civility>
           <birth>
             <dateBirth>1940-06-22T00:00:00+02:00</dateBirth>
             <place>Bardot</place>
             <countryCode>99351</countryCode>
           </birth>
           <adresse>
diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py
index ba49bae6..f2da53a5 100644
--- a/tests/test_toulouse_maelis.py
+++ b/tests/test_toulouse_maelis.py
@@ -765,17 +765,17 @@ def test_read_rl2(mocked_post, mocked_get, con, app):
     Link.objects.create(resource=con, family_id='1312', name_id='local')
 
     resp = app.get(url + '?NameID=local&rl_id=613879')
     assert resp.json['err'] == 0
     assert resp.json['data'] == {
         'num': '613879',
         'lastname': 'DOE',
         'firstname': 'JANE',
-        'maidenName': None,
+        'maidenName': 'SMITH',
         'quality': 'MERE',
         'civility': 'MME',
         'birth': {
             'communeCode': None,
             'countryCode': '99351',
             'dateBirth': '1940-06-22T00:00:00+02:00',
             'place': 'Bardot',
         },
@@ -1619,16 +1619,17 @@ def test_update_rl1_wrong_referential_key_error(mocked_post, mocked_get, con, ap
 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]
     url = get_endpoint('create-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
+        'maidenName': 'Smith',
         'quality': 'MERE',
         'birth/dateBirth': '1940-06-22',
         'adresse/num': '170',
         'adresse/street1': "Chateau d'eau",
         'adresse/town': 'Paris',
         'adresse/zipcode': '75014',
     }
 
@@ -1640,16 +1641,17 @@ def test_create_rl2(mocked_post, mocked_get, con, app):
 
 
 def test_create_rl2_not_linked_error(con, app):
     url = get_endpoint('create-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
+        'maidenName': 'Smith',
         'quality': 'MERE',
         'birth/dateBirth': '1940-06-22',
         'adresse/num': '170',
         'adresse/street1': "Chateau d'eau",
         'adresse/town': 'Paris',
         'adresse/zipcode': '75014',
     }
 
@@ -1663,16 +1665,17 @@ def test_create_rl2_not_linked_error(con, app):
 def test_create_rl2_connection_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
     mocked_post.side_effect = CONNECTION_ERROR
     url = get_endpoint('create-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
+        'maidenName': 'Smith',
         'quality': 'MERE',
         'birth/dateBirth': '1940-06-22',
         'adresse/num': '170',
         'adresse/street1': "Chateau d'eau",
         'adresse/town': 'Paris',
         'adresse/zipcode': '75014',
     }
 
@@ -1687,16 +1690,17 @@ def test_create_rl2_connection_error(mocked_post, mocked_get, con, app):
 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
     url = get_endpoint('create-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
+        'maidenName': 'Smith',
         'quality': 'MERE',
         'birth/dateBirth': '1940-06-22',
         'adresse/num': '170',
         'adresse/street1': "Chateau d'eau",
         'adresse/town': 'Paris',
         'adresse/zipcode': '75014',
     }
 
@@ -1711,16 +1715,17 @@ def test_create_rl2_already_exists_error(mocked_post, mocked_get, con, app):
 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]
     url = get_endpoint('create-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
+        'maidenName': 'Smith',
         'quality': 'plop',
         'birth/dateBirth': '1940-06-22',
         'adresse/num': '170',
         'adresse/street1': "Chateau d'eau",
         'adresse/town': 'Paris',
         'adresse/zipcode': '75014',
     }
 
@@ -1735,16 +1740,17 @@ def test_create_rl2_wrong_referential_key_error(mocked_post, mocked_get, con, ap
 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]
     url = get_endpoint('update-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
+        'maidenName': 'Smith',
         'quality': 'MERE',
         'birth/dateBirth': '1940-06-22',
     }
 
     Link.objects.create(resource=con, family_id='1312', name_id='local')
     resp = app.post_json(url + '?NameID=local', params=params)
     assert_sent_payload(mocked_post, 'Q_update_rl2.xml')
     assert resp.json['err'] == 0
@@ -1752,16 +1758,17 @@ def test_update_rl2(mocked_post, mocked_get, con, app):
 
 def test_update_rl2_not_linked_error(con, app):
     url = get_endpoint('update-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
         'quality': 'MERE',
+        'maidenName': 'Smith',
         'birth/dateBirth': '1940-06-22',
     }
 
     resp = app.post_json(url + '?NameID=local', params=params)
     assert resp.json['err'] == 'not-linked'
     assert resp.json['err_desc'] == 'User not linked to family'
 
 
@@ -1770,16 +1777,17 @@ def test_update_rl2_not_linked_error(con, app):
 def test_update_rl2_connection_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
     mocked_post.side_effect = CONNECTION_ERROR
     url = get_endpoint('update-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
+        'maidenName': 'Smith',
         'quality': 'MERE',
         'birth/dateBirth': '1940-06-22',
     }
 
     Link.objects.create(resource=con, family_id='1312', name_id='local')
     resp = app.post_json(url + '?NameID=local', params=params, status=500)
     assert resp.json['err']
     assert resp.json['err_desc'] == 'No address associated with hostname'
@@ -1790,16 +1798,17 @@ def test_update_rl2_connection_error(mocked_post, mocked_get, con, app):
 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
     url = get_endpoint('update-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
+        'maidenName': 'Smith',
         'quality': 'MERE',
         'birth/dateBirth': '1940-06-22',
     }
 
     Link.objects.create(resource=con, family_id='1312', name_id='local')
     resp = app.post_json(url + '?NameID=local', params=params)
     assert resp.json['err'] == 'no-rl2'
     assert resp.json['err_desc'] == 'No RL2 to update on family'
@@ -1810,16 +1819,17 @@ def test_update_rl2_not_exists_error(mocked_post, mocked_get, con, app):
 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]
     url = get_endpoint('update-rl2')
     params = {
         'civility': 'MME',
         'firstname': 'JANE',
         'lastname': 'DOE',
+        'maidenName': 'Smith',
         'quality': 'plop',
         'birth/dateBirth': '1940-06-22',
     }
 
     Link.objects.create(resource=con, family_id='1312', name_id='local')
     resp = app.post_json(url + '?NameID=local', params=params)
     assert resp.json['err'] == 'wrong-key'
     assert resp.json['err_desc'] == "quality key value 'plop' do not belong to 'Quality' required referential"
-- 
2.30.2

