From 6ba69ab03c582146bbdafcbd933d01d43f5a4ef1 Mon Sep 17 00:00:00 2001 From: rikuke <33894149+rikuke@users.noreply.github.com> Date: Fri, 14 Jun 2024 13:50:04 +0300 Subject: [PATCH] Hl 1361 missing full application (#3089) * fix: include full application in ahjo queries * chore: print application number if error in update --- backend/benefit/applications/models.py | 1 - .../applications/services/ahjo_payload.py | 4 +- .../benefit/applications/tests/conftest.py | 24 +++++++++- .../tests/test_ahjo_integration.py | 47 +++++++++++++++++++ 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/backend/benefit/applications/models.py b/backend/benefit/applications/models.py index 2f173ca9a6..8a195d6c2c 100755 --- a/backend/benefit/applications/models.py +++ b/backend/benefit/applications/models.py @@ -186,7 +186,6 @@ def get_by_statuses( # Excluded attachment types excluded_types = [ AttachmentType.PDF_SUMMARY, - AttachmentType.FULL_APPLICATION, AttachmentType.DECISION_TEXT_XML, AttachmentType.DECISION_TEXT_SECRET_XML, ] diff --git a/backend/benefit/applications/services/ahjo_payload.py b/backend/benefit/applications/services/ahjo_payload.py index ae09a8b0c9..1176c84a37 100644 --- a/backend/benefit/applications/services/ahjo_payload.py +++ b/backend/benefit/applications/services/ahjo_payload.py @@ -272,7 +272,9 @@ def prepare_update_application_payload( """Prepare the payload that is sent to Ahjo when an application is updated, \ in this case it only contains a Records dict""" if not pdf_summary.ahjo_version_series_id: - raise ValueError("Attachment must have an ahjo_version_series_id for update.") + raise ValueError( + f"Attachment for {application.application_number} must have a ahjo_version_series_id for update." + ) language = resolve_payload_language(application) return { "records": [ diff --git a/backend/benefit/applications/tests/conftest.py b/backend/benefit/applications/tests/conftest.py index 15f3523677..25413059f6 100755 --- a/backend/benefit/applications/tests/conftest.py +++ b/backend/benefit/applications/tests/conftest.py @@ -492,11 +492,31 @@ def pytest_sessionfinish(session, exitstatus): @pytest.fixture def application_with_ahjo_case_id(decided_application): - decided_application.ahjo_case_id = "HEL 2024 12345" - decided_application.save() + decided_application.ahjo_case_id = generate_ahjo_case_id() return decided_application +@pytest.fixture +def multiple_applications_with_ahjo_case_id( + mock_get_organisation_roles_and_create_company, +): + with factory.Faker.override_default_locale("fi_FI"): + applications = DecidedApplicationFactory.create_batch( + 5, company=mock_get_organisation_roles_and_create_company + ) + + for a in applications: + a.ahjo_case_id = generate_ahjo_case_id() + a.save() + return applications + + +def generate_ahjo_case_id(): + year = random.randint(2000, 2099) + case_id = random.randint(10000, 99999) + return f"HEL {year} {case_id}" + + @pytest.fixture def application_with_ahjo_decision(application_with_ahjo_case_id): template = AcceptedDecisionProposalFactory() diff --git a/backend/benefit/applications/tests/test_ahjo_integration.py b/backend/benefit/applications/tests/test_ahjo_integration.py index 7ea97c13d4..962389b415 100644 --- a/backend/benefit/applications/tests/test_ahjo_integration.py +++ b/backend/benefit/applications/tests/test_ahjo_integration.py @@ -716,6 +716,30 @@ def test_generate_ahjo_secret_decision_text_xml(decided_application): os.remove(attachment.attachment_file.path) +@pytest.mark.django_db +def test_get_applications_for_ahjo_update( + multiple_applications_with_ahjo_case_id, +): + for a in multiple_applications_with_ahjo_case_id: + AhjoStatus.objects.create( + application=a, + status=AhjoStatusEnum.DECISION_PROPOSAL_ACCEPTED, + ) + + applications_for_ahjo_update = Application.objects.get_by_statuses( + [ + ApplicationStatus.ACCEPTED, + ApplicationStatus.REJECTED, + ], + AhjoStatusEnum.DECISION_PROPOSAL_ACCEPTED, + False, + ) + + assert applications_for_ahjo_update.count() == len( + multiple_applications_with_ahjo_case_id + ) + + @pytest.mark.django_db def test_get_applications_for_open_case( multiple_decided_applications, @@ -745,6 +769,23 @@ def test_get_applications_for_open_case( ahjo_status.created_at = now + timedelta(days=index) ahjo_status.save() + wanted_open_case_attachments = [ + AttachmentType.EMPLOYMENT_CONTRACT, + AttachmentType.PAY_SUBSIDY_DECISION, + AttachmentType.COMMISSION_CONTRACT, + AttachmentType.EDUCATION_CONTRACT, + AttachmentType.HELSINKI_BENEFIT_VOUCHER, + AttachmentType.EMPLOYEE_CONSENT, + AttachmentType.OTHER_ATTACHMENT, + AttachmentType.FULL_APPLICATION, + ] + + unwanted_open_case_attachments = [ + AttachmentType.PDF_SUMMARY, + AttachmentType.DECISION_TEXT_XML, + AttachmentType.DECISION_TEXT_SECRET_XML, + ] + applications_for_open_case = Application.objects.get_by_statuses( [ ApplicationStatus.HANDLING, @@ -754,6 +795,12 @@ def test_get_applications_for_open_case( AhjoStatusEnum.SUBMITTED_BUT_NOT_SENT_TO_AHJO, True, ) + + for app in applications_for_open_case: + attachments = app.attachments.all() + for a in attachments: + assert a.attachment_type in wanted_open_case_attachments + assert a.attachment_type not in unwanted_open_case_attachments # only handled_applications should be returned as their last AhjoStatus is SUBMITTED_BUT_NOT_SENT_TO_AHJO # and their application status is HANDLING assert applications_for_open_case.count() == len(wanted_applications_for_open_case)