From cba8238383dfe899c8d4f5fc96ec468bcafb713c Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Tue, 29 Nov 2022 18:43:22 +0100
Subject: [PATCH 4/4] toulouse-maelis: add indicators referentials (#71858)

---
 .../data/test_read_child-indicator_list.json  | 66 +++++++++++++++++++
 .../data/test_read_rl-indicator_list.json     | 34 ++++++++++
 functests/toulouse_maelis/test_family.py      |  2 +
 passerelle/contrib/toulouse_maelis/models.py  | 24 +++++++
 .../R_read_child_indicator_list.xml           | 46 +++++++++++++
 .../R_read_rl_indicator_list.xml              | 26 ++++++++
 tests/test_toulouse_maelis.py                 | 62 +++++++++++++++++
 7 files changed, 260 insertions(+)
 create mode 100644 functests/toulouse_maelis/data/test_read_child-indicator_list.json
 create mode 100644 functests/toulouse_maelis/data/test_read_rl-indicator_list.json
 create mode 100644 tests/data/toulouse_maelis/R_read_child_indicator_list.xml
 create mode 100644 tests/data/toulouse_maelis/R_read_rl_indicator_list.xml

diff --git a/functests/toulouse_maelis/data/test_read_child-indicator_list.json b/functests/toulouse_maelis/data/test_read_child-indicator_list.json
new file mode 100644
index 00000000..8fdbdbc3
--- /dev/null
+++ b/functests/toulouse_maelis/data/test_read_child-indicator_list.json
@@ -0,0 +1,66 @@
+[
+  {
+    "code": "APPDENTAIRE",
+    "label": "Port appareil dentaire",
+    "typeDesc": "NONE",
+    "choiceList": [],
+    "id": "APPDENTAIRE",
+    "text": "Port appareil dentaire"
+  },
+  {
+    "code": "AUTRE",
+    "label": "Autre",
+    "typeDesc": "NOTE",
+    "choiceList": [],
+    "id": "AUTRE",
+    "text": "Autre"
+  },
+  {
+    "code": "AVL",
+    "label": "Auxiliaire de Vie loisirs",
+    "typeDesc": "NONE",
+    "choiceList": [],
+    "id": "AVL",
+    "text": "Auxiliaire de Vie loisirs"
+  },
+  {
+    "code": "AVS",
+    "label": "Auxiliaire de Vie scolaire ",
+    "typeDesc": "NONE",
+    "choiceList": [],
+    "id": "AVS",
+    "text": "Auxiliaire de Vie scolaire"
+  },
+  {
+    "code": "ETABSPEC",
+    "label": "Etablissement sp\u00e9cialis\u00e9",
+    "typeDesc": "NOTE",
+    "choiceList": [],
+    "id": "ETABSPEC",
+    "text": "Etablissement sp\u00e9cialis\u00e9"
+  },
+  {
+    "code": "LENTILLE",
+    "label": "Port lentilles de contact",
+    "typeDesc": "NONE",
+    "choiceList": [],
+    "id": "LENTILLE",
+    "text": "Port lentilles de contact"
+  },
+  {
+    "code": "LUNETTE",
+    "label": "Port de lunettes",
+    "typeDesc": "NONE",
+    "choiceList": [],
+    "id": "LUNETTE",
+    "text": "Port de lunettes"
+  },
+  {
+    "code": "MDPH",
+    "label": "Notification MDPH",
+    "typeDesc": "NONE",
+    "choiceList": [],
+    "id": "MDPH",
+    "text": "Notification MDPH"
+  }
+]
diff --git a/functests/toulouse_maelis/data/test_read_rl-indicator_list.json b/functests/toulouse_maelis/data/test_read_rl-indicator_list.json
new file mode 100644
index 00000000..3f288cdc
--- /dev/null
+++ b/functests/toulouse_maelis/data/test_read_rl-indicator_list.json
@@ -0,0 +1,34 @@
+[
+  {
+    "code": "AVL",
+    "label": "Auxiliaire de Vie loisirs",
+    "typeDesc": "NONE",
+    "choiceList": [],
+    "id": "AVL",
+    "text": "Auxiliaire de Vie loisirs"
+  },
+  {
+    "code": "AVS",
+    "label": "Auxiliaire de Vie scolaire ",
+    "typeDesc": "NONE",
+    "choiceList": [],
+    "id": "AVS",
+    "text": "Auxiliaire de Vie scolaire"
+  },
+  {
+    "code": "ETABSPEC",
+    "label": "Etablissement sp\u00e9cialis\u00e9",
+    "typeDesc": "NOTE",
+    "choiceList": [],
+    "id": "ETABSPEC",
+    "text": "Etablissement sp\u00e9cialis\u00e9"
+  },
+  {
+    "code": "MDPH",
+    "label": "Notification MDPH",
+    "typeDesc": "NONE",
+    "choiceList": [],
+    "id": "MDPH",
+    "text": "Notification MDPH"
+  }
+]
diff --git a/functests/toulouse_maelis/test_family.py b/functests/toulouse_maelis/test_family.py
index d46449f7..7418b996 100644
--- a/functests/toulouse_maelis/test_family.py
+++ b/functests/toulouse_maelis/test_family.py
@@ -128,24 +128,26 @@ FAMILY_RESET_PAYLOAD = {
 }
 
 
 # @pytest.mark.xfail(run=False)
 @pytest.mark.parametrize(
     "ref",
     [
         'category',
+        'child-indicator',
         'civility',
         'country',
         'csp',
         'dietcode',
         'organ',
         'pai',
         'quality',
         'quotient',
+        'rl-indicator',
         'situation',
         'street',
         'vaccin',
     ],
 )
 def test_referentials(conn, ref):
     url = conn + '/read-%s-list' % ref
     resp = requests.get(url)
diff --git a/passerelle/contrib/toulouse_maelis/models.py b/passerelle/contrib/toulouse_maelis/models.py
index 5408053d..be106668 100644
--- a/passerelle/contrib/toulouse_maelis/models.py
+++ b/passerelle/contrib/toulouse_maelis/models.py
@@ -92,16 +92,22 @@ class ToulouseMaelis(BaseResource, HTTPResource):
         data = cache.get(cache_key)
         if data is None:
             response = self.call('Family', 'read' + referential_name + 'List')
             data_list = []
             if referential_name == 'Organ':
                 data_list = [{'id': x.id, 'text': x.code} for x in response]
             elif referential_name == 'Street':
                 data_list = [{'id': x.idStreet, 'text': x.libelleStreet} for x in response]
+            elif 'Indicator' in referential_name:
+                data_list = []
+                for item in serialize_object(response):
+                    item['id'] = item['code']
+                    item['text'] = item['label']
+                    data_list.append(item)
             else:
                 data_list = [{'id': x.code, 'text': x.libelle} for x in response]
 
             # remove redundant codes from list
             uniq_text = set()
             uniq_data = []
             for item in data_list:
                 item['text'] = item['text'].strip()
@@ -360,16 +366,25 @@ class ToulouseMaelis(BaseResource, HTTPResource):
         display_category='Famille',
         description='Liste des catégories',
         name='read-category-list',
         perm='can_access',
     )
     def read_category_list(self, request):
         return {'data': self.get_referential('Category')['list']}
 
