Tests for get_email_data script.

This commit is contained in:
mike cullerton 2021-10-07 12:11:22 -04:00
parent 826b98a6ea
commit 7f11d5bd58
3 changed files with 149 additions and 32 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_5cbdc71" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.0.0-dev">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_5cbdc71" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
<bpmn:process id="Process_GetEmailData" name="Get Email Data" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_1erkgz2</bpmn:outgoing>
@ -8,8 +8,11 @@
<bpmn:userTask id="Activity_GetData" name="Get Data" camunda:formKey="DataForm">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="email_id" label="Email ID" type="string" />
<camunda:formField id="workflow_id" label="Workflow ID" type="string" />
<camunda:formField id="email_id" label="Email ID" type="string">
<camunda:validation>
<camunda:constraint name="required" config="True" />
</camunda:validation>
</camunda:formField>
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1erkgz2</bpmn:incoming>
@ -19,22 +22,12 @@
<bpmn:scriptTask id="Activity_GetEmailData" name="Get Email Data">
<bpmn:incoming>Flow_1ira7x5</bpmn:incoming>
<bpmn:outgoing>Flow_1bt23l3</bpmn:outgoing>
<bpmn:script>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)</bpmn:script>
<bpmn:script>email_data = get_email_data(email_id=email_id)</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_1bt23l3" sourceRef="Activity_GetEmailData" targetRef="Activity_DisplayEmailData" />
<bpmn:manualTask id="Activity_DisplayEmailData" name="Display Email Data">
<bpmn:documentation># Email Data
{{ email_data }}
</bpmn:documentation>
{{ email_data }}</bpmn:documentation>
<bpmn:incoming>Flow_1bt23l3</bpmn:incoming>
<bpmn:outgoing>Flow_0uujrj4</bpmn:outgoing>
</bpmn:manualTask>
@ -46,35 +39,35 @@ print(email_data)</bpmn:script>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_GetEmailData">
<bpmndi:BPMNEdge id="Flow_0uujrj4_di" bpmnElement="Flow_0uujrj4">
<di:waypoint x="690" y="177" />
<di:waypoint x="752" y="177" />
<di:waypoint x="690" y="117" />
<di:waypoint x="752" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1bt23l3_di" bpmnElement="Flow_1bt23l3">
<di:waypoint x="530" y="177" />
<di:waypoint x="590" y="177" />
<di:waypoint x="530" y="117" />
<di:waypoint x="590" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1ira7x5_di" bpmnElement="Flow_1ira7x5">
<di:waypoint x="370" y="177" />
<di:waypoint x="430" y="177" />
<di:waypoint x="373" y="117" />
<di:waypoint x="430" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1erkgz2_di" bpmnElement="Flow_1erkgz2">
<di:waypoint x="215" y="177" />
<di:waypoint x="270" y="177" />
<di:waypoint x="215" y="117" />
<di:waypoint x="273" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="159" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1wpvwpe_di" bpmnElement="Activity_GetData">
<dc:Bounds x="270" y="137" width="100" height="80" />
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1db9xh7_di" bpmnElement="Activity_GetEmailData">
<dc:Bounds x="430" y="137" width="100" height="80" />
<dc:Bounds x="430" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0ue8wu7_di" bpmnElement="Activity_DisplayEmailData">
<dc:Bounds x="590" y="137" width="100" height="80" />
<dc:Bounds x="590" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0s0boyj_di" bpmnElement="Event_0s0boyj">
<dc:Bounds x="752" y="159" width="36" height="36" />
<dc:Bounds x="752" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1wpvwpe_di" bpmnElement="Activity_GetData">
<dc:Bounds x="273" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_5cbdc71" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
<bpmn:process id="Process_GetEmailData" name="Get Email Data" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_1erkgz2</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_1erkgz2" sourceRef="StartEvent_1" targetRef="Activity_GetData" />
<bpmn:userTask id="Activity_GetData" name="Get Data" camunda:formKey="DataForm">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="workflow_id" label="Workflow ID" type="string" />
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1erkgz2</bpmn:incoming>
<bpmn:outgoing>Flow_1ira7x5</bpmn:outgoing>
</bpmn:userTask>
<bpmn:sequenceFlow id="Flow_1ira7x5" sourceRef="Activity_GetData" targetRef="Activity_GetEmailData" />
<bpmn:scriptTask id="Activity_GetEmailData" name="Get Email Data">
<bpmn:incoming>Flow_1ira7x5</bpmn:incoming>
<bpmn:outgoing>Flow_1bt23l3</bpmn:outgoing>
<bpmn:script>email_data = get_email_data(email_workflow_id=workflow_id)</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_1bt23l3" sourceRef="Activity_GetEmailData" targetRef="Activity_DisplayEmailData" />
<bpmn:manualTask id="Activity_DisplayEmailData" name="Display Email Data">
<bpmn:documentation># Email Data
{{ email_data }}</bpmn:documentation>
<bpmn:incoming>Flow_1bt23l3</bpmn:incoming>
<bpmn:outgoing>Flow_0uujrj4</bpmn:outgoing>
</bpmn:manualTask>
<bpmn:endEvent id="Event_0s0boyj">
<bpmn:incoming>Flow_0uujrj4</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0uujrj4" sourceRef="Activity_DisplayEmailData" targetRef="Event_0s0boyj" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_GetEmailData">
<bpmndi:BPMNEdge id="Flow_0uujrj4_di" bpmnElement="Flow_0uujrj4">
<di:waypoint x="690" y="117" />
<di:waypoint x="752" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1bt23l3_di" bpmnElement="Flow_1bt23l3">
<di:waypoint x="530" y="117" />
<di:waypoint x="590" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1ira7x5_di" bpmnElement="Flow_1ira7x5">
<di:waypoint x="370" y="117" />
<di:waypoint x="430" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1erkgz2_di" bpmnElement="Flow_1erkgz2">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1wpvwpe_di" bpmnElement="Activity_GetData">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1db9xh7_di" bpmnElement="Activity_GetEmailData">
<dc:Bounds x="430" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0ue8wu7_di" bpmnElement="Activity_DisplayEmailData">
<dc:Bounds x="590" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0s0boyj_di" bpmnElement="Event_0s0boyj">
<dc:Bounds x="752" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -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')
# 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'])