From 8621bbae1b61b3f399015c6590b3cecbe38cb39d Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Wed, 14 Dec 2022 12:49:38 +0100
Subject: [PATCH] toulouse-maelis: return family id on read family members
 endpoints (#72399)

---
 functests/toulouse_maelis/conftest.py                      | 1 +
 functests/toulouse_maelis/data/test_create_family.json     | 3 ++-
 functests/toulouse_maelis/data/test_update_family.json     | 3 ++-
 functests/toulouse_maelis/data/test_update_family_ras.json | 3 ++-
 passerelle/contrib/toulouse_maelis/models.py               | 5 +++++
 tests/test_toulouse_maelis.py                              | 2 ++
 6 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/functests/toulouse_maelis/conftest.py b/functests/toulouse_maelis/conftest.py
index 9564ed71..3d96ace0 100644
--- a/functests/toulouse_maelis/conftest.py
+++ b/functests/toulouse_maelis/conftest.py
@@ -293,16 +293,17 @@ def remove_id_on_child(child):
 def remove_id_on_rlg(rlg):
     if rlg:
         rlg['num'] = 'N/A'
         rlg['lastname'] = 'N/A'
 
 
 def remove_id_on_family(family):
     family['number'] = 'N/A'
+    family['family_id'] = 'N/A'
     remove_id_on_rlg(family['RL1'])
     remove_id_on_rlg(family['RL2'])
     for child in family['childList']:
         remove_id_on_child(child)
     for person in family['emergencyPersonList']:
         person['numPerson'] = 'N/A'
 
 
diff --git a/functests/toulouse_maelis/data/test_create_family.json b/functests/toulouse_maelis/data/test_create_family.json
index 12ee696c..fcab8777 100644
--- a/functests/toulouse_maelis/data/test_create_family.json
+++ b/functests/toulouse_maelis/data/test_create_family.json
@@ -238,10 +238,11 @@
       "civility_text": "Madame",
       "quality_text": "ORGANISME SOCIAL",
       "sexe_text": "F\u00e9minin"
     }
   ],
   "indicatorList": [],
   "childErrorList": [],
   "category_text": "BIPARENTALE",
-  "situation_text": "Vivant maritalement"
+  "situation_text": "Vivant maritalement",
+  "family_id": "N/A"
 }
diff --git a/functests/toulouse_maelis/data/test_update_family.json b/functests/toulouse_maelis/data/test_update_family.json
index 018b9f8f..75bcbc97 100644
--- a/functests/toulouse_maelis/data/test_update_family.json
+++ b/functests/toulouse_maelis/data/test_update_family.json
@@ -339,10 +339,11 @@
       "civility_text": "Madame",
       "quality_text": "ORGANISME SOCIAL",
       "sexe_text": "F\u00e9minin"
     }
   ],
   "indicatorList": [],
   "childErrorList": [],
   "category_text": "BIPARENTALE",
-  "situation_text": "Vivant maritalement"
+  "situation_text": "Vivant maritalement",
+  "family_id": "N/A"
 }
diff --git a/functests/toulouse_maelis/data/test_update_family_ras.json b/functests/toulouse_maelis/data/test_update_family_ras.json
index 8e943b4c..c815a7b8 100644
--- a/functests/toulouse_maelis/data/test_update_family_ras.json
+++ b/functests/toulouse_maelis/data/test_update_family_ras.json
@@ -251,10 +251,11 @@
       "contact": null,
       "quality_text": "AUTRE",
       "sexe_text": "Masculin"
     }
   ],
   "indicatorList": [],
   "childErrorList": [],
   "category_text": "MONOPARENTALE",
-  "situation_text": "UNION LIBRE"
+  "situation_text": "UNION LIBRE",
+  "family_id": "N/A"
 }
diff --git a/passerelle/contrib/toulouse_maelis/models.py b/passerelle/contrib/toulouse_maelis/models.py
index 862035aa..bdb89698 100644
--- a/passerelle/contrib/toulouse_maelis/models.py
+++ b/passerelle/contrib/toulouse_maelis/models.py
@@ -732,78 +732,83 @@ class ToulouseMaelis(BaseResource, HTTPResource):
         parameters={
             'NameID': {'description': 'Publik NameID'},
             'income_year': {'description': 'Année de revenu pour filtrer les quotients'},
         },
     )
     def read_family(self, request, NameID, income_year=None):
         family_id = self.get_link(NameID).family_id
         data = self.get_family(family_id, incomeYear=income_year)
