First couple tests, and a workflow for testing email

This commit is contained in:
mike cullerton 2021-10-16 14:23:12 -04:00
parent f9856d68a9
commit 6b1e0ebbfe
2 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,86 @@
<?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_09wjj2q" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
<bpmn:process id="Process_098hnjo" name="Send email w/ included templage" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_0yh2coe</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0yh2coe" sourceRef="StartEvent_1" targetRef="Activity_15btti7" />
<bpmn:sequenceFlow id="Flow_0ovknlg" sourceRef="Activity_15btti7" targetRef="Activity_181l58g" />
<bpmn:sequenceFlow id="Flow_103ct5a" sourceRef="Activity_181l58g" targetRef="Activity_0170t0m" />
<bpmn:endEvent id="Event_0f4v65r">
<bpmn:incoming>Flow_1nd1ian</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_1nd1ian" sourceRef="Activity_0170t0m" targetRef="Event_0f4v65r" />
<bpmn:userTask id="Activity_15btti7" name="Get Email Data" camunda:formKey="DataForm">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="subject" label="Subject" type="string" />
<camunda:formField id="recipients" label="Recipients" type="string" />
<camunda:formField id="include_me" label="Included Template" type="string" />
<camunda:formField id="name" label="Name" type="string" />
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_0yh2coe</bpmn:incoming>
<bpmn:outgoing>Flow_0ovknlg</bpmn:outgoing>
</bpmn:userTask>
<bpmn:scriptTask id="Activity_181l58g" name="Send Email">
<bpmn:documentation>Hello,
Thank you for supporting the cause!
{% include 'include_me' %}
Did we include the other template?
</bpmn:documentation>
<bpmn:incoming>Flow_0ovknlg</bpmn:incoming>
<bpmn:outgoing>Flow_103ct5a</bpmn:outgoing>
<bpmn:script>email_model = email(subject=subject, recipients=recipients)</bpmn:script>
</bpmn:scriptTask>
<bpmn:manualTask id="Activity_0170t0m" name="Display Email">
<bpmn:documentation># Email Model
{{ email_model }}
</bpmn:documentation>
<bpmn:incoming>Flow_103ct5a</bpmn:incoming>
<bpmn:outgoing>Flow_1nd1ian</bpmn:outgoing>
</bpmn:manualTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_098hnjo">
<bpmndi:BPMNEdge id="Flow_0yh2coe_di" bpmnElement="Flow_0yh2coe">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0ovknlg_di" bpmnElement="Flow_0ovknlg">
<di:waypoint x="370" y="117" />
<di:waypoint x="430" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_103ct5a_di" bpmnElement="Flow_103ct5a">
<di:waypoint x="530" y="117" />
<di:waypoint x="590" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1nd1ian_di" bpmnElement="Flow_1nd1ian">
<di:waypoint x="690" y="117" />
<di:waypoint x="752" 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="Event_0f4v65r_di" bpmnElement="Event_0f4v65r">
<dc:Bounds x="752" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0rtrmp6_di" bpmnElement="Activity_15btti7">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0xt518j_di" bpmnElement="Activity_181l58g">
<dc:Bounds x="430" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1tcaou0_di" bpmnElement="Activity_0170t0m">
<dc:Bounds x="590" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -0,0 +1,47 @@
from tests.base_test import BaseTest
from crc.services.workflow_processor import WorkflowProcessor
from crc.services.workflow_service import WorkflowService
from crc import mail
class TestJinjaService(BaseTest):
def test_jinja_service_documentation(self):
self.load_example_data()
workflow = self.create_workflow('random_fact')
processor = WorkflowProcessor(workflow)
processor.do_engine_steps()
task = processor.next_task()
task.data = {"my_template": "Hi {{name}}, This is a jinja template too!",
"name": "Dan"}
task.task_spec.documentation = """{% include 'my_template' %} Cool Right?"""
docs = WorkflowService._process_documentation(task)
self.assertEqual("Hi Dan, This is a jinja template too! Cool Right?", docs)
def test_jinja_service_email(self):
workflow = self.create_workflow('jinja_email')
workflow_api = self.get_workflow_api(workflow)
task = workflow_api.next_task
data = {'subject': "My Email Subject",
'recipients': 'user@example.com',
'include_me': "Hello {{name}}, This is a jinja template too!",
'name': 'World'}
with mail.record_messages() as outbox:
workflow_api = self.complete_form(workflow, task, data)
self.assertIn('Hello World, This is a jinja template too!', outbox[0].body)
self.assertIn("# Email Model\n1", workflow_api.next_task.documentation)
print(f'test_jinja_service_email: {workflow_api.next_task.data}')
def test_jinja_service_tools(self):
pass
def test_jinja_service_documents(self):
pass
def test_jinja_service_properties(self):
pass