Skip to content

Commit

Permalink
Merge pull request #131 from communitiesuk/FS-2940
Browse files Browse the repository at this point in the history
FS-2940 - Fix yes no appearing only in English
  • Loading branch information
adamdavies1 authored Mar 18, 2024
2 parents e4e69e6 + b5a36a9 commit 5f2ef38
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
18 changes: 17 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
6 changes: 4 additions & 2 deletions fsd_utils/mapping/application/qa_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="en") -> dict:
"""function takes the form data and returns
dict of questions & answers.
"""
Expand All @@ -37,8 +37,10 @@ def extract_questions_and_answers(forms) -> dict:

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":
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]" },
Expand Down
43 changes: 42 additions & 1 deletion tests/test_data_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -248,7 +249,13 @@ 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",
},
Expand All @@ -273,6 +280,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": [
Expand All @@ -296,6 +304,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": [
Expand Down
8 changes: 8 additions & 0 deletions tests/test_mapping_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -132,6 +133,13 @@ def test_extract_questions_and_answers(app_context):
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"]

Expand Down

0 comments on commit 5f2ef38

Please sign in to comment.