+        data['family_id'] = family_id
         return {'data': data}
 
     @endpoint(
         display_category='Famille',
         description="Informations sur un responsable légal",
         perm='can_access',
         name='read-rl',
         parameters={
             'NameID': {'description': 'Publik NameID'},
             'rl_id': {'description': 'Numéro du représentant légal'},
             'income_year': {'description': 'Année de revenu pour filtrer les quotients'},
         },
     )
     def read_rl(self, request, NameID, rl_id, income_year=None):
         family_id = self.get_link(NameID).family_id
         data = self.get_rl(family_id, rl_id, incomeYear=income_year)
+        data['family_id'] = family_id
         return {'data': data}
 
     @endpoint(
         display_category='Famille',
         description="Informations sur une personne autorisée à récupérer les enfants ou à prévenir en cas d'urgence",
         perm='can_access',
         name='read-person',
         parameters={
             'NameID': {'description': 'Publik NameID'},
             'person_id': {'description': 'Numéro de la personne'},
         },
     )
     def read_person(self, request, NameID, person_id):
         family_id = self.get_link(NameID).family_id
         data = self.get_person(family_id, person_id)
+        data['family_id'] = family_id
         return {'data': data}
 
     @endpoint(
         display_category='Famille',
         description="Informations sur un enfant",
         perm='can_access',
         name='read-child',
         parameters={
             'NameID': {'description': 'Publik NameID'},
             'child_id': {'description': "Numéro de l'enfant"},
         },
     )
     def read_child(self, request, NameID, child_id):
         family_id = self.get_link(NameID).family_id
         data = self.get_child(family_id, child_id)
+        data['family_id'] = family_id
         return {'data': data}
 
     @endpoint(
         display_category='Famille',
         description="Informations sur une personne autorisée à récupérer l'enfant",
         perm='can_access',
         name='read-child-person',
         parameters={
             'NameID': {'description': 'Publik NameID'},
             'child_id': {'description': "Numéro de l'enfant"},
             'person_id': {'description': 'Numéro de la personne'},
         },
     )
     def read_child_person(self, request, NameID, child_id, person_id):
         family_id = self.get_link(NameID).family_id
         data = self.get_child_person(family_id, child_id, person_id)
+        data['family_id'] = family_id
         return {'data': data}
 
     @endpoint(
         display_category='Famille',
         description="Vérifier qu'un responsable légal existe en base",
         perm='can_access',
         name='is-rl-exists',
         post={'request_body': {'schema': {'application/json': schemas.ISEXISTS_SCHEMA}}},
diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py
index 0f5ef10c..8b952f10 100644
--- a/tests/test_toulouse_maelis.py
+++ b/tests/test_toulouse_maelis.py
@@ -677,16 +677,17 @@ def test_read_family(family_service, xml, con, app):
     resp = app.get(url + '?NameID=local')
     assert resp.json['err'] == 0
     data = resp.json['data']
     del data['RL1']
     del data['RL2']
     del data['childList']
     del data['emergencyPersonList']
     assert data == {
+        'family_id': '1312',
         'number': 1312,
         'category': 'BI',
         'situation': 'M',
         'flagCom': True,
         'nbChild': 2,
         'nbTotalChild': None,
         'nbAES': None,
         'quotientList': [],
@@ -927,16 +928,17 @@ def test_read_rl1_with_income_year(family_service, con, app):
 def test_read_rl2(family_service, con, app):
     family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
     url = get_endpoint('read-rl')
     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'] == {
+        'family_id': '1312',
         'num': '613879',
         'lastname': 'DOE',
         'firstname': 'JANE',
         'maidenName': 'SMITH',
         'quality': 'MERE',
         'civility': 'MME',
         'birth': {
             'communeCode': None,
-- 
2.30.2

