From 50a0691ebfcb726bd6e173c17463551e3a3b39bc Mon Sep 17 00:00:00 2001 From: Adam Davies Date: Fri, 15 Mar 2024 15:12:39 +0000 Subject: [PATCH 1/9] Fix yes no appearing only in english --- fsd_utils/mapping/application/qa_mapping.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fsd_utils/mapping/application/qa_mapping.py b/fsd_utils/mapping/application/qa_mapping.py index 7c0b930..9ee701d 100644 --- a/fsd_utils/mapping/application/qa_mapping.py +++ b/fsd_utils/mapping/application/qa_mapping.py @@ -10,7 +10,7 @@ from fsd_utils.mapping.application.multi_input import MultiInput -def extract_questions_and_answers(forms) -> dict: +def extract_questions_and_answers(forms, language) -> dict: """function takes the form data and returns dict of questions & answers. """ @@ -36,9 +36,11 @@ def extract_questions_and_answers(forms) -> dict: questions_answers[form_name][field["title"]] = answer elif isinstance(answer, bool) and field["type"] == "list": - + + yes = "Yes" if language == "en" else "Oes" + no = "No" if language == "en" else "Nac Oes" questions_answers[form_name][field["title"]] = ( - "Yes" if answer else "No" + yes if answer else no ) elif isinstance(answer, list) and field["type"] == "multiInput": From 77f08a66dbb1a96ab9d8c27d5294ea1ef66e771e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 15 Mar 2024 15:28:05 +0000 Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- fsd_utils/mapping/application/qa_mapping.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fsd_utils/mapping/application/qa_mapping.py b/fsd_utils/mapping/application/qa_mapping.py index 9ee701d..4e9e3c4 100644 --- a/fsd_utils/mapping/application/qa_mapping.py +++ b/fsd_utils/mapping/application/qa_mapping.py @@ -36,9 +36,9 @@ def extract_questions_and_answers(forms, language) -> dict: questions_answers[form_name][field["title"]] = answer elif isinstance(answer, bool) and field["type"] == "list": - + yes = "Yes" if language == "en" else "Oes" - no = "No" if language == "en" else "Nac Oes" + no = "No" if language == "en" else "Nac Oes" questions_answers[form_name][field["title"]] = ( yes if answer else no ) From 5c247fd2282b62460e52f595362810c173dc7f9c Mon Sep 17 00:00:00 2001 From: FSD Github Actions Date: Fri, 15 Mar 2024 15:28:14 +0000 Subject: [PATCH 3/9] Update version to 2.0.43 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ab3dc46..0125986 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "funding-service-design-utils" -version = "2.0.42" +version = "2.0.43" authors = [ { name="DLUHC", email="FundingServiceDesignTeam@levellingup.gov.uk" }, From 15f31d65910b5b6df5abb93887965582ec697379 Mon Sep 17 00:00:00 2001 From: Adam Davies Date: Fri, 15 Mar 2024 16:02:33 +0000 Subject: [PATCH 4/9] adding default value --- fsd_utils/mapping/application/qa_mapping.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsd_utils/mapping/application/qa_mapping.py b/fsd_utils/mapping/application/qa_mapping.py index 4e9e3c4..2be5505 100644 --- a/fsd_utils/mapping/application/qa_mapping.py +++ b/fsd_utils/mapping/application/qa_mapping.py @@ -10,7 +10,7 @@ from fsd_utils.mapping.application.multi_input import MultiInput -def extract_questions_and_answers(forms, language) -> dict: +def extract_questions_and_answers(forms, language="en") -> dict: """function takes the form data and returns dict of questions & answers. """ From 9d91512c0c5c4e8f6513125aaf83b4e28392e8c9 Mon Sep 17 00:00:00 2001 From: Adam Davies Date: Mon, 18 Mar 2024 10:31:15 +0000 Subject: [PATCH 5/9] Adding welsh test and lunch json testing options --- .vscode/launch.json | 18 +++++++++++++- tests/test_data_utils.py | 40 +++++++++++++++++++++++++++++++ tests/test_mapping_application.py | 8 +++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index e60dafe..4c70aa3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -31,6 +31,22 @@ "${file}" ], "justMyCode": false - } + }, + { + "name": "Run Tests: Current Function (debug)", + "type": "python", + "request": "launch", + "module": "pytest", + "console": "integratedTerminal", + "cwd": "${workspaceFolder}", + "envFile": "${workspaceFolder}/.env.development", + "args": [ + "-c", + "pytest.ini", + "-k", + "test_extract_questions_and_answers_welsh" // modify this accordingly + ], + "justMyCode": false + } ] } diff --git a/tests/test_data_utils.py b/tests/test_data_utils.py index 4ca6390..04542d2 100644 --- a/tests/test_data_utils.py +++ b/tests/test_data_utils.py @@ -248,6 +248,12 @@ def test_get_remote_data_json_404(self, flask_test_client): "key": "XsAoTv", "title": "Capital costs", "type": "multiInput", + }, + { + "key": "SxkwhF", + "type": "list", + "title": "Does your organisation have any alternative names?", + "answer": True } ], "question": "Capital funding", @@ -273,6 +279,7 @@ def test_get_remote_data_json_404(self, flask_test_client): "When did you start providing day provision?": "March 2023", "Revenue costs": "Test Funding Required NS Form \n . 40\n . 1 April 2023 to 31 March 2024\n . Not provided", # noqa "Capital costs": "Test Funding Required NS Form \n . 50\n . 1 April 2024 to 31 March 2025", + "Does your organisation have any alternative names?": "Yes", } }, "incorrect_form_data": [ @@ -296,6 +303,39 @@ def test_get_remote_data_json_404(self, flask_test_client): "exception_message": ("Could not map the data for form: applicant-information-ns"), } +test_data_sort_questions_answers_welsh = { + "forms": [ + { + "name": "test_form", + "questions": [ + { + "fields": [ + { + "key": "SxkwhF", + "type": "list", + "title": "Os ydych yn llwyddiannus, a wnewch chi ddefnyddio eich cyllid o fewn y 12 mis nesaf?", + "answer": True + }, + { + "key": "SxkwhF", + "type": "list", + "title": "A ydych wedi sicrhau unrhyw gyllid cydweddu eto?", + "answer": False + } + ], + "question": "Capital funding", + }, + ], + } + ], + "questions_answers": { + "test_form": { + "Os ydych yn llwyddiannus, a wnewch chi ddefnyddio eich cyllid o fewn y 12 mis nesaf?": "Oes", + "A ydych wedi sicrhau unrhyw gyllid cydweddu eto?": "Nac Oes", + } + } +} + iso_and_nested_data = { "input_data": [ diff --git a/tests/test_mapping_application.py b/tests/test_mapping_application.py index 7d6a210..88a714c 100644 --- a/tests/test_mapping_application.py +++ b/tests/test_mapping_application.py @@ -12,6 +12,7 @@ from fsd_utils.mapping.application.qa_mapping import extract_questions_and_answers from tests.test_data_utils import multi_input_test_data from tests.test_data_utils import test_data_sort_questions_answers +from tests.test_data_utils import test_data_sort_questions_answers_welsh @pytest.mark.parametrize( @@ -131,6 +132,13 @@ def test_extract_questions_and_answers(app_context): response = extract_questions_and_answers(forms) assert response == test_data_sort_questions_answers["questions_answers"] + +def test_extract_questions_and_answers_welsh(app_context): + forms = test_data_sort_questions_answers_welsh["forms"] + + response = extract_questions_and_answers(forms, "cy") + assert response == test_data_sort_questions_answers_welsh["questions_answers"] + def test_extract_questions_and_answers_fail(app_context): forms = test_data_sort_questions_answers["incorrect_form_data"] From d464bd54c0b8b40d41c32cd5e73f6d290751eb9b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:31:39 +0000 Subject: [PATCH 6/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_data_utils.py | 16 ++++++++-------- tests/test_mapping_application.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_data_utils.py b/tests/test_data_utils.py index 04542d2..75711f7 100644 --- a/tests/test_data_utils.py +++ b/tests/test_data_utils.py @@ -253,8 +253,8 @@ def test_get_remote_data_json_404(self, flask_test_client): "key": "SxkwhF", "type": "list", "title": "Does your organisation have any alternative names?", - "answer": True - } + "answer": True, + }, ], "question": "Capital funding", }, @@ -309,19 +309,19 @@ def test_get_remote_data_json_404(self, flask_test_client): "name": "test_form", "questions": [ { - "fields": [ + "fields": [ { "key": "SxkwhF", "type": "list", "title": "Os ydych yn llwyddiannus, a wnewch chi ddefnyddio eich cyllid o fewn y 12 mis nesaf?", - "answer": True + "answer": True, }, { "key": "SxkwhF", "type": "list", "title": "A ydych wedi sicrhau unrhyw gyllid cydweddu eto?", - "answer": False - } + "answer": False, + }, ], "question": "Capital funding", }, @@ -329,11 +329,11 @@ def test_get_remote_data_json_404(self, flask_test_client): } ], "questions_answers": { - "test_form": { + "test_form": { "Os ydych yn llwyddiannus, a wnewch chi ddefnyddio eich cyllid o fewn y 12 mis nesaf?": "Oes", "A ydych wedi sicrhau unrhyw gyllid cydweddu eto?": "Nac Oes", } - } + }, } diff --git a/tests/test_mapping_application.py b/tests/test_mapping_application.py index 88a714c..2c936ec 100644 --- a/tests/test_mapping_application.py +++ b/tests/test_mapping_application.py @@ -132,7 +132,7 @@ def test_extract_questions_and_answers(app_context): response = extract_questions_and_answers(forms) assert response == test_data_sort_questions_answers["questions_answers"] - + def test_extract_questions_and_answers_welsh(app_context): forms = test_data_sort_questions_answers_welsh["forms"] From e1de80efa99ac0c7d6e3eac67927a8ea81a63923 Mon Sep 17 00:00:00 2001 From: Adam Davies Date: Mon, 18 Mar 2024 10:49:10 +0000 Subject: [PATCH 7/9] Fixing flake8 error --- tests/test_data_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_data_utils.py b/tests/test_data_utils.py index 75711f7..d9d16af 100644 --- a/tests/test_data_utils.py +++ b/tests/test_data_utils.py @@ -275,7 +275,8 @@ def test_get_remote_data_json_404(self, flask_test_client): "Revenue for 1 April 2024 to 31 March 2025": "4020", "Capital for 1 April 2023 to 31 March 2024": "1230", "Capital for 1 April 2024 to 31 March 2025": "1230", - "Which membership organisations are you a member of?": "Homeless link", + "Which membership organisations are you a member of?": + "Homeless link", "When did you start providing day provision?": "March 2023", "Revenue costs": "Test Funding Required NS Form \n . 40\n . 1 April 2023 to 31 March 2024\n . Not provided", # noqa "Capital costs": "Test Funding Required NS Form \n . 50\n . 1 April 2024 to 31 March 2025", From 3e9c97422e310034033debf3b7046acde9a99b6c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:51:22 +0000 Subject: [PATCH 8/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_data_utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_data_utils.py b/tests/test_data_utils.py index d9d16af..75711f7 100644 --- a/tests/test_data_utils.py +++ b/tests/test_data_utils.py @@ -275,8 +275,7 @@ def test_get_remote_data_json_404(self, flask_test_client): "Revenue for 1 April 2024 to 31 March 2025": "4020", "Capital for 1 April 2023 to 31 March 2024": "1230", "Capital for 1 April 2024 to 31 March 2025": "1230", - "Which membership organisations are you a member of?": - "Homeless link", + "Which membership organisations are you a member of?": "Homeless link", "When did you start providing day provision?": "March 2023", "Revenue costs": "Test Funding Required NS Form \n . 40\n . 1 April 2023 to 31 March 2024\n . Not provided", # noqa "Capital costs": "Test Funding Required NS Form \n . 50\n . 1 April 2024 to 31 March 2025", From b5a36a9627ecc20f725813911678f6b0fa399ae4 Mon Sep 17 00:00:00 2001 From: Adam Davies Date: Mon, 18 Mar 2024 11:18:20 +0000 Subject: [PATCH 9/9] Adding long line ignore for test data --- tests/test_data_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_data_utils.py b/tests/test_data_utils.py index 75711f7..2e62f8c 100644 --- a/tests/test_data_utils.py +++ b/tests/test_data_utils.py @@ -1,3 +1,4 @@ +# flake8: noqa: E501 import pytest from fsd_utils.simple_utils.data_utils import get_remote_data_as_json from requests.exceptions import HTTPError