diff --git a/tests/data/get_email_data/get_email_data.bpmn b/tests/data/get_email_data/get_email_data.bpmn index 0c6a44fe..38555b5b 100644 --- a/tests/data/get_email_data/get_email_data.bpmn +++ b/tests/data/get_email_data/get_email_data.bpmn @@ -1,5 +1,5 @@ - + Flow_1erkgz2 @@ -8,8 +8,11 @@ - - + + + + + Flow_1erkgz2 @@ -19,22 +22,12 @@ Flow_1ira7x5 Flow_1bt23l3 - email_data = None -if 'email_id' in globals(): - email_id = globals()['email_id'] - email_data = get_email_data(email_id=email_id) -elif 'workflow_id' in globals(): - workflow_id = globals()['workflow_id'] - email_data = get_email_data(workflow_id=workflow_id) -else: - email_data = 'nothing' -print(email_data) + email_data = get_email_data(email_id=email_id) # Email Data -{{ email_data }} - +{{ email_data }} Flow_1bt23l3 Flow_0uujrj4 @@ -46,35 +39,35 @@ print(email_data) - - + + - - + + - - + + - - + + - - - - + - + - + - + + + + diff --git a/tests/data/get_email_data_by_workflow/get_email_data_by_workflow.bpmn b/tests/data/get_email_data_by_workflow/get_email_data_by_workflow.bpmn new file mode 100644 index 00000000..70c71531 --- /dev/null +++ b/tests/data/get_email_data_by_workflow/get_email_data_by_workflow.bpmn @@ -0,0 +1,70 @@ + + + + + Flow_1erkgz2 + + + + + + + + + Flow_1erkgz2 + Flow_1ira7x5 + + + + Flow_1ira7x5 + Flow_1bt23l3 + email_data = get_email_data(email_workflow_id=workflow_id) + + + + # Email Data +{{ email_data }} + Flow_1bt23l3 + Flow_0uujrj4 + + + Flow_0uujrj4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/scripts/test_get_email_data.py b/tests/scripts/test_get_email_data.py index 44faf246..df324d48 100644 --- a/tests/scripts/test_get_email_data.py +++ b/tests/scripts/test_get_email_data.py @@ -1,15 +1,17 @@ from tests.base_test import BaseTest from crc import mail, session from crc.models.study import StudyModel +from crc.models.workflow import WorkflowModel from crc.services.email_service import EmailService class TestGetEmailData(BaseTest): - def test_get_email_data(self): + def test_get_email_data_by_email_id(self): self.load_example_data() study = session.query(StudyModel).first() with mail.record_messages() as outbox: + # Send an email we can use for get_email_data email_model = EmailService.add_email(subject='My Email Subject', sender='sender@example.com', recipients=['joe@example.com'], @@ -19,6 +21,58 @@ class TestGetEmailData(BaseTest): workflow_api = self.get_workflow_api(workflow) task = workflow_api.next_task + # Run workflow with get_email_data workflow_api = self.complete_form(workflow, task, {'email_id': email_model.id}) - print('test_get_email_data') \ No newline at end of file + # Make assertions + task = workflow_api.next_task + data = task.data + self.assertIn('email_data', data) + email_data = data['email_data'] + self.assertEqual(1, len(email_data)) + self.assertEqual('My Email Subject', email_data[0]['subject']) + self.assertEqual('sender@example.com', email_data[0]['sender']) + self.assertEqual('[\'joe@example.com\']', email_data[0]['recipients']) + + def test_get_email_data_by_workflow_id(self): + self.load_example_data() + study = session.query(StudyModel).first() + email_workflow = session.query(WorkflowModel).first() + + with mail.record_messages() as outbox: + # Send an email we can use for get_email_data + email_model_one = EmailService.add_email(subject='My Email Subject', + sender='sender@example.com', + recipients=['joe@example.com'], + content='asdf', + content_html=None, + study_id=study.id, + workflow_id=email_workflow.id) + email_model_two = EmailService.add_email(subject='My Other Email Subject', + sender='sender2@example.com', + recipients=['joanne@example.com'], + content='xyzpdq', + content_html=None, + study_id=study.id, + workflow_id=email_workflow.id) + + workflow = self.create_workflow('get_email_data_by_workflow') + workflow_api = self.get_workflow_api(workflow) + task = workflow_api.next_task + + # Run workflow with get_email_data + workflow_api = self.complete_form(workflow, task, {'workflow_id': email_workflow.id}) + task = workflow_api.next_task + data = task.data + + # Make assertions + self.assertIn('email_data', data) + email_data = data['email_data'] + self.assertEqual(2, len(email_data)) + self.assertEqual('My Email Subject', email_data[0]['subject']) + self.assertEqual('sender@example.com', email_data[0]['sender']) + self.assertEqual('[\'joe@example.com\']', email_data[0]['recipients']) + + self.assertEqual('My Other Email Subject', email_data[1]['subject']) + self.assertEqual('sender2@example.com', email_data[1]['sender']) + self.assertEqual('[\'joanne@example.com\']', email_data[1]['recipients'])