From dc7b39b5c8ca652a9de7c1f85a9772f9b7d1fe06 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Mon, 18 Oct 2021 11:21:24 -0400 Subject: [PATCH] Tests and workflows for the cases where attachments is None or '' --- .../email_attachment_empty_string.bpmn | 84 +++++++++++++++++++ .../email_none_attachment.bpmn | 84 +++++++++++++++++++ tests/emails/test_email_script.py | 45 ++++++++++ 3 files changed, 213 insertions(+) create mode 100644 tests/data/email_attachment_empty_string/email_attachment_empty_string.bpmn create mode 100644 tests/data/email_none_attachment/email_none_attachment.bpmn diff --git a/tests/data/email_attachment_empty_string/email_attachment_empty_string.bpmn b/tests/data/email_attachment_empty_string/email_attachment_empty_string.bpmn new file mode 100644 index 00000000..e93e34a6 --- /dev/null +++ b/tests/data/email_attachment_empty_string/email_attachment_empty_string.bpmn @@ -0,0 +1,84 @@ + + + + + Flow_1synsig + + + # Dear Approver +## you have been requested for approval + + +--- +New request submitted by {{ PIComputingID }} + +Email content to be delivered to {{ ApprvlApprvr1 }} + +--- +**Test Some Formatting** + _UVA Tracking Number:_ {{ 321 }} + Flow_08n2npe + Flow_1ch3gt4 + attachments = '' +email_id = email(subject=subject,recipients=recipients, attachments=attachments) + + + + + + + + + + + Flow_1synsig + Flow_08n2npe + + + + Flow_1gei5cf + + + + # Email +{{ email_id }} + Flow_1ch3gt4 + Flow_1gei5cf + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/email_none_attachment/email_none_attachment.bpmn b/tests/data/email_none_attachment/email_none_attachment.bpmn new file mode 100644 index 00000000..ebfbc897 --- /dev/null +++ b/tests/data/email_none_attachment/email_none_attachment.bpmn @@ -0,0 +1,84 @@ + + + + + Flow_1synsig + + + # Dear Approver +## you have been requested for approval + + +--- +New request submitted by {{ PIComputingID }} + +Email content to be delivered to {{ ApprvlApprvr1 }} + +--- +**Test Some Formatting** + _UVA Tracking Number:_ {{ 321 }} + Flow_08n2npe + Flow_1ch3gt4 + attachments = None +email_id = email(subject=subject,recipients=recipients, attachments=attachments) + + + + + + + + + + + Flow_1synsig + Flow_08n2npe + + + + Flow_1gei5cf + + + + # Email +{{ email_id }} + Flow_1ch3gt4 + Flow_1gei5cf + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/emails/test_email_script.py b/tests/emails/test_email_script.py index 0b1ec499..cdc96f4e 100644 --- a/tests/emails/test_email_script.py +++ b/tests/emails/test_email_script.py @@ -37,3 +37,48 @@ class TestEmailScript(BaseTest): db_emails = EmailModel.query.count() self.assertEqual(db_emails, 1) + + def test_email_with_none_attachment(self): + # This workflow specifically sends `attachments = None` as a parameter + # to the email script + workflow = self.create_workflow('email_none_attachment') + workflow_api = self.get_workflow_api(workflow) + task = workflow_api.next_task + + with mail.record_messages() as outbox: + + workflow_api = self.complete_form(workflow, task, {'subject': 'My Test Email', + 'recipients': 'user@example.com'}) + task = workflow_api.next_task + # Make sure 'attachments' is in task.data, and is None + self.assertIn('attachments', task.data) + self.assertEqual(task.data['attachments'], None) + + # Make sure we still send an email + self.assertIn('email_id', task.data) + + self.assertEqual(len(outbox), 1) + self.assertEqual(outbox[0].subject, "My Test Email") + self.assertEqual(outbox[0].recipients, ['user@example.com']) + + def test_email_attachment_empty_string(self): + # This workflow specifically sends `attachments = ''` as a parameter + # to the email script + workflow = self.create_workflow('email_attachment_empty_string') + workflow_api = self.get_workflow_api(workflow) + task = workflow_api.next_task + + with mail.record_messages() as outbox: + workflow_api = self.complete_form(workflow, task, {'subject': 'My Test Email', + 'recipients': 'user@example.com'}) + task = workflow_api.next_task + # Make sure 'attachments' is in task.data, and is None + self.assertIn('attachments', task.data) + self.assertEqual(task.data['attachments'], '') + + # Make sure we still send an email + self.assertIn('email_id', task.data) + + self.assertEqual(len(outbox), 1) + self.assertEqual(outbox[0].subject, "My Test Email") + self.assertEqual(outbox[0].recipients, ['user@example.com'])