Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FS-2878-bug-fix-none-value-should-return-pre-fixed-answer: #93

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions fsd_utils/mapping/application/application_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ def convert_bool_value(data):
try:

def convert_values(value):
if value is None:
if value is None or value == "None":
return "Not provided"
elif value is True:
return "Yes"
elif value is False:
return "No"
if isinstance(value, bool):
return "Yes" if value else "No"
else:
return value

Expand All @@ -35,7 +33,7 @@ def convert_values(value):

def format_answer(answer):
try:
if answer is None:
if answer is None or answer == "None":
return "Not provided"

if "null" in answer:
Expand Down Expand Up @@ -95,6 +93,8 @@ def format_radio_field(answer):
answer = answer.split("-")
formatted_answer = " ".join(answer).strip()
return formatted_answer
else:
return answer

except Exception: # noqa
current_app.logger.info(
Expand Down
20 changes: 4 additions & 16 deletions fsd_utils/mapping/application/multi_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,19 @@ def format_keys_and_values(cls, key: str, value: list, index: enumerate):
str: The formatted string representation of the key-value pair.
"""

def formatted_values(values):
return (
", ".join(
map(
str,
convert_bool_value([values])
if len(values) > 1
else convert_bool_value(values),
)
)
if isinstance(values, list)
else convert_bool_value(values)
)
sanitised_values = convert_bool_value(value)

values = "\n".join(
[
f"{cls.indent(6) if i == 1 else cls.indent(7)}. {str(item).strip()}"
for i, item in enumerate(value, start=1)
for i, item in enumerate(sanitised_values, start=1)
]
)

return (
f"\n{cls.indent(5)}* {str(key.strip())} \n {formatted_values(values)}" # noqa
f"\n{cls.indent(5)}* {str(key.strip())} \n {values}" # noqa
if index != 1
else (f"* {str(key.strip())} \n {formatted_values(values)}") # noqa
else (f"* {str(key.strip())} \n {values}") # noqa
)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "funding-service-design-utils"
version = "2.0.12"
version = "2.0.13"
authors = [
{ name="DLUHC", email="[email protected]" },
]
Expand Down
19 changes: 13 additions & 6 deletions tests/test_data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def test_get_remote_data_json_404(self, flask_test_client):
],
},
"expected_response": [
"* trusts one \n . 125\n . 1 April 2023 to 31 March 2024\n . Capital\n . True", # noqa
"\n * trust two \n . 456\n . 1 April 2024 to 31 March 2025\n . Revenue\n . False", # noqa
"* trusts one \n . 125\n . 1 April 2023 to 31 March 2024\n . Capital\n . Yes", # noqa
"\n * trust two \n . 456\n . 1 April 2024 to 31 March 2025\n . Revenue\n . No", # noqa
],
},
"single_value": {
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_get_remote_data_json_404(self, flask_test_client):
"sIFBGc": False,
},
],
"expected_response": "* trusts one \n . 125\n . 1 April 2023 to 31 March 2024\n . Capital\n . True\n\n * trust two \n . 456\n . 1 April 2024 to 31 March 2025\n . Revenue\n . False", # noqa
"expected_response": "* trusts one \n . 125\n . 1 April 2023 to 31 March 2024\n . Capital\n . Yes\n\n * trust two \n . 456\n . 1 April 2024 to 31 March 2025\n . Revenue\n . No", # noqa
},
"single_value": {
"input_data": [
Expand Down Expand Up @@ -125,7 +125,13 @@ def test_get_remote_data_json_404(self, flask_test_client):
"key": "NxVqXd",
"title": "What funding are you applying for?",
"type": "list",
}
},
{
"key": "NxVqXd",
"title": "What funding are you applying?",
"type": "list",
"answer": "capital",
},
],
"question": "What funding are you applying for?",
},
Expand Down Expand Up @@ -180,10 +186,10 @@ def test_get_remote_data_json_404(self, flask_test_client):
{
"answer": [
{
"TrTaZQ": "Test Funding Required NS Form",
"dpDFgB": "Test Funding Required NS Form",
"iZdZrr": 40,
"leIxEX": "1 April 2023 to 31 March 2024",
"TrTaZQ": "None",
}
],
"key": "mCbbyN",
Expand Down Expand Up @@ -220,14 +226,15 @@ def test_get_remote_data_json_404(self, flask_test_client):
"questions_answers": {
"funding-required-ns": {
"What funding are you applying for?": "both revenue and capital",
"What funding are you applying?": "capital",
"Both revenue and capital": "4020",
"Revenue for 1 April 2024 to 31 March 2025": "4020",
"Testing hyphen in field type text": "This-is-a-type-text-answer",
"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",
"When did you start providing day provision?": "March 2023",
"Revenue costs": "* Test Funding Required NS Form \n . Test Funding Required NS Form\n . 40\n . 1 April 2023 to 31 March 2024", # noqa
"Revenue costs": "* Test Funding Required NS Form \n . 40\n . 1 April 2023 to 31 March 2024\n . Not provided", # noqa
"Capital costs": "* 50 \n . Test Funding Required NS Form\n . 1 April 2024 to 31 March 2025\n . Test Funding Required NS Form", # noqa
}
},
Expand Down