diff --git a/src/open_inwoner/conf/base.py b/src/open_inwoner/conf/base.py index 9bbf3ae0ae..ac3360447b 100644 --- a/src/open_inwoner/conf/base.py +++ b/src/open_inwoner/conf/base.py @@ -693,7 +693,7 @@ "schedule": crontab(minute="0", hour="4", day_of_month="*"), }, "Dagelijkse misluke email samenvatting": { - "task": "open_inwoner.configurations.tasks.send_failed_email_digest", + "task": "open_inwoner.configurations.tasks.send_failed_mail_digest", "schedule": crontab(minute="0", hour="7", day_of_month="*"), }, "Probeer emails opnieuw te sturen": { diff --git a/src/open_inwoner/configurations/tasks.py b/src/open_inwoner/configurations/tasks.py index 595f1a232d..1cf6cb0a9b 100644 --- a/src/open_inwoner/configurations/tasks.py +++ b/src/open_inwoner/configurations/tasks.py @@ -8,9 +8,9 @@ @app.task -def send_failed_email_digest(): - logger.info("starting send_failed_email_digest() task") +def send_failed_mail_digest(): + logger.info("starting send_failed_mail_digest() task") - call_command("send_failed_email_digest") + call_command("send_failed_mail_digest") - logger.info("finished send_failed_email_digest() task") + logger.info("finished send_failed_mail_digest() task") diff --git a/src/open_inwoner/configurations/tests/test_emails.py b/src/open_inwoner/configurations/tests/test_emails.py index c4589b8bb2..ce465ea21e 100644 --- a/src/open_inwoner/configurations/tests/test_emails.py +++ b/src/open_inwoner/configurations/tests/test_emails.py @@ -8,11 +8,12 @@ from django_yubin.models import Log from freezegun import freeze_time -from open_inwoner.configurations.tasks import send_failed_email_digest +from open_inwoner.configurations.tasks import send_failed_mail_digest from ..models import SiteConfiguration +@override_settings(CELERY_TASK_ALWAYS_EAGER=True) class DailyFailingEmailDigestTestCase(TestCase): def test_no_recipients_configured(self): config = SiteConfiguration.get_solo() @@ -91,12 +92,27 @@ def test_send_daily_failing_email_digest(self): self.assertIn("to@example.com", email.body) self.assertIn("1 januari 2024 13:00", email.body) + def test_task_triggers_sending_of_digest(self): + config = SiteConfiguration.get_solo() + config.recipients_email_digest = ["admin@localhost"] + config.save() -@override_settings(CELERY_TASK_ALWAYS_EAGER=True) -# Due to Celery's eager task discovery, we have to mock the imported -# call_command. -@mock.patch("open_inwoner.configurations.tasks.call_command") -class DailyFailingEmailDigestTaskTestCase(TestCase): + with freeze_time("2024-01-01T12:00:00"): + yubin_send_mail( + subject="Should show up in email", + from_email="from@example.com", + recipient_list=["to@example.com"], + message="test", + ) + + with freeze_time("2024-01-02T00:00:00"): + send_failed_mail_digest.delay() + + self.assertEqual(len(mail.outbox), 1) + + # Due to Celery's eager task discovery, we have to mock the imported + # call_command. + @mock.patch("open_inwoner.configurations.tasks.call_command") def test_task_invokes_management_command(self, m): - send_failed_email_digest.delay() - m.assert_called_once_with("send_failed_email_digest") + send_failed_mail_digest.delay() + m.assert_called_once_with("send_failed_mail_digest")