From 2f3fe59a0f96beabc1195ce42314a74a43194fe5 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Wed, 13 Oct 2021 13:40:14 -0400 Subject: [PATCH] Test for Exception when email service fails --- tests/emails/test_email_script.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/emails/test_email_script.py b/tests/emails/test_email_script.py index b84e8bbd..8176a9e0 100644 --- a/tests/emails/test_email_script.py +++ b/tests/emails/test_email_script.py @@ -2,6 +2,7 @@ from tests.base_test import BaseTest from crc import mail from crc.models.email import EmailModel import datetime +from unittest.mock import patch class TestEmailScript(BaseTest): @@ -49,3 +50,21 @@ class TestEmailScript(BaseTest): # Make sure timestamp is UTC self.assertEqual(db_emails[0].timestamp.tzinfo, datetime.timezone.utc) + + @patch('crc.services.email_service.EmailService.add_email') + def test_email_raises_exception(self, mock_response): + self.load_example_data() + mock_response.return_value.ok = True + mock_response.side_effect = Exception("This is my exception!") + + workflow = self.create_workflow('email') + + task_data = { + 'PIComputingID': 'dhf8r@virginia.edu', + 'ApprvlApprvr1': 'lb3dp@virginia.edu' + } + task = self.get_workflow_api(workflow).next_task + + with mail.record_messages() as outbox: + with self.assertRaises(Exception) as e: + self.complete_form(workflow, task, task_data)