From 6ed852ae01d9c5f2800614541ccf0fb43670ac75 Mon Sep 17 00:00:00 2001
From: Remco Tukker <remco.tukker@geant.org>
Date: Fri, 21 Jul 2023 00:27:58 +0200
Subject: [PATCH] fixes for conversion bugs that Daniel found

---
 compendium_v2/conversion/conversion.py |  5 +++++
 compendium_v2/conversion/mapping.py    | 22 +++++++++++++++++++++-
 test/test_conversion.py                |  2 +-
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/compendium_v2/conversion/conversion.py b/compendium_v2/conversion/conversion.py
index 74bb0877..dba24a7c 100644
--- a/compendium_v2/conversion/conversion.py
+++ b/compendium_v2/conversion/conversion.py
@@ -56,6 +56,9 @@ def convert_answers(answers):
                     mapped_answer.append(mapping.VALUE_TO_CODE_MAPPING[id][entry])
                 answer = mapped_answer
 
+        if id == 16504:
+            answer = '\n'.join(answer)
+
         # code to convert my description in the mapping to a json structure
         question_names = question_name.split(":")
         subdict = data
@@ -125,6 +128,8 @@ def _cli(app):
 
         for nren, answers in nren_surveys.items():
             survey_dict = convert_answers(answers)
+            survey_dict["page"] = 0
+            survey_dict["verification_status"] = {}
             response = SurveyResponse(
                 nren=nren,
                 nren_id=nren.id,
diff --git a/compendium_v2/conversion/mapping.py b/compendium_v2/conversion/mapping.py
index 35bbe0d1..00c69e2a 100644
--- a/compendium_v2/conversion/mapping.py
+++ b/compendium_v2/conversion/mapping.py
@@ -183,7 +183,7 @@ ID_TO_NAME = {
     16501: "business_continuity_plans",  # "Yes" "No"
     16502: "business_continuity_plans_specifics",
     16503: "security_controls",  # json list with double quotes
-    16504: "security_controls-Comment",
+    16504: "security_controls-Comment",  # json list with double quotes that should be mapped to string
     # 16505: "policy_comments",
     16760: "policies:gender_equality_policy:available",  # "Yes" "No"
     16761: "policies:gender_equality_policy:url",
@@ -452,6 +452,16 @@ CONNECTION = {
     "No - other reason / unsure": "no_other"
 }
 
+COVERED = {
+    "Yes - including transit to other networks": "yes_incl_other",
+    "Yes - national NREN access": "yes_national_nren",
+    "In some circumstances ": "sometimes",
+    "No - not eligible for policy reasons": "no_policy",
+    "No - financial restrictions (NREN is unable to charge/cover costs)": "no_financial",
+    "No - other reason": "no_other",
+    "Unsure/unclear": "unsure"
+}
+
 CHARGING_LEVELS = {
     "Charges typically higher than for R+E users": "higher_than_r_e_charges",
     "Same charging model as for R+E users": "same_as_r_e_charges",
@@ -496,6 +506,16 @@ VALUE_TO_CODE_MAPPING = {
         "Integrity checking": "integrity_checking",
         "Other": "other"
     },
+    16539: COVERED,
+    16540: COVERED,
+    16541: COVERED,
+    16542: COVERED,
+    16543: COVERED,
+    16544: COVERED,
+    16545: COVERED,
+    16546: COVERED,
+    16547: COVERED,
+    16548: COVERED,
     16763: {
         "We participate in GEANT Crisis workshops such as CLAW": "geant_workshops",
         "No, we have not done any crisis exercises or trainings": "none",
diff --git a/test/test_conversion.py b/test/test_conversion.py
index 73453cf8..5d67a98a 100644
--- a/test/test_conversion.py
+++ b/test/test_conversion.py
@@ -32,7 +32,7 @@ def test_queries(app_with_survey_db, mocker):
 
         responses = db.session.scalars(select(SurveyResponse).order_by(SurveyResponse.nren_id)).all()
         assert len(responses) == 1
-        assert responses[0].answers == {"data": {}}
+        assert responses[0].answers == {"data": {}, "page": 0, "verification_status": {}}
 
 
 def test_conversion():
-- 
GitLab