From 9c04bde02fae3c4733b0c763d111a32b8ca8dfac Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Wed, 30 Nov 2022 14:31:45 +0100
Subject: [PATCH 2/3] toulouse-maelis: adapt functest on update_coordinate
 (#71964)

---
 functests/toulouse_maelis/conftest.py         |  7 ++-
 .../data/test_update_coordinate.json          | 54 -------------------
 .../data/test_update_coordinate_CAFInfo.json  |  4 ++
 .../data/test_update_coordinate_adresse.json  | 10 ++++
 .../data/test_update_coordinate_contact.json  |  8 +++
 .../test_update_coordinate_profession.json    | 13 +++++
 functests/toulouse_maelis/test_family.py      |  3 +-
 7 files changed, 42 insertions(+), 57 deletions(-)
 delete mode 100644 functests/toulouse_maelis/data/test_update_coordinate.json
 create mode 100644 functests/toulouse_maelis/data/test_update_coordinate_CAFInfo.json
 create mode 100644 functests/toulouse_maelis/data/test_update_coordinate_adresse.json
 create mode 100644 functests/toulouse_maelis/data/test_update_coordinate_contact.json
 create mode 100644 functests/toulouse_maelis/data/test_update_coordinate_profession.json

diff --git a/functests/toulouse_maelis/conftest.py b/functests/toulouse_maelis/conftest.py
index 226b1ace..e854ea0c 100644
--- a/functests/toulouse_maelis/conftest.py
+++ b/functests/toulouse_maelis/conftest.py
@@ -284,21 +284,24 @@ def diff_child(conn, name_id, index, expected_file, key=None):
     remove_id_on_child(child)
     if not key:
         assert diff(child, expected_file)
     else:
         assert diff(child[key], expected_file)
     return data
 
 
-def diff_rlg(conn, name_id, index, expected_file):
+def diff_rlg(conn, name_id, index, expected_file, key=None):
     data = read_family(conn, name_id)
     rlg = copy.deepcopy(data['RL%s' % index])
     remove_id_on_rlg(rlg)
-    assert diff(rlg, expected_file)
+    if not key:
+        assert diff(rlg, expected_file)
+    else:
+        assert diff(rlg[key], expected_file)
     return data
 
 
 def diff_family(conn, name_id, expected_file, key=None):
     data = read_family(conn, name_id)
     family = copy.deepcopy(data)
     remove_id_on_family(family)
     if not key:
diff --git a/functests/toulouse_maelis/data/test_update_coordinate.json b/functests/toulouse_maelis/data/test_update_coordinate.json
deleted file mode 100644
index bc5b0040..00000000
--- a/functests/toulouse_maelis/data/test_update_coordinate.json
+++ /dev/null
@@ -1,54 +0,0 @@
-{
-  "num": "N/A",
-  "firstname": "HOMER",
-  "lastname": "N/A",
-  "maidenName": null,
-  "quality": "PERE",
-  "civility": "M.",
-  "birth": {
-    "dateBirth": "1956-05-12T00:00:00+01:00",
-    "place": null,
-    "communeCode": null,
-    "countryCode": null
-  },
-  "adresse": {
-    "idStreet": null,
-    "num": 42,
-    "numComp": "Q",
-    "street1": "reset",
-    "street2": null,
-    "town": "reset",
-    "zipcode": "reset",
-    "numComp_text": "quater"
-  },
-  "contact": {
-    "phone": null,
-    "mobile": null,
-    "mail": null,
-    "isContactMail": false,
-    "isContactSms": false,
-    "isInvoicePdf": false
-  },
-  "profession": {
-    "codeCSP": "15",
-    "profession": null,
-    "employerName": null,
-    "phone": null,
-    "addressPro": {
-      "num": 42,
-      "street": null,
-      "zipcode": null,
-      "town": null
-    },
-    "codeCSP_text": "AUTRES"
-  },
-  "CAFInfo": {
-    "number": "reset",
-    "organ": null
-  },
-  "indicatorList": [],
-  "quotientList": [],
-  "subscribeActivityList": [],
-  "civility_text": "Monsieur",
-  "quality_text": "PERE"
-}
diff --git a/functests/toulouse_maelis/data/test_update_coordinate_CAFInfo.json b/functests/toulouse_maelis/data/test_update_coordinate_CAFInfo.json
new file mode 100644
index 00000000..97e3e093
--- /dev/null
+++ b/functests/toulouse_maelis/data/test_update_coordinate_CAFInfo.json
@@ -0,0 +1,4 @@
+{
+  "number": "reset",
+  "organ": null
+}
diff --git a/functests/toulouse_maelis/data/test_update_coordinate_adresse.json b/functests/toulouse_maelis/data/test_update_coordinate_adresse.json
new file mode 100644
index 00000000..bf548b6b
--- /dev/null
+++ b/functests/toulouse_maelis/data/test_update_coordinate_adresse.json
@@ -0,0 +1,10 @@
+{
+  "idStreet": null,
+  "num": 42,
+  "numComp": "Q",
+  "street1": "reset",
+  "street2": null,
+  "town": "reset",
+  "zipcode": "reset",
+  "numComp_text": "quater"
+}
diff --git a/functests/toulouse_maelis/data/test_update_coordinate_contact.json b/functests/toulouse_maelis/data/test_update_coordinate_contact.json
new file mode 100644
index 00000000..a14f554e
--- /dev/null
+++ b/functests/toulouse_maelis/data/test_update_coordinate_contact.json
@@ -0,0 +1,8 @@
+{
+  "phone": null,
+  "mobile": null,
+  "mail": null,
+  "isContactMail": false,
+  "isContactSms": false,
+  "isInvoicePdf": false
+}
diff --git a/functests/toulouse_maelis/data/test_update_coordinate_profession.json b/functests/toulouse_maelis/data/test_update_coordinate_profession.json
new file mode 100644
index 00000000..5cb1b665
--- /dev/null
+++ b/functests/toulouse_maelis/data/test_update_coordinate_profession.json
@@ -0,0 +1,13 @@
+{
+  "codeCSP": "15",
+  "profession": null,
+  "employerName": null,
+  "phone": null,
+  "addressPro": {
+    "num": 42,
+    "street": null,
+    "zipcode": null,
+    "town": null
+  },
+  "codeCSP_text": "AUTRES"
+}
diff --git a/functests/toulouse_maelis/test_family.py b/functests/toulouse_maelis/test_family.py
index feccac85..1a7c7942 100644
--- a/functests/toulouse_maelis/test_family.py
+++ b/functests/toulouse_maelis/test_family.py
@@ -372,17 +372,18 @@ def test_update_coordinate(conn, update_data):
     # reset RL2 coordinates
     url = conn + '/update-coordinate?NameID=%s&rl_id=%s' % (update_data['name_id'], update_data['rl2_num'])
     payload = {}
     for key in 'adresse', 'contact', 'profession', 'CAFInfo':
         payload[key] = FAMILY_RESET_PAYLOAD['rl2'][key]
     resp = requests.post(url, json=payload)
     resp.raise_for_status()
     assert resp.json()['err'] == 0
-    assert diff_rlg(conn, update_data['name_id'], 2, 'test_update_coordinate.json')
+    for key in 'adresse', 'contact', 'profession', 'CAFInfo':
+        assert diff_rlg(conn, update_data['name_id'], 2, 'test_update_coordinate_%s.json' % key, key)
 
     # restore RL2 coordinates
     payload = {}
     for key in 'adresse', 'contact', 'profession', 'CAFInfo':
         payload[key] = update_data['family_payload']['rl2'][key]
     resp = requests.post(url, json=payload)
     resp.raise_for_status()
     assert resp.json()['err'] == 0
-- 
2.30.2

