Skip to content

Commit 3c42f05

Browse files
authored
Merge pull request #791 from NHSDigital/DTOSS-remove-email-functionality
Remove email functionality for reporting
2 parents e97d319 + 663f67a commit 3c42f05

File tree

6 files changed

+6
-321
lines changed

6 files changed

+6
-321
lines changed

manage_breast_screening/config/.env.tpl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ BASIC_AUTH_PASSWORD=changeme
3131
# Notifications specific env vars
3232
NOTIFICATIONS_BATCH_RETRY_LIMIT=5
3333

34-
35-
NOTIFICATIONS_SMTP_PASSWORD=changeme
36-
37-
NOTIFICATIONS_SMTP_IS_ENABLED=False
38-
3934
API_OAUTH_API_KEY=""
4035
API_OAUTH_API_KID=""
4136
API_OAUTH_PRIVATE_KEY=""

manage_breast_screening/notifications/management/commands/create_reports.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from manage_breast_screening.notifications.models import ZONE_INFO
1212
from manage_breast_screening.notifications.queries.helper import Helper
1313
from manage_breast_screening.notifications.services.blob_storage import BlobStorage
14-
from manage_breast_screening.notifications.services.nhs_mail import NhsMail
1514

1615
logger = getLogger(__name__)
1716
INSIGHTS_JOB_NAME = "CreateReports"
@@ -24,12 +23,10 @@ def __init__(
2423
self,
2524
name: str,
2625
params: list,
27-
send_email: bool = False,
2826
query: str | None = None,
2927
):
3028
self.name = name
3129
self.params = params
32-
self.send_email = send_email
3330
self.query = query or name
3431

3532

@@ -44,12 +41,12 @@ class Command(BaseCommand):
4441
BSO_CODES = ["MBD"]
4542
REPORTS = [
4643
ReportConfig(
47-
"invites-not-sent", [datetime.now(tz=ZONE_INFO).date()], True, "failures"
44+
"invites-not-sent", [datetime.now(tz=ZONE_INFO).date()], "failures"
4845
),
49-
ReportConfig("reconciliation", ["3 months"], True),
46+
ReportConfig("reconciliation", ["3 months"]),
5047
]
5148
SMOKE_TEST_BSO_CODE = "SM0K3"
52-
SMOKE_TEST_CONFIG = ReportConfig("reconciliation", ["1 week"], False)
49+
SMOKE_TEST_CONFIG = ReportConfig("reconciliation", ["1 week"])
5350

5451
def add_arguments(self, parser):
5552
parser.add_argument("--smoke-test", action="store_true")
@@ -59,7 +56,6 @@ def handle(self, *args, **options):
5956
logger.info("Create Report Command started")
6057

6158
bso_codes, report_configs = self.configuration(options)
62-
external_reports = {}
6359

6460
for bso_code in bso_codes:
6561
for report_config in report_configs:
@@ -74,15 +70,8 @@ def handle(self, *args, **options):
7470

7571
BlobStorage().add(filename, csv, content_type="text/csv")
7672

77-
if report_config.send_email:
78-
external_reports[filename] = csv
79-
8073
logger.info("Report %s created", report_config.name)
8174

82-
if bool(external_reports):
83-
NhsMail().send_reports_email(external_reports)
84-
logger.info(f"Reports sent: {', '.join(external_reports.keys())}")
85-
8675
def configuration(self, options: dict) -> tuple[list[str], list[ReportConfig]]:
8776
if options.get("smoke_test", False):
8877
bso_codes = [self.SMOKE_TEST_BSO_CODE]

manage_breast_screening/notifications/services/nhs_mail.py

Lines changed: 0 additions & 91 deletions
This file was deleted.

manage_breast_screening/notifications/templates/report_emails/reports.html

Lines changed: 0 additions & 11 deletions
This file was deleted.

manage_breast_screening/notifications/tests/management/commands/test_create_reports.py

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from manage_breast_screening.notifications.management.commands.create_reports import (
1010
Command,
11-
ReportConfig,
1211
)
1312
from manage_breast_screening.notifications.queries.helper import Helper
1413

@@ -38,11 +37,7 @@ def mocked_dependencies(self, dataframe, csv_data, now):
3837
with patch(f"{Command.__module__}.datetime") as mock_datetime:
3938
mock_datetime.today.return_value = now
4039

41-
with patch(f"{Command.__module__}.NhsMail") as mock_email:
42-
mock_email_service = MagicMock()
43-
mock_email.return_value = mock_email_service
44-
45-
yield (mock_read_sql, mock_blob_storage, mock_email_service)
40+
yield (mock_read_sql, mock_blob_storage)
4641

