From 6545cebbd4d409cef859e6aaed8f40913d4ec01d Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Sun, 17 Jul 2022 17:20:38 +0200
Subject: [PATCH 2/5] toulouse_maelis: adapt payloads on RL tests (#67326)

---
 tests/test_toulouse_maelis.py | 130 +++++++++++++---------------------
 1 file changed, 51 insertions(+), 79 deletions(-)

diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py
index 489659d0..52aac00d 100644
--- a/tests/test_toulouse_maelis.py
+++ b/tests/test_toulouse_maelis.py
@@ -573,29 +573,25 @@ def test_is_rl_exists_schema_error(con, app):
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_create_family(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
     mocked_post.return_value = CREATE_FAMILY
     url = get_endpoint('create-family')
     params = {
-        'rl1/adresse': {
-            'street1': 'Chateau',
-            'town': 'Paris',
-            'zipcode': '75014',
-        },
-        'rl1': {
-            'firstname': 'Jhon',
-            'lastname': 'Doe',
-            'quality': 'AU',
-            'dateBirth': '1938-07-26',
-        },
         'categorie': 'ACCEUI',
         'situation': 'C',
+        'rl1/firstname': 'Jhon',
+        'rl1/lastname': 'Doe',
+        'rl1/quality': 'AU',
+        'rl1/dateBirth': '1938-07-26',
+        'rl1/adresse/street1': 'Chateau',
+        'rl1/adresse/town': 'Paris',
+        'rl1/adresse/zipcode': '75014',
     }
 
     resp = app.post_json(url + '?NameID=local', params=params)
     assert_sent_payload(mocked_post, 'Q_create_family.xml')
     assert resp.json['err'] == 0
     assert resp.json['data'] == {
         'number': 196545,
         'password': '394634V2',
@@ -603,171 +599,147 @@ def test_create_family(mocked_post, mocked_get, con, app):
         'childErrorList': [],
     }
     assert Link.objects.get(resource=con, family_id='196545', name_id='local')
 
 
 def test_create_family_already_linked_error(con, app):
     url = get_endpoint('create-family')
     params = {
-        'rl1/adresse': {
-            'street1': 'Chateau',
-            'town': 'Paris',
-            'zipcode': '75014',
-        },
-        'rl1': {
-            'firstname': 'Jhon',
-            'lastname': 'Doe',
-            'quality': 'AU',
-            'dateBirth': '1938-07-26',
-        },
         'categorie': 'ACCEUI',
         'situation': 'C',
+        'rl1/firstname': 'Jhon',
+        'rl1/lastname': 'Doe',
+        'rl1/quality': 'AU',
+        'rl1/dateBirth': '1938-07-26',
+        'rl1/adresse/street1': 'Chateau',
+        'rl1/adresse/town': 'Paris',
+        'rl1/adresse/zipcode': '75014',
     }
 
     Link.objects.create(resource=con, family_id='1312', name_id='local')
     resp = app.post_json(url + '?NameID=local', params=params)
     assert resp.json['err'] == 'already-linked'
     assert resp.json['err_desc'] == 'User already linked to family'
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_create_family_maelis_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
     mocked_post.return_value = CREATE_FAMILY_ERR
     url = get_endpoint('create-family')
     params = {
-        'rl1/adresse': {
-            'street1': 'Chateau',
-            'town': 'Paris',
-            'zipcode': '75014',
-        },
-        'rl1': {
-            'firstname': 'Jhon',
-            'lastname': 'Doe',
-            'quality': 'AU',
-            'dateBirth': '1938-07-26',
-        },
         'categorie': 'ACCEUI',
         'situation': 'C',
+        'rl1/firstname': 'Jhon',
+        'rl1/lastname': 'Doe',
+        'rl1/quality': 'AU',
+        'rl1/dateBirth': '1938-07-26',
+        'rl1/adresse/street1': 'Chateau',
+        'rl1/adresse/town': 'Paris',
+        'rl1/adresse/zipcode': '75014',
     }
 
     resp = app.post_json(url + '?NameID=local', params=params)
     assert resp.json['err'] == 'E54a'
     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_family(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
     mocked_post.return_value = UPDATE_FAMILY
     url = get_endpoint('update-family')
     params = {
-        'rl1/adresse': {
-            'street1': 'Chateau',
-            'town': 'Paris',
-            'zipcode': '75014',
-        },
-        'rl1': {
-            'firstname': 'Jhon',
-            'lastname': 'Doe',
-            'quality': 'AU',
-            'dateBirth': '1938-07-26',
-        },
         'categorie': 'BI',
         'situation': 'C',
+        'rl1/firstname': 'Jhon',
+        'rl1/lastname': 'Doe',
+        'rl1/quality': 'AU',
+        'rl1/dateBirth': '1938-07-26',
+        'rl1/adresse/street1': 'Chateau',
+        'rl1/adresse/town': 'Paris',
+        'rl1/adresse/zipcode': '75014',
     }
 
     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_family.xml')
     assert resp.json['err'] == 0
 
 
 def test_update_family_already_not_linked_error(con, app):
     url = get_endpoint('update-family')
     params = {
-        'rl1/adresse': {
-            'street1': 'Chateau',
-            'town': 'Paris',
-            'zipcode': '75014',
-        },
-        'rl1': {
-            'firstname': 'Jhon',
-            'lastname': 'Doe',
-            'quality': 'AU',
-            'dateBirth': '1938-07-26',
-        },
-        'categorie': 'ACCEUI',
+        'categorie': 'BI',
         'situation': 'C',
+        'rl1/firstname': 'Jhon',
+        'rl1/lastname': 'Doe',
+        'rl1/quality': 'AU',
+        'rl1/dateBirth': '1938-07-26',
+        'rl1/adresse/street1': 'Chateau',
+        'rl1/adresse/town': 'Paris',
+        'rl1/adresse/zipcode': '75014',
     }
 
     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'
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_update_family_soap_error(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
     mocked_post.return_value = UPDATE_FAMILY_500
     url = get_endpoint('update-family')
     params = {
-        'rl1/adresse': {
-            'street1': 'Chateau',
-            'town': 'Paris',
-            'zipcode': '75014',
-        },
-        'rl1': {
-            'firstname': 'Jhon',
-            'lastname': 'Doe',
-            'quality': 'AU',
-            'dateBirth': '1938-07-26',
-        },
+        'nbChild': '100',
         'categorie': 'BI',
         'situation': 'C',
-        'nbChild': '100',
+        'rl1/firstname': 'Jhon',
+        'rl1/lastname': 'Doe',
+        'rl1/quality': 'AU',
+        'rl1/dateBirth': '1938-07-26',
+        'rl1/adresse/street1': 'Chateau',
+        'rl1/adresse/town': 'Paris',
+        'rl1/adresse/zipcode': '75014',
     }
 
     Link.objects.create(resource=con, family_id='1312', name_id='local')
     resp = app.post_json(url + '?NameID=local', params=params)
     assert resp.json['err'] == 'Family-updateFamily-soap:Server'
     assert 'Une erreur est survenue' in resp.json['err_desc']
 
 
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_update_coordinate(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
     mocked_post.return_value = UPDATE_FAMILY
     url = get_endpoint('update-coordinate')
     params = {
-        'adresse': {
-            'num': '169',
-            'numComp': None,
-            'street1': 'Château',
-            'street2': None,
-            'town': 'Paris',
-            'zipcode': '75014',
-        }
+        'adresse/num': '169',
+        'adresse/numComp': None,
+        'adresse/street1': 'Château',
+        'adresse/street2': None,
+        'adresse/town': 'Paris',
+        'adresse/zipcode': '75014',
     }
 
     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_update_coordinate.xml')
     assert resp.json['err'] == 0
     assert resp.json['data'] == 'ok'
 
 
 def test_update_coordinate_schema_error(con, app):
     url = get_endpoint('update-coordinate')
     params = {
-        'contact': {
-            'isContactMail': 'true more text',
-        }
+        'contact/isContactMail': 'true more text',
     }
 
     resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params, status=400)
     assert resp.json['err'] == 1
     assert resp.json['err_desc'] == "'true more text' is not of type 'boolean'"
-- 
2.30.2