+    @endpoint(
+        display_category='Famille',
+        description='Liste des indicateurs sur le enfants',
+        name='read-child-indicator-list',
+        perm='can_access',
+    )
+    def read_child_indicator_list(self, request):
+        return {'data': self.get_referential('ChildIndicator')['list']}
+
     @endpoint(
         display_category='Famille',
         description='Liste des civilités',
         name='read-civility-list',
         perm='can_access',
     )
     def read_civility_list(self, request):
         return {'data': self.get_referential('Civility')['list']}
@@ -441,16 +456,25 @@ class ToulouseMaelis(BaseResource, HTTPResource):
         display_category='Famille',
         description='Liste des quotients',
         name='read-quotient-list',
         perm='can_access',
     )
     def read_quotient_list(self, request):
         return {'data': self.get_referential('Quotient')['list']}
 
+    @endpoint(
+        display_category='Famille',
+        description='Liste des indicateurs sur les responables légaux',
+        name='read-rl-indicator-list',
+        perm='can_access',
+    )
+    def read_rl_indicator_list(self, request):
+        return {'data': self.get_referential('RLIndicator')['list']}
+
     @endpoint(
         display_category='Famille',
         description='Liste des sexes',
         name='read-sex-list',
         perm='can_access',
     )
     def read_sex_list(self, request):
         return {'data': self.get_referential('Sex')['list']}
