cr-connect-workflow/tests/emails/test_mails.py

114 lines
4.9 KiB
Python
Raw Normal View History

from crc import mail
2020-06-12 18:17:08 +00:00
from crc.models.email import EmailModel
2020-06-04 06:35:59 +00:00
from crc.services.mails import (
send_ramp_up_submission_email,
send_ramp_up_approval_request_email,
send_ramp_up_approval_request_first_review_email,
send_ramp_up_approved_email,
2020-06-05 18:08:31 +00:00
send_ramp_up_denied_email,
send_ramp_up_denied_email_to_approver
2020-06-04 06:35:59 +00:00
)
from tests.base_test import BaseTest
2020-06-04 06:35:59 +00:00
class TestMails(BaseTest):
def setUp(self):
2020-06-10 04:57:56 +00:00
"""Initial setup shared by all TestApprovals tests"""
self.load_example_data()
self.study = self.create_study()
self.workflow = self.create_workflow('random_fact')
2020-06-04 06:35:59 +00:00
self.sender = 'sender@sartography.com'
self.recipients = ['recipient@sartography.com']
self.primary_investigator = 'Dr. Bartlett'
self.approver_1 = 'Max Approver'
self.approver_2 = 'Close Reviewer'
def test_send_ramp_up_submission_email(self):
2020-06-08 22:17:41 +00:00
with mail.record_messages() as outbox:
send_ramp_up_submission_email(self.sender, self.recipients, self.approver_1)
2020-06-08 22:17:41 +00:00
self.assertEqual(len(outbox), 1)
self.assertEqual(outbox[0].subject, 'Research Ramp-up Plan Submitted')
self.assertIn(self.approver_1, outbox[0].body)
self.assertIn(self.approver_1, outbox[0].html)
send_ramp_up_submission_email(self.sender, self.recipients, self.approver_1, self.approver_2)
2020-06-08 22:17:41 +00:00
self.assertEqual(len(outbox), 2)
self.assertIn(self.approver_1, outbox[1].body)
self.assertIn(self.approver_1, outbox[1].html)
self.assertIn(self.approver_2, outbox[1].body)
self.assertIn(self.approver_2, outbox[1].html)
2020-06-04 06:35:59 +00:00
2020-06-12 18:17:08 +00:00
db_emails = EmailModel.query.count()
self.assertEqual(db_emails, 2)
2020-06-04 06:35:59 +00:00
def test_send_ramp_up_approval_request_email(self):
2020-06-08 22:17:41 +00:00
with mail.record_messages() as outbox:
send_ramp_up_approval_request_email(self.sender, self.recipients, self.primary_investigator)
2020-06-08 22:17:41 +00:00
self.assertEqual(len(outbox), 1)
self.assertEqual(outbox[0].subject, 'Research Ramp-up Plan Approval Request')
self.assertIn(self.primary_investigator, outbox[0].body)
self.assertIn(self.primary_investigator, outbox[0].html)
2020-06-04 06:35:59 +00:00
2020-06-12 18:17:08 +00:00
db_emails = EmailModel.query.count()
self.assertEqual(db_emails, 1)
2020-06-04 06:35:59 +00:00
def test_send_ramp_up_approval_request_first_review_email(self):
2020-06-08 22:17:41 +00:00
with mail.record_messages() as outbox:
send_ramp_up_approval_request_first_review_email(
self.sender, self.recipients, self.primary_investigator
2020-06-08 22:17:41 +00:00
)
self.assertEqual(len(outbox), 1)
self.assertEqual(outbox[0].subject, 'Research Ramp-up Plan Approval Request')
self.assertIn(self.primary_investigator, outbox[0].body)
self.assertIn(self.primary_investigator, outbox[0].html)
2020-06-04 06:35:59 +00:00
2020-06-12 18:17:08 +00:00
db_emails = EmailModel.query.count()
self.assertEqual(db_emails, 1)
2020-06-04 06:35:59 +00:00
def test_send_ramp_up_approved_email(self):
2020-06-08 22:17:41 +00:00
with mail.record_messages() as outbox:
send_ramp_up_approved_email(self.sender, self.recipients, self.approver_1)
2020-06-08 22:17:41 +00:00
self.assertEqual(len(outbox), 1)
self.assertEqual(outbox[0].subject, 'Research Ramp-up Plan Approved')
self.assertIn(self.approver_1, outbox[0].body)
self.assertIn(self.approver_1, outbox[0].html)
2020-06-04 06:35:59 +00:00
send_ramp_up_approved_email(self.sender, self.recipients, self.approver_1, self.approver_2)
2020-06-08 22:17:41 +00:00
self.assertEqual(len(outbox), 2)
self.assertIn(self.approver_1, outbox[1].body)
self.assertIn(self.approver_1, outbox[1].html)
self.assertIn(self.approver_2, outbox[1].body)
self.assertIn(self.approver_2, outbox[1].html)
2020-06-04 06:35:59 +00:00
2020-06-12 18:17:08 +00:00
db_emails = EmailModel.query.count()
self.assertEqual(db_emails, 2)
2020-06-04 06:35:59 +00:00
def test_send_ramp_up_denied_email(self):
2020-06-08 22:17:41 +00:00
with mail.record_messages() as outbox:
send_ramp_up_denied_email(self.sender, self.recipients, self.approver_1)
2020-06-08 22:17:41 +00:00
self.assertEqual(outbox[0].subject, 'Research Ramp-up Plan Denied')
self.assertIn(self.approver_1, outbox[0].body)
self.assertIn(self.approver_1, outbox[0].html)
2020-06-05 18:08:31 +00:00
2020-06-12 18:17:08 +00:00
db_emails = EmailModel.query.count()
self.assertEqual(db_emails, 1)
2020-06-05 18:08:31 +00:00
def test_send_send_ramp_up_denied_email_to_approver(self):
2020-06-08 22:17:41 +00:00
with mail.record_messages() as outbox:
send_ramp_up_denied_email_to_approver(
self.sender, self.recipients, self.primary_investigator, self.approver_2
2020-06-08 22:17:41 +00:00
)
self.assertEqual(outbox[0].subject, 'Research Ramp-up Plan Denied')
self.assertIn(self.primary_investigator, outbox[0].body)
self.assertIn(self.primary_investigator, outbox[0].html)
self.assertIn(self.approver_2, outbox[0].body)
self.assertIn(self.approver_2, outbox[0].html)
2020-06-12 18:17:08 +00:00
db_emails = EmailModel.query.count()
self.assertEqual(db_emails, 1)