diff --git a/tests/test_integrations/test_email/test_email_service.py b/tests/test_integrations/test_email/test_email_service.py index 76c8badb9..33b9f8daa 100644 --- a/tests/test_integrations/test_email/test_email_service.py +++ b/tests/test_integrations/test_email/test_email_service.py @@ -4,7 +4,7 @@ from django.test import override_settings from freezegun import freeze_time -from tests.factories import ApplicationFactory, ReservationFactory, UnitFactory, UserFactory +from tests.factories import ApplicationFactory, ApplicationRoundFactory, ReservationFactory, UnitFactory, UserFactory from tests.helpers import TranslationsFromPOFiles, patch_method from tilavarauspalvelu.enums import Language, ReservationNotification, ReservationStateChoice, ReservationTypeChoice from tilavarauspalvelu.integrations.email.main import EmailService @@ -104,7 +104,8 @@ def test_email_service__send_application_in_allocation_emails__no_recipients(out @override_settings(SEND_EMAILS=True) def test_email_service__send_application_handled_emails(outbox): - application = ApplicationFactory.create_in_status_handled() + application_round = ApplicationRoundFactory.create_in_status_results_sent() + application = ApplicationFactory.create_in_status_handled(application_round=application_round) EmailService.send_application_handled_emails() @@ -116,8 +117,15 @@ def test_email_service__send_application_handled_emails(outbox): @override_settings(SEND_EMAILS=True) def test_email_service__send_application_handled_emails__multiple_languages(outbox): - application_1 = ApplicationFactory.create_in_status_handled(user__preferred_language="fi") - application_2 = ApplicationFactory.create_in_status_handled(user__preferred_language="en") + application_round = ApplicationRoundFactory.create_in_status_results_sent() + application_1 = ApplicationFactory.create_in_status_handled( + application_round=application_round, + user__preferred_language="fi", + ) + application_2 = ApplicationFactory.create_in_status_handled( + application_round=application_round, + user__preferred_language="en", + ) with TranslationsFromPOFiles(): EmailService.send_application_handled_emails() @@ -134,7 +142,7 @@ def test_email_service__send_application_handled_emails__multiple_languages(outb @override_settings(SEND_EMAILS=True) @patch_method(SentryLogger.log_message) def test_email_service__send_application_handled_emails__wrong_status(outbox): - ApplicationFactory.create_in_status_in_allocation() + ApplicationFactory.create_in_status_handled() EmailService.send_application_handled_emails() @@ -149,7 +157,10 @@ def test_email_service__send_application_handled_emails__wrong_status(outbox): @override_settings(SEND_EMAILS=True) @patch_method(SentryLogger.log_message) def test_email_service__send_application_handled_emails__no_recipients(outbox): - ApplicationFactory.create_in_status_handled(user__email="", contact_person__email="") + application_round = ApplicationRoundFactory.create_in_status_results_sent() + ApplicationFactory.create_in_status_handled( + application_round=application_round, user__email="", contact_person__email="" + ) EmailService.send_application_handled_emails() diff --git a/tilavarauspalvelu/models/application/queryset.py b/tilavarauspalvelu/models/application/queryset.py index eccec1935..8b4893804 100644 --- a/tilavarauspalvelu/models/application/queryset.py +++ b/tilavarauspalvelu/models/application/queryset.py @@ -9,10 +9,9 @@ from helsinki_gdpr.models import SerializableMixin from lookup_property import L -from tilavarauspalvelu.enums import ApplicationRoundStatusChoice, ApplicationSectionStatusChoice +from tilavarauspalvelu.enums import ApplicationRoundStatusChoice, ApplicationStatusChoice if TYPE_CHECKING: - from tilavarauspalvelu.enums import ApplicationStatusChoice from tilavarauspalvelu.models import Application @@ -110,7 +109,7 @@ def should_send_in_allocation_email(self) -> Self: """Get all applications that need the "application in allocation" notification to be sent.""" return self.filter( L(application_round__status=ApplicationRoundStatusChoice.IN_ALLOCATION.value), - L(status=ApplicationSectionStatusChoice.IN_ALLOCATION.value), + L(status=ApplicationStatusChoice.IN_ALLOCATION.value), in_allocation_notification_sent_date__isnull=True, application_sections__isnull=False, ) @@ -118,8 +117,8 @@ def should_send_in_allocation_email(self) -> Self: def should_send_handled_email(self) -> Self: """Get all applications that need the "application handled" notification to be sent.""" return self.filter( - L(application_round__status=ApplicationRoundStatusChoice.HANDLED.value), - L(status=ApplicationSectionStatusChoice.HANDLED.value), + L(application_round__status=ApplicationRoundStatusChoice.RESULTS_SENT.value), + L(status=ApplicationStatusChoice.RESULTS_SENT.value), results_ready_notification_sent_date__isnull=True, application_sections__isnull=False, )