diff --git a/tests/data/toulouse_maelis/R_read_child_indicator_list.xml b/tests/data/toulouse_maelis/R_read_child_indicator_list.xml
new file mode 100644
index 00000000..947b4c1a
--- /dev/null
+++ b/tests/data/toulouse_maelis/R_read_child_indicator_list.xml
@@ -0,0 +1,46 @@
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+  <soap:Body>
+    <ns2:readChildIndicatorListResponse xmlns:ns2="family.ws.maelis.sigec.com">
+      <childIndicatorList>
+        <code>APPDENTAIRE</code>
+        <label>Port appareil dentaire</label>
+        <typeDesc>NONE</typeDesc>
+      </childIndicatorList>
+      <childIndicatorList>
+        <code>AUTRE</code>
+        <label>Autre</label>
+        <typeDesc>NOTE</typeDesc>
+      </childIndicatorList>
+      <childIndicatorList>
+        <code>AVL</code>
+        <label>Auxiliaire de Vie loisirs</label>
+        <typeDesc>NONE</typeDesc>
+      </childIndicatorList>
+      <childIndicatorList>
+        <code>AVS</code>
+        <label>Auxiliaire de Vie scolaire </label>
+        <typeDesc>NONE</typeDesc>
+      </childIndicatorList>
+      <childIndicatorList>
+        <code>ETABSPEC</code>
+        <label>Etablissement sp&#233;cialis&#233;</label>
+        <typeDesc>NOTE</typeDesc>
+      </childIndicatorList>
+      <childIndicatorList>
+        <code>LENTILLE</code>
+        <label>Port lentilles de contact</label>
+        <typeDesc>NONE</typeDesc>
+      </childIndicatorList>
+      <childIndicatorList>
+        <code>LUNETTE</code>
+        <label>Port de lunettes</label>
+        <typeDesc>NONE</typeDesc>
+      </childIndicatorList>
+      <childIndicatorList>
+        <code>MDPH</code>
+        <label>Notification MDPH</label>
+        <typeDesc>NONE</typeDesc>
+      </childIndicatorList>
+    </ns2:readChildIndicatorListResponse>
+  </soap:Body>
+</soap:Envelope>
diff --git a/tests/data/toulouse_maelis/R_read_rl_indicator_list.xml b/tests/data/toulouse_maelis/R_read_rl_indicator_list.xml
new file mode 100644
index 00000000..d6650d04
--- /dev/null
+++ b/tests/data/toulouse_maelis/R_read_rl_indicator_list.xml
@@ -0,0 +1,26 @@
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+  <soap:Body>
+    <ns2:readRLIndicatorListResponse xmlns:ns2="family.ws.maelis.sigec.com">
+      <rlIndicatorList>
+        <code>AVL</code>
+        <label>Auxiliaire de Vie loisirs</label>
+        <typeDesc>NONE</typeDesc>
+      </rlIndicatorList>
+      <rlIndicatorList>
+        <code>AVS</code>
+        <label>Auxiliaire de Vie scolaire </label>
+        <typeDesc>NONE</typeDesc>
+      </rlIndicatorList>
+      <rlIndicatorList>
+        <code>ETABSPEC</code>
+        <label>Etablissement sp&#233;cialis&#233;</label>
+        <typeDesc>NOTE</typeDesc>
+      </rlIndicatorList>
+      <rlIndicatorList>
+        <code>MDPH</code>
+        <label>Notification MDPH</label>
+        <typeDesc>NONE</typeDesc>
+      </rlIndicatorList>
+    </ns2:readRLIndicatorListResponse>
+  </soap:Body>
+</soap:Envelope>
diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py
index 61053692..18b5598a 100644
--- a/tests/test_toulouse_maelis.py
+++ b/tests/test_toulouse_maelis.py
@@ -41,24 +41,26 @@ INVOICE_SERVICE_WSDL = FakedResponse(content=get_xml_file('InvoiceService.wsdl')
 FAILED_AUTH = FakedResponse(content=get_xml_file('R_failed_authentication.xml'), status_code=500)
 ISWSRUNNING_TRUE = FakedResponse(content=get_xml_file('R_is_ws_running.xml') % b'true', status_code=200)
 ISWSRUNNING_FALSE = FakedResponse(content=get_xml_file('R_is_ws_running.xml') % b'false', status_code=200)
 READ_FAMILY = FakedResponse(content=get_xml_file('R_read_family.xml'), status_code=200)
 READ_FAMILY_LAX = FakedResponse(content=get_xml_file('R_read_family_relax.xml'), status_code=200)
 READ_FAMILY_ORD = FakedResponse(content=get_xml_file('R_read_family_reordered.xml'), status_code=200)
 READ_RL1_FAMILY = FakedResponse(content=get_xml_file('R_read_family_with_only_rl1.xml'), status_code=200)
 READ_CATEGORIES = FakedResponse(content=get_xml_file('R_read_category_list.xml'), status_code=200)
+READ_CHILD_INDICATOR = FakedResponse(content=get_xml_file('R_read_child_indicator_list.xml'), status_code=200)
 READ_CIVILITIES = FakedResponse(content=get_xml_file('R_read_civility_list.xml'), status_code=200)
 READ_COUNTRY = FakedResponse(content=get_xml_file('R_read_country_list.xml'), status_code=200)
 READ_CSP = FakedResponse(content=get_xml_file('R_read_csp_list.xml'), status_code=200)
 READ_DIETCODE = FakedResponse(content=get_xml_file('R_read_dietcode_list.xml'), status_code=200)
 READ_ORGAN = FakedResponse(content=get_xml_file('R_read_organ_list.xml'), status_code=200)
 READ_PAI = FakedResponse(content=get_xml_file('R_read_pai_list.xml'), status_code=200)
 READ_QUALITIES = FakedResponse(content=get_xml_file('R_read_quality_list.xml'), status_code=200)
 READ_QUOTIENT = FakedResponse(content=get_xml_file('R_read_quotient_list.xml'), status_code=200)
+READ_RL_INDICATOR = FakedResponse(content=get_xml_file('R_read_rl_indicator_list.xml'), status_code=200)
 READ_SITUATIONS = FakedResponse(content=get_xml_file('R_read_situation_list.xml'), status_code=200)
 READ_STREET = FakedResponse(content=get_xml_file('R_read_street_list.xml'), status_code=200)
 READ_VACCIN = FakedResponse(content=get_xml_file('R_read_vaccin_list.xml'), status_code=200)
 IS_RL_EXISTS_TRUE = FakedResponse(content=get_xml_file('R_is_rl_exists.xml') % b'true', status_code=200)
 IS_RL_EXISTS_FALSE = FakedResponse(content=get_xml_file('R_is_rl_exists.xml') % b'false', status_code=200)
 IS_CHILD_EXISTS_TRUE = FakedResponse(content=get_xml_file('R_is_child_exists.xml') % b'true', status_code=200)
 IS_CHILD_EXISTS_FALSE = FakedResponse(
     content=get_xml_file('R_is_child_exists.xml') % b'false', status_code=200
@@ -327,16 +329,46 @@ def test_read_country_list(mocked_post, mocked_get, con, app):
     assert len(resp.json['data']) == 3
     assert resp.json['data'] == [
         {'id': '212', 'text': 'AFGHANISTAN'},
         {'id': '99303', 'text': 'AFRIQUE DU SUD'},
         {'id': '99125', 'text': 'ALBANIE'},
     ]
 
 
+@mock.patch('passerelle.utils.Request.get')
+@mock.patch('passerelle.utils.Request.post')
+def test_read_child_indicator_list(mocked_post, mocked_get, con, app):
+    mocked_get.return_value = FAMILY_SERVICE_WSDL
+    mocked_post.return_value = READ_CHILD_INDICATOR
+    url = get_endpoint('read-child-indicator-list')
+
+    resp = app.get(url)
+    assert resp.json['err'] == 0
+    assert len(resp.json['data']) == 8
+    assert resp.json['data'][0:2] == [
+        {
+            'id': 'APPDENTAIRE',
+            'text': 'Port appareil dentaire',
+            'choiceList': [],
+            'code': 'APPDENTAIRE',
+            'label': 'Port appareil dentaire',
+            'typeDesc': 'NONE',
+        },
+        {
+            'id': 'AUTRE',
+            'text': 'Autre',
+            'choiceList': [],
+            'code': 'AUTRE',
+            'label': 'Autre',
+            'typeDesc': 'NOTE',
+        },
+    ]
+
+
 @mock.patch('passerelle.utils.Request.get')
 @mock.patch('passerelle.utils.Request.post')
 def test_read_civility_list(mocked_post, mocked_get, con, app):
     mocked_get.return_value = FAMILY_SERVICE_WSDL
     mocked_post.return_value = READ_CIVILITIES
     url = get_endpoint('read-civility-list')
 
     resp = app.get(url)
@@ -500,16 +532,46 @@ def test_read_quotient_list(mocked_post, mocked_get, con, app):
         {'id': 'QCLSH', 'text': 'QUOTIENT CENTRE AERE'},
         {'id': 'QJEU', 'text': 'QUOTIENT JEUNESSE'},
         {'id': 'QS', 'text': 'QUOTIENT SCOLAIRE'},
         {'id': 'QSPORT', 'text': 'QUOTIENT SPORT'},
         {'id': 'MOY ECO', 'text': 'REVENU MOYEN ( MENSUEL OU ANNUEL)'},
     ]
 
 
+@mock.patch('passerelle.utils.Request.get')
+@mock.patch('passerelle.utils.Request.post')
+def test_read_rl_indicator_list(mocked_post, mocked_get, con, app):
+    mocked_get.return_value = FAMILY_SERVICE_WSDL
+    mocked_post.return_value = READ_RL_INDICATOR
+    url = get_endpoint('read-rl-indicator-list')
+
+    resp = app.get(url)
+    assert resp.json['err'] == 0
+    assert len(resp.json['data']) == 4
+    assert resp.json['data'][1:3] == [
+        {
+            'id': 'AVS',
+            'text': 'Auxiliaire de Vie scolaire',
+            'choiceList': [],
+            'code': 'AVS',
+            'label': 'Auxiliaire de Vie scolaire ',
+            'typeDesc': 'NONE',
+        },
+        {
+            'id': 'ETABSPEC',
+            'text': 'Etablissement spécialisé',
+            'choiceList': [],
+            'code': 'ETABSPEC',
+            'label': 'Etablissement spécialisé',
+            'typeDesc': 'NOTE',
+        },
+    ]
+
+
 def test_read_sex_list(con, app):
     url = get_endpoint('read-sex-list')
 
     resp = app.get(url)
     assert resp.json['err'] == 0
     assert resp.json['data'] == [
         {'id': 'M', 'text': 'Masculin'},
         {'id': 'F', 'text': 'Féminin'},
-- 
2.30.2

