Skip to content

Commit

Permalink
Hl 1533 ahjo title (#3541)
Browse files Browse the repository at this point in the history
* fix: remove comma after "täydennys"

* fix: longer public title length in ahjo payload
  • Loading branch information
rikuke authored Nov 18, 2024
1 parent a4479bf commit cb09842
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
30 changes: 20 additions & 10 deletions backend/benefit/applications/services/ahjo_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"""

Expand All @@ -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"},
Expand Down Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions backend/benefit/applications/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
16 changes: 11 additions & 5 deletions backend/benefit/applications/tests/test_ahjo_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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


Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -169,7 +171,7 @@ def test_prepare_final_case_title_truncate(
AhjoRecordTitle.APPLICATION,
AhjoRecordType.APPLICATION,
AhjoRequestType.UPDATE_APPLICATION,
", täydennys,",
", täydennys",
0,
0,
),
Expand All @@ -178,7 +180,7 @@ def test_prepare_final_case_title_truncate(
AhjoRecordTitle.APPLICATION,
AhjoRecordType.ATTACHMENT,
AhjoRequestType.ADD_RECORDS,
", täydennys,",
", täydennys",
0,
0,
),
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit cb09842

Please sign in to comment.