Skip to content

Commit

Permalink
[#2657] fix incorrect command invocation for failing mail digest task
Browse files Browse the repository at this point in the history
  • Loading branch information
swrichards committed Aug 7, 2024
1 parent 84b589f commit 7d7e0ec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 4 additions & 4 deletions src/open_inwoner/configurations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
32 changes: 24 additions & 8 deletions src/open_inwoner/configurations/tests/test_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")

0 comments on commit 7d7e0ec

Please sign in to comment.