From a0d877e02f14dc815c3c1f64cadd592000826c9e Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Wed, 24 Jun 2020 22:23:31 -0600 Subject: [PATCH] Feedback from PR addressed --- crc/services/approval_service.py | 3 --- crc/services/mails.py | 12 ++++++------ tests/data/email/email.bpmn | 13 +++++++------ tests/emails/test_email_script.py | 29 ++++++++++++++++------------- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/crc/services/approval_service.py b/crc/services/approval_service.py index dbeed829..754bd48d 100644 --- a/crc/services/approval_service.py +++ b/crc/services/approval_service.py @@ -132,7 +132,6 @@ class ApprovalService(object): mail_result = send_ramp_up_approved_email( 'askresearch@virginia.edu', [pi_user_info.email_address], - approval_id, f'{approver_info.display_name} - ({approver_info.uid})' ) if mail_result: @@ -145,7 +144,6 @@ class ApprovalService(object): mail_result = send_ramp_up_denied_email( 'askresearch@virginia.edu', [pi_user_info.email_address], - approval_id, f'{approver_info.display_name} - ({approver_info.uid})' ) if mail_result: @@ -161,7 +159,6 @@ class ApprovalService(object): mail_result = send_ramp_up_denied_email_to_approver( 'askresearch@virginia.edu', approver_email, - approval_id, f'{pi_user_info.display_name} - ({pi_user_info.uid})', f'{approver_info.display_name} - ({approver_info.uid})' ) diff --git a/crc/services/mails.py b/crc/services/mails.py index b9b18bd1..c4942a7d 100644 --- a/crc/services/mails.py +++ b/crc/services/mails.py @@ -41,7 +41,7 @@ def send_mail(subject, sender, recipients, content, content_html, study_id=None) except Exception as e: return str(e) -def send_ramp_up_submission_email(sender, recipients, approval_id, approver_1, approver_2=None): +def send_ramp_up_submission_email(sender, recipients, approver_1, approver_2=None): from crc import env subject = 'Research Ramp-up Plan Submitted' @@ -54,7 +54,7 @@ def send_ramp_up_submission_email(sender, recipients, approval_id, approver_1, a result = send_mail(subject, sender, recipients, content, content_html) return result -def send_ramp_up_approval_request_email(sender, recipients, approval_id, primary_investigator): +def send_ramp_up_approval_request_email(sender, recipients, primary_investigator): from crc import env subject = 'Research Ramp-up Plan Approval Request' @@ -67,7 +67,7 @@ def send_ramp_up_approval_request_email(sender, recipients, approval_id, primary result = send_mail(subject, sender, recipients, content, content_html) return result -def send_ramp_up_approval_request_first_review_email(sender, recipients, approval_id, primary_investigator): +def send_ramp_up_approval_request_first_review_email(sender, recipients, primary_investigator): from crc import env subject = 'Research Ramp-up Plan Approval Request' @@ -80,7 +80,7 @@ def send_ramp_up_approval_request_first_review_email(sender, recipients, approva result = send_mail(subject, sender, recipients, content, content_html) return result -def send_ramp_up_approved_email(sender, recipients, approval_id, approver_1, approver_2=None): +def send_ramp_up_approved_email(sender, recipients, approver_1, approver_2=None): from crc import env subject = 'Research Ramp-up Plan Approved' @@ -93,7 +93,7 @@ def send_ramp_up_approved_email(sender, recipients, approval_id, approver_1, app result = send_mail(subject, sender, recipients, content, content_html) return result -def send_ramp_up_denied_email(sender, recipients, approval_id, approver): +def send_ramp_up_denied_email(sender, recipients, approver): from crc import env subject = 'Research Ramp-up Plan Denied' @@ -106,7 +106,7 @@ def send_ramp_up_denied_email(sender, recipients, approval_id, approver): result = send_mail(subject, sender, recipients, content, content_html) return result -def send_ramp_up_denied_email_to_approver(sender, recipients, approval_id, primary_investigator, approver_2): +def send_ramp_up_denied_email_to_approver(sender, recipients, primary_investigator, approver_2): from crc import env subject = 'Research Ramp-up Plan Denied' diff --git a/tests/data/email/email.bpmn b/tests/data/email/email.bpmn index 54ec61a8..1b8d5252 100644 --- a/tests/data/email/email.bpmn +++ b/tests/data/email/email.bpmn @@ -13,6 +13,7 @@ --- +New request submitted by {{ PIComputingID }} Email content to be delivered to {{ ApprvlApprvr1 }} @@ -37,17 +38,17 @@ Email content to be delivered to {{ ApprvlApprvr1 }} - - - + + + - - - + + + diff --git a/tests/emails/test_email_script.py b/tests/emails/test_email_script.py index 79d5c6ee..12a00fac 100644 --- a/tests/emails/test_email_script.py +++ b/tests/emails/test_email_script.py @@ -1,36 +1,39 @@ from tests.base_test import BaseTest +from crc.models.email import EmailModel from crc.services.file_service import FileService from crc.scripts.email import Email from crc.services.workflow_processor import WorkflowProcessor from crc.api.common import ApiError -from crc import db +from crc import db, mail class TestEmailScript(BaseTest): def test_do_task(self): - # self.load_example_data() - # self.create_reference_document() workflow = self.create_workflow('email') - # processor = WorkflowProcessor(workflow) - # task = processor.next_task() - # TODO: Replace with proper `complete_form` method from test_tasks - # processor.complete_task(task) - # task = processor.next_task() task_data = { 'PIComputingID': 'dhf8r', 'ApprvlApprvr1': 'lb3dp' } task = self.get_workflow_api(workflow).next_task - self.complete_form(workflow, task, task_data) + with mail.record_messages() as outbox: + self.complete_form(workflow, task, task_data) - # script = Email() - # script.do_task(task, 'Subject', 'PIComputingID', 'ApprvlApprvr1') + self.assertEqual(len(outbox), 1) + self.assertEqual(outbox[0].subject, 'Camunda Email Subject') - # TODO: Add proper assertions - self.assertTrue(True) + # PI is present + self.assertIn(task_data['PIComputingID'], outbox[0].body) + self.assertIn(task_data['PIComputingID'], outbox[0].html) + + # Approver is present + self.assertIn(task_data['ApprvlApprvr1'], outbox[0].body) + self.assertIn(task_data['ApprvlApprvr1'], outbox[0].html) + + db_emails = EmailModel.query.count() + self.assertEqual(db_emails, 1)