From de3e96f50f6128bb2077ccb1d3d6dfbe377389aa Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Thu, 15 Dec 2022 22:56:45 +0100
Subject: [PATCH 2/4] toulouse-maelis: correct bool input on WS (#72523)

---
 passerelle/contrib/toulouse_maelis/models.py | 16 ++++++++++++++++
 tests/test_toulouse_maelis.py                |  3 +++
 2 files changed, 19 insertions(+)

diff --git a/passerelle/contrib/toulouse_maelis/models.py b/passerelle/contrib/toulouse_maelis/models.py
index ce4d7e9c..ed470019 100644
--- a/passerelle/contrib/toulouse_maelis/models.py
+++ b/passerelle/contrib/toulouse_maelis/models.py
@@ -366,16 +366,18 @@ class ToulouseMaelis(BaseResource, HTTPResource):
             )
             item['isActive'] = self.encode_bool(item['isActive'])
 
     def assert_child_medical_record_payload_in_referential(self, post_data, parent_keys=None):
         keys = parent_keys or []
         data = post_data
         for key in keys:
             data = data[key]
+        if 'isAuthHospital' in data:
+            data['isAuthHospital'] = self.encode_bool(data['isAuthHospital'])
 
         for i in range(0, len(data.get('vaccinList', []))):
             self.assert_post_data_in_referential(
                 'Vaccin', post_data, keys + ['vaccinList', i, 'code'], required=False
             )
 
     def assert_child_pai_payoad_in_referential(self, post_data, parent_keys=None):
         keys = parent_keys or []
@@ -391,16 +393,19 @@ class ToulouseMaelis(BaseResource, HTTPResource):
 
     def assert_child_payload_in_referential(self, post_data, parent_keys=None):
         keys = parent_keys or []
         self.assert_post_data_in_referential('Sex', post_data, keys + ['sexe'])
 
         data = post_data
         for key in keys:
             data = data[key]
+        for key in 'bPhoto', 'bLeaveAlone':
+            if key in data:
+                data[key] = self.encode_bool(data[key])
 
         if 'dietcode' in data:
             self.assert_post_data_in_referential('DietCode', post_data, keys + ['dietcode'], required=False)
         if 'paiInfoBean' in data:
             self.assert_child_pai_payoad_in_referential(post_data, keys + ['paiInfoBean'])
         if 'medicalRecord' in data:
             # dead code as updateFamily seems not to modify medicalRecord
             self.assert_child_medical_record_payload_in_referential(post_data, keys + ['medicalRecord'])
@@ -420,16 +425,25 @@ class ToulouseMaelis(BaseResource, HTTPResource):
         self.assert_post_data_in_referential(
             'Complement', post_data, keys + ['adresse', 'numComp'], required=False
         )
         self.assert_post_data_in_referential(
             'CSP', post_data, keys + ['profession', 'codeCSP'], required=False
         )
         self.assert_post_data_in_referential('Organ', post_data, keys + ['CAFInfo', 'organ'], required=False)
 
+        data = post_data
+        for key in keys:
+            data = data[key]
+        if 'contact' in data:
+            data = data['contact']
+            for key in 'isContactMail', 'isContactSms', 'isInvoicePdf':
+                if key in data:
+                    data[key] = self.encode_bool(data[key])
+
     def assert_rl_payload_in_referential(self, post_data, parent_keys=None):
         keys = parent_keys or []
         self.assert_post_data_in_referential('Civility', post_data, keys + ['civility'])
         self.assert_post_data_in_referential('Quality', post_data, keys + ['quality'])
         self.assert_update_coordinate_payload_in_referential(post_data, keys)
         self.assert_update_indicator_payload_in_referential('RLIndicator', post_data, keys)
 
     def assert_create_rl1_payload_in_referential(self, post_data):
@@ -445,16 +459,18 @@ class ToulouseMaelis(BaseResource, HTTPResource):
                 self.assert_rl_payload_in_referential(post_data, [rlg])
         for i, person in enumerate(post_data.get('emergencyPersonList') or []):
             for j in range(0, len(person.get('personList') or [])):
                 self.assert_person_payload_in_referential(
                     post_data, ['emergencyPersonList', i, 'personList', j]
                 )
         for i in range(0, len(post_data.get('childList') or [])):
             self.assert_child_payload_in_referential(post_data, ['childList', i])
+        if 'flagCom' in post_data:
+            post_data['flagCom'] = self.encode_bool(post_data['flagCom'])
 
     def replace_null_values(self, dico):
         '''send null fields as empty SOAP tag to tell maelis to empty the value'''
         for key, value in dico.items():
             if isinstance(value, dict):
                 self.replace_null_values(value)
             if value is None:
                 dico[key] = ''
diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py
index 8595e577..41a2dbeb 100644
--- a/tests/test_toulouse_maelis.py
+++ b/tests/test_toulouse_maelis.py
@@ -1257,29 +1257,31 @@ def test_create_family(family_service, con, app):
 
     family_service.add_soap_response(
         'createFamily', get_xml_file('R_create_family.xml'), request_check=request_check
     )
     url = get_endpoint('create-family')
     params = {
         'category': 'ACCEUI',
         'situation': 'C',
+        'flagCom': False,
         'rl1/civility': 'M.',
         'rl1/firstname': 'Jhon',
         'rl1/lastname': 'Doe',
         'rl1/quality': 'AU',
         'rl1/birth/communeCode': None,
         'rl1/birth/countryCode': '99350',
         'rl1/birth/dateBirth': '1938-07-26',
         'rl1/birth/place': 'Rabbat',
         'rl1/adresse/idStreet': 'AM0330',
         'rl1/adresse/street1': 'Chateau',
         'rl1/adresse/town': 'Paris',
         'rl1/adresse/zipcode': '75014',
         'rl1/adresse/numComp': 'B',
+        'rl1/contact/isContactMail': True,
         'rl1/profession/codeCSP': 'ART',
         'rl1/CAFInfo/organ': 'A10007752822',
         'emergencyPersonList/0/civility': 'MME',
         'emergencyPersonList/0/firstname': 'Keny',
         'emergencyPersonList/0/lastname': 'Arkana',
         'emergencyPersonList/0/sexe': 'F',
         'emergencyPersonList/0/dateBirth': '1982-12-20',
         'emergencyPersonList/0/quality': 'T',
@@ -2151,16 +2153,17 @@ def test_update_coordinate(family_service, con, app):
     params = {
         'adresse/num': '169',
         'adresse/numComp': 'B',
         'adresse/idStreet': 'AM0330',
         'adresse/street1': 'Château',
         'adresse/street2': None,
         'adresse/town': 'Paris',
         'adresse/zipcode': '75014',
+        'contact/isContactMail': True,
         'profession/codeCSP': 'ART',
         'profession/profession': 'informaticien',
         'profession/employerName': 'EO',
         'profession/phone': '0123456789',
         'profession/addressPro': {'num': None, 'street': None, 'zipcode': None, 'town': 'Orléans'},
         'CAFInfo/number': '789',
         'CAFInfo/organ': 'A10007752822',
     }
-- 
2.30.2

