Skip to content

Commit 4ba2c9f

Browse files
authored
Merge pull request #1139 from alphagov/2126-detailed-reminders-email-mondays
2126: Send detailed case reminder emails only on Mondays
2 parents 53d55e7 + 25f9499 commit 4ba2c9f

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

accessibility_monitoring_platform/apps/notifications/management/commands/send_reminders_email.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
import os
44

55
from django.core.management.base import BaseCommand
6+
from django.utils import timezone
7+
68
from ...utils import email_all_specialists_all_detailed_reminders_due
79

10+
DAY_OF_WEEK_MONDAY: int = 0
11+
812

913
class Command(BaseCommand):
1014
def handle(self, *args, **options): # pylint: disable=unused-argument
11-
if os.getenv("COPILOT_ENVIRONMENT_NAME") == "prodenv":
15+
if (
16+
os.getenv("COPILOT_ENVIRONMENT_NAME") == "prodenv"
17+
and timezone.now().weekday() == DAY_OF_WEEK_MONDAY
18+
):
1219
email_all_specialists_all_detailed_reminders_due()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Test for send_reminders_email command which should only email the users on a Monday.
3+
"""
4+
5+
import os
6+
from datetime import datetime, timezone
7+
from unittest.mock import Mock, patch
8+
9+
import pytest
10+
from django.core.management import call_command
11+
12+
MONDAY: datetime = datetime(2025, 11, 10, 2, 0, 0, tzinfo=timezone.utc)
13+
TUESDAY: datetime = datetime(2025, 11, 11, 2, 0, 0, tzinfo=timezone.utc)
14+
WEDNESDAY: datetime = datetime(2025, 11, 12, 2, 0, 0, tzinfo=timezone.utc)
15+
THURSDAY: datetime = datetime(2025, 11, 13, 2, 0, 0, tzinfo=timezone.utc)
16+
FRIDAY: datetime = datetime(2025, 11, 14, 2, 0, 0, tzinfo=timezone.utc)
17+
SATURDAY: datetime = datetime(2025, 11, 15, 2, 0, 0, tzinfo=timezone.utc)
18+
SUNDAY: datetime = datetime(2025, 11, 16, 2, 0, 0, tzinfo=timezone.utc)
19+
20+
21+
@pytest.mark.parametrize(
22+
"call_time, expected_to_call",
23+
[
24+
(MONDAY, True),
25+
(TUESDAY, False),
26+
(TUESDAY, False),
27+
(WEDNESDAY, False),
28+
(THURSDAY, False),
29+
(FRIDAY, False),
30+
(SATURDAY, False),
31+
(SUNDAY, False),
32+
],
33+
)
34+
@pytest.mark.django_db
35+
def test_send_reminders_email_only_called_monday(call_time, expected_to_call):
36+
"""Test send_reminders_email only calls init_int_test_data can be called"""
37+
os.environ["COPILOT_ENVIRONMENT_NAME"] = "prodenv"
38+
mock_email_all_specialists_all_detailed_reminders_due: Mock = Mock()
39+
with patch(
40+
"django.utils.timezone.now",
41+
Mock(return_value=call_time),
42+
):
43+
with patch(
44+
"accessibility_monitoring_platform.apps.notifications.management.commands.send_reminders_email.email_all_specialists_all_detailed_reminders_due",
45+
mock_email_all_specialists_all_detailed_reminders_due,
46+
):
47+
call_command("send_reminders_email")
48+
49+
if expected_to_call is True:
50+
mock_email_all_specialists_all_detailed_reminders_due.assert_called_once()
51+
else:
52+
mock_email_all_specialists_all_detailed_reminders_due.assert_not_called()

0 commit comments

Comments
 (0)