4742
@pytest.fixture
4843
def dataframe(self, csv_data):
@@ -54,11 +49,10 @@ def test_handle_creates_all_reports(self, dataframe, csv_data, now):
5449
with self.mocked_dependencies(dataframe, csv_data, now) as md:
5550
Command().handle()
5651

57-
mock_read_sql, mock_blob_storage, mock_email_service = md
52+
mock_read_sql, mock_blob_storage = md
5853

5954
assert mock_read_sql.call_count == 2
6055
assert mock_blob_storage.add.call_count == 2
61-
assert mock_email_service.send_reports_email.call_count == 1
6256

6357
for bso_code in Command.BSO_CODES:
6458
mock_read_sql.assert_any_call(
@@ -82,13 +76,6 @@ def test_handle_creates_all_reports(self, dataframe, csv_data, now):
8276
content_type="text/csv",
8377
)
8478

85-
mock_email_service.send_reports_email.assert_called_once_with(
86-
{
87-
failures_filename: csv_data,
88-
reconciliation_filename: csv_data,
89-
}
90-
)
91-
9279
def test_handle_raises_command_error(self, mock_insights_logger):
9380
with patch(f"{Helper.__module__}.Helper") as mock_query:
9481
mock_query.sql.side_effect = Exception("err")
@@ -127,7 +114,7 @@ def test_smoke_test_argument_uses_correct_configuration(
127114
with self.mocked_dependencies(dataframe, csv_data, now) as md:
128115
Command().handle(**{"smoke_test": True})
129116

130-
mock_read_sql, mock_blob_storage, mock_email_service = md
117+
mock_read_sql, mock_blob_storage = md
131118

132119
mock_read_sql.assert_called_once_with(
133120
Helper.sql("reconciliation"), connection, params=["1 week", "SM0K3"]
@@ -137,71 +124,3 @@ def test_smoke_test_argument_uses_correct_configuration(
137124
csv_data,
138125
content_type="text/csv",
139126
)
140-
mock_email_service.assert_not_called()
141-
142-
def test_handle_does_not_email_reports_with_send_email_false(
143-
self, dataframe, csv_data, now, monkeypatch
144-
):
145-
"""
146-
Test that internal reports are not emailed but still stored.
147-
"""
148-
test_reports = [
149-
ReportConfig("external-report", [now.date()], True),
150-
ReportConfig("internal-report", [now.date()], False),
151-
]
152-
monkeypatch.setattr(Command, "REPORTS", test_reports)
153-
154-
with patch(f"{Helper.__module__}.Helper.sql") as mock_helper_sql:
155-
mock_helper_sql.return_value = "SELECT 1"
156-
157-
with self.mocked_dependencies(dataframe, csv_data, now) as md:
158-
Command().handle()
159-
160-
mock_read_sql, mock_blob_storage, mock_email_service = md
161-
162-
assert mock_read_sql.call_count == 2
163-
assert mock_blob_storage.add.call_count == 2
164-
assert mock_email_service.send_reports_email.call_count == 1
165-
166-
internal_filename = (
167-
f"{now.strftime('%Y-%m-%dT%H:%M:%S')}-MBD-internal-report-report.csv"
168-
)
169-
external_filename = (
170-
f"{now.strftime('%Y-%m-%dT%H:%M:%S')}-MBD-external-report-report.csv"
171-
)
172-
mock_blob_storage.add.assert_any_call(
173-
internal_filename,
174-
csv_data,
175-
content_type="text/csv",
176-
)
177-
mock_blob_storage.add.assert_any_call(
178-
external_filename,
179-
csv_data,
180-
content_type="text/csv",
181-
)
182-
183-
mock_email_service.send_reports_email.assert_called_once_with(
184-
{external_filename: csv_data}
185-
)
186-
187-
def test_handle_with_internal_reports_does_not_call_email_service(
188-
self, dataframe, csv_data, now, monkeypatch
189-
):
190-
"""
191-
Test that internal reports are not emailed but still stored.
192-
"""
193-
monkeypatch.setattr(
194-
Command, "REPORTS", [ReportConfig("internal-report", [1], False)]
195-
)
196-
197-
with patch(f"{Helper.__module__}.Helper.sql") as mock_helper_sql:
198-
mock_helper_sql.return_value = "SELECT 1"
199-
200-
with self.mocked_dependencies(dataframe, csv_data, now) as md:
201-
Command().handle()
202-
203-
mock_read_sql, mock_blob_storage, mock_email_service = md
204-
205-
assert mock_read_sql.call_count == 1
206-
assert mock_blob_storage.add.call_count == 1
207-
assert mock_email_service.send_reports_email.call_count == 0

0 commit comments

Comments
 (0)