Changes to tests, and new test for the get_file_data script

This commit is contained in:
mike cullerton 2021-10-07 09:25:07 -04:00
parent 6f93554e7e
commit ea083e3a52
4 changed files with 109 additions and 3 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?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_0y2dq4f" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0"> <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_0y2dq4f" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
<bpmn:process id="Process_0tad5ma" name="Set Recipients" isExecutable="true"> <bpmn:process id="Process_0tad5ma" name="Set Recipients" isExecutable="true">
<bpmn:startEvent id="StartEvent_1"> <bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_1synsig</bpmn:outgoing> <bpmn:outgoing>Flow_1synsig</bpmn:outgoing>
@ -22,7 +22,8 @@ Email content to be delivered to {{ ApprvlApprvr1 }}
<bpmn:outgoing>Flow_1xlrgne</bpmn:outgoing> <bpmn:outgoing>Flow_1xlrgne</bpmn:outgoing>
<bpmn:script>subject="Camunda Email Subject" <bpmn:script>subject="Camunda Email Subject"
recipients=[ApprvlApprvr1,PIComputingID] recipients=[ApprvlApprvr1,PIComputingID]
email(subject=subject,recipients=recipients)</bpmn:script> email_id = email(subject=subject,recipients=recipients)
</bpmn:script>
</bpmn:scriptTask> </bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_1synsig" sourceRef="StartEvent_1" targetRef="Activity_1l9vih3" /> <bpmn:sequenceFlow id="Flow_1synsig" sourceRef="StartEvent_1" targetRef="Activity_1l9vih3" />
<bpmn:sequenceFlow id="Flow_1xlrgne" sourceRef="Activity_0s5v97n" targetRef="Event_0izrcj4" /> <bpmn:sequenceFlow id="Flow_1xlrgne" sourceRef="Activity_0s5v97n" targetRef="Event_0izrcj4" />

View File

@ -0,0 +1,81 @@
<?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: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="email_id" label="Email ID" type="string" />
<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 = 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: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="177" />
<di:waypoint x="752" y="177" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1bt23l3_di" bpmnElement="Flow_1bt23l3">
<di:waypoint x="530" y="177" />
<di:waypoint x="590" y="177" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1ira7x5_di" bpmnElement="Flow_1ira7x5">
<di:waypoint x="370" y="177" />
<di:waypoint x="430" y="177" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1erkgz2_di" bpmnElement="Flow_1erkgz2">
<di:waypoint x="215" y="177" />
<di:waypoint x="270" y="177" />
</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" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1db9xh7_di" bpmnElement="Activity_GetEmailData">
<dc:Bounds x="430" y="137" 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" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0s0boyj_di" bpmnElement="Event_0s0boyj">
<dc:Bounds x="752" y="159" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -16,7 +16,7 @@ class TestEmailScript(BaseTest):
with mail.record_messages() as outbox: with mail.record_messages() as outbox:
self.complete_form(workflow, task, task_data) workflow_api = self.complete_form(workflow, task, task_data)
self.assertEqual(len(outbox), 1) self.assertEqual(len(outbox), 1)
self.assertEqual(outbox[0].subject, 'Camunda Email Subject') self.assertEqual(outbox[0].subject, 'Camunda Email Subject')

View File

@ -0,0 +1,24 @@
from tests.base_test import BaseTest
from crc import mail, session
from crc.models.study import StudyModel
from crc.services.email_service import EmailService
class TestGetEmailData(BaseTest):
def test_get_email_data(self):
self.load_example_data()
study = session.query(StudyModel).first()
with mail.record_messages() as outbox:
email_model = 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 = self.create_workflow('get_email_data')
workflow_api = self.get_workflow_api(workflow)
task = workflow_api.next_task
workflow_api = self.complete_form(workflow, task, {'email_id': email_model.id})
print('test_get_email_data')