From 97b9d84c38e79db87c7528a5f9b73e963a4b2faa Mon Sep 17 00:00:00 2001 From: richard-dds Date: Wed, 15 May 2019 10:17:03 -0400 Subject: [PATCH] Select only recipient emails from the db --- atst/utils/notification_sender.py | 7 +++---- tests/utils/test_notification_sender.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/atst/utils/notification_sender.py b/atst/utils/notification_sender.py index 5567d000..0fdc31b0 100644 --- a/atst/utils/notification_sender.py +++ b/atst/utils/notification_sender.py @@ -1,4 +1,5 @@ from logging import Logger +from sqlalchemy import select from atst.queue import ATSTQueue from atst.database import db @@ -22,7 +23,5 @@ class NotificationSender(object): self.queue.send_mail(recipients, self.EMAIL_SUBJECT, body) def _get_recipients(self, type_): - return [ - recipient.email - for recipient in db.session.query(NotificationRecipient).all() - ] + query = select([NotificationRecipient.email]) + return db.session.execute(query).fetchone() diff --git a/tests/utils/test_notification_sender.py b/tests/utils/test_notification_sender.py index 0e8f3c23..458433c7 100644 --- a/tests/utils/test_notification_sender.py +++ b/tests/utils/test_notification_sender.py @@ -23,5 +23,5 @@ def test_can_send_notification(mock_queue, notification_sender): notification_sender.send(email_body) mock_queue.send_mail.assert_called_once_with( - ["test@example.com"], notification_sender.EMAIL_SUBJECT, email_body + ("test@example.com",), notification_sender.EMAIL_SUBJECT, email_body )