diff --git a/fsd_utils/mapping/application/application_utils.py b/fsd_utils/mapping/application/application_utils.py index 4d7cb60..980347f 100644 --- a/fsd_utils/mapping/application/application_utils.py +++ b/fsd_utils/mapping/application/application_utils.py @@ -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 @@ -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: @@ -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( diff --git a/fsd_utils/mapping/application/multi_input.py b/fsd_utils/mapping/application/multi_input.py index 2206841..cc548f5 100644 --- a/fsd_utils/mapping/application/multi_input.py +++ b/fsd_utils/mapping/application/multi_input.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 3fe40f3..e65f8b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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="FundingServiceDesignTeam@levellingup.gov.uk" }, ] diff --git a/tests/test_data_utils.py b/tests/test_data_utils.py index d41427a..236de2a 100644 --- a/tests/test_data_utils.py +++ b/tests/test_data_utils.py @@ -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": { @@ -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": [ @@ -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?", }, @@ -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", @@ -220,6 +226,7 @@ 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", @@ -227,7 +234,7 @@ def test_get_remote_data_json_404(self, flask_test_client): "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 } },