From cb09842886b71592f5e1990d7975db52b569358f Mon Sep 17 00:00:00 2001 From: rikuke <33894149+rikuke@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:24:50 +0200 Subject: [PATCH] Hl 1533 ahjo title (#3541) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: remove comma after "täydennys" * fix: longer public title length in ahjo payload --- .../applications/services/ahjo_payload.py | 30 ++++++++++++------- .../benefit/applications/tests/conftest.py | 4 +-- .../applications/tests/test_ahjo_payload.py | 16 ++++++---- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/backend/benefit/applications/services/ahjo_payload.py b/backend/benefit/applications/services/ahjo_payload.py index da8d4ee8d0..0e933d85dc 100644 --- a/backend/benefit/applications/services/ahjo_payload.py +++ b/backend/benefit/applications/services/ahjo_payload.py @@ -78,17 +78,17 @@ class UpdateRecordsRecordTitle(AhjoTitle): A class for creating the title of an update record. Inherits from AhjoTitle. Uses the application's modification date and application number to format the title. - The prefix is set to ", täydennys," by default. + The prefix is set to ", täydennys" by default. Attributes: - prefix (str): A default string ", täydennys," that is used in the title of update records. + prefix (str): A default string ", täydennys" that is used in the title of update records. attachment_created_at (datetime): The created_at date of the attachment that is being updated to Ahjo. Methods: __str__(): Returns the formatted string representation of the update record title. """ - prefix: str = field(default=", täydennys,") + prefix: str = field(default=", täydennys") attachment_created_at: datetime = None def __str__(self): @@ -121,7 +121,7 @@ class AddRecordsRecordTitle(AhjoTitle): __str__(): Returns the formatted string representation of the additional record title. """ - prefix: str = field(default=", täydennys,") + prefix: str = field(default=", täydennys") attachment_created_at: datetime = None def __str__(self): @@ -190,7 +190,7 @@ def prepare_case_title(application: Application, company_name: str) -> str: def prepare_final_case_title(application: Application, limit: int = 150) -> str: - """Prepare the final case title for Ahjo, if the full title is over 150 characters, \ + """Prepare the final case title for Ahjo, if the full title length is over the given limit, \ truncate the company name to fit the limit.""" full_case_title = prepare_case_title(application, application.company.name) length_of_full_title = len(full_case_title) @@ -230,7 +230,10 @@ def resolve_payload_language(application: Application) -> str: def _prepare_top_level_dict( - application: Application, case_records: List[dict], case_title: str + application: Application, + case_records: List[dict], + public_case_title: str, + internal_case_title: str, ) -> dict: """Prepare the dictionary that is sent to Ahjo""" @@ -242,13 +245,13 @@ def _prepare_top_level_dict( handler = application.calculation.handler case_dict = { - "Title": case_title, + "Title": public_case_title, "Acquired": application_date.isoformat("T", "seconds"), "ClassificationCode": "02 05 01 00", "ClassificationTitle": "Kunnan myöntämät avustukset", "Language": resolve_payload_language(application), "PublicityClass": "Julkinen", - "InternalTitle": case_title, + "InternalTitle": internal_case_title, "Subjects": [ {"Subject": "Helsinki-lisät", "Scheme": "hki-yhpa"}, {"Subject": "kunnan myöntämät avustukset", "Scheme": "hki-yhpa"}, @@ -395,8 +398,15 @@ def prepare_open_case_payload( ) -> dict: "Prepare the complete dictionary payload that is sent to Ahjo" case_records = _prepare_case_records(application, pdf_summary) - case_title = prepare_final_case_title(application) - payload = _prepare_top_level_dict(application, case_records, case_title) + public_case_title = prepare_final_case_title(application=application, limit=512) + internal_case_title = prepare_final_case_title(application=application, limit=150) + + payload = _prepare_top_level_dict( + application=application, + case_records=case_records, + public_case_title=public_case_title, + internal_case_title=internal_case_title, + ) return payload diff --git a/backend/benefit/applications/tests/conftest.py b/backend/benefit/applications/tests/conftest.py index 68167662da..ae36dce9b8 100755 --- a/backend/benefit/applications/tests/conftest.py +++ b/backend/benefit/applications/tests/conftest.py @@ -425,13 +425,13 @@ def ahjo_open_case_top_level_dict(decided_application): handler = application.calculation.handler return { - "Title": "message title", + "Title": "a" * 512, "Acquired": application.created_at.isoformat(), "ClassificationCode": "02 05 01 00", "ClassificationTitle": "Kunnan myöntämät avustukset", "Language": language, "PublicityClass": "Julkinen", - "InternalTitle": "message title", + "InternalTitle": "a" * 150, "Subjects": [ {"Subject": "Helsinki-lisät", "Scheme": "hki-yhpa"}, {"Subject": "kunnan myöntämät avustukset", "Scheme": "hki-yhpa"}, diff --git a/backend/benefit/applications/tests/test_ahjo_payload.py b/backend/benefit/applications/tests/test_ahjo_payload.py index dd332e69e6..b4cafe05ee 100644 --- a/backend/benefit/applications/tests/test_ahjo_payload.py +++ b/backend/benefit/applications/tests/test_ahjo_payload.py @@ -75,7 +75,7 @@ def test_update_records_record_title_str(): application=mock_app, attachment_created_at=attachment_created_at ) result = str(update_records_title) - expected = f"{AhjoRecordTitle.APPLICATION}, täydennys, 25.02.2023, 67890" + expected = f"{AhjoRecordTitle.APPLICATION}, täydennys 25.02.2023, 67890" assert result == expected @@ -90,7 +90,7 @@ def test_add_records_record_title_str(): application=mock_app, attachment_created_at=attachment_created_at ) result = str(add_records_title) - expected = f"{AhjoRecordTitle.APPLICATION}, täydennys, 10.03.2023, 54321" + expected = f"{AhjoRecordTitle.APPLICATION}, täydennys 10.03.2023, 54321" assert result == expected @@ -141,6 +141,8 @@ def test_truncate_string_to_limit( ("a" * 100, 100, 150), ("a" * 50, 100, 150), ("1234567890AB", 10, 150), + # 256 characters is the maximun length for the company name in the database + ("a" * 256, 512, 512), ], ) def test_prepare_final_case_title_truncate( @@ -169,7 +171,7 @@ def test_prepare_final_case_title_truncate( AhjoRecordTitle.APPLICATION, AhjoRecordType.APPLICATION, AhjoRequestType.UPDATE_APPLICATION, - ", täydennys,", + ", täydennys", 0, 0, ), @@ -178,7 +180,7 @@ def test_prepare_final_case_title_truncate( AhjoRecordTitle.APPLICATION, AhjoRecordType.ATTACHMENT, AhjoRequestType.ADD_RECORDS, - ", täydennys,", + ", täydennys", 0, 0, ), @@ -370,8 +372,12 @@ def test_prepare_case_records(decided_application, settings): def test_prepare_top_level_dict(decided_application, ahjo_open_case_top_level_dict): application = Application.objects.get(pk=decided_application.pk) + long_title = "a" * 512 + short_title = "a" * 150 - got = _prepare_top_level_dict(application, [], "message title") + got = _prepare_top_level_dict( + application, [], public_case_title=long_title, internal_case_title=short_title + ) assert ahjo_open_case_top_level_dict == got