Add NotificationSender, one test

This commit is contained in:
richard-dds
2019-05-10 16:01:25 -04:00
parent 802c62e3e9
commit a6c5f484b9
6 changed files with 99 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
from atst.queue import ATSTQueue
from atst.database import db
from atst.models import NotificationRecipient
class NotificationSender(object):
EMAIL_SUBJECT = "ATST notification"
def __init__(self, queue: ATSTQueue):
self.queue = queue
def send(self, body, type_=None):
recipients = self._get_recipients(type_)
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()
]