mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-22 12:48:25 +00:00
Test and workflow for new script
This commit is contained in:
parent
e43df04116
commit
2e9205fa08
86
tests/data/get_workflow_state/get_workflow_state.bpmn
Normal file
86
tests/data/get_workflow_state/get_workflow_state.bpmn
Normal 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_0ytxrnf" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
|
||||
<bpmn:process id="Process_GetWorkflowState" name="Get Workflow State" isExecutable="true">
|
||||
<bpmn:startEvent id="StartEvent_1">
|
||||
<bpmn:outgoing>Flow_0swyqww</bpmn:outgoing>
|
||||
</bpmn:startEvent>
|
||||
<bpmn:sequenceFlow id="Flow_0swyqww" sourceRef="StartEvent_1" targetRef="Activity_GetSpecID" />
|
||||
<bpmn:endEvent id="Event_1lw9mnv">
|
||||
<bpmn:incoming>Flow_1pun04v</bpmn:incoming>
|
||||
</bpmn:endEvent>
|
||||
<bpmn:sequenceFlow id="Flow_0xj9g7j" sourceRef="Activity_GetWorkflowState" targetRef="Activity_DisplayWorkflowState" />
|
||||
<bpmn:scriptTask id="Activity_GetWorkflowState" name="Get Workflow State">
|
||||
<bpmn:incoming>Flow_17sm08f</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_0xj9g7j</bpmn:outgoing>
|
||||
<bpmn:script>workflow_state = get_workflow_state(workflow_spec_id=workflow_spec_id)</bpmn:script>
|
||||
</bpmn:scriptTask>
|
||||
<bpmn:sequenceFlow id="Flow_17sm08f" sourceRef="Activity_GetSpecID" targetRef="Activity_GetWorkflowState" />
|
||||
<bpmn:userTask id="Activity_GetSpecID" name="Get Workflow Spec ID" camunda:formKey="DataForm">
|
||||
<bpmn:extensionElements>
|
||||
<camunda:formData>
|
||||
<camunda:formField id="workflow_spec_id" label="'Workflow Spec ID'" type="string">
|
||||
<camunda:validation>
|
||||
<camunda:constraint name="required" config="True" />
|
||||
</camunda:validation>
|
||||
</camunda:formField>
|
||||
</camunda:formData>
|
||||
</bpmn:extensionElements>
|
||||
<bpmn:incoming>Flow_0swyqww</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_17sm08f</bpmn:outgoing>
|
||||
</bpmn:userTask>
|
||||
<bpmn:sequenceFlow id="Flow_1pun04v" sourceRef="Activity_DisplayWorkflowState" targetRef="Event_1lw9mnv" />
|
||||
<bpmn:manualTask id="Activity_DisplayWorkflowState" name="Display Workflow State">
|
||||
<bpmn:documentation>## Workflow State
|
||||
|
||||
|
||||
### State
|
||||
{{ workflow_state.state }}
|
||||
|
||||
|
||||
### Message
|
||||
{{ workflow_state.message }}
|
||||
|
||||
</bpmn:documentation>
|
||||
<bpmn:incoming>Flow_0xj9g7j</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_1pun04v</bpmn:outgoing>
|
||||
</bpmn:manualTask>
|
||||
</bpmn:process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_GetWorkflowState">
|
||||
<bpmndi:BPMNEdge id="Flow_0swyqww_di" bpmnElement="Flow_0swyqww">
|
||||
<di:waypoint x="215" y="117" />
|
||||
<di:waypoint x="289" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_0xj9g7j_di" bpmnElement="Flow_0xj9g7j">
|
||||
<di:waypoint x="568" y="117" />
|
||||
<di:waypoint x="647" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_17sm08f_di" bpmnElement="Flow_17sm08f">
|
||||
<di:waypoint x="389" y="117" />
|
||||
<di:waypoint x="468" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_1pun04v_di" bpmnElement="Flow_1pun04v">
|
||||
<di:waypoint x="747" y="117" />
|
||||
<di:waypoint x="822" 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_1lw9mnv_di" bpmnElement="Event_1lw9mnv">
|
||||
<dc:Bounds x="822" y="99" width="36" height="36" />
|
||||
<bpmndi:BPMNLabel>
|
||||
<dc:Bounds x="430" y="202" width="41" height="14" />
|
||||
</bpmndi:BPMNLabel>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_08wyc5y_di" bpmnElement="Activity_GetSpecID">
|
||||
<dc:Bounds x="289" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_183seks_di" bpmnElement="Activity_GetWorkflowState">
|
||||
<dc:Bounds x="468" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_1vrtzdz_di" bpmnElement="Activity_DisplayWorkflowState">
|
||||
<dc:Bounds x="647" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</bpmn:definitions>
|
53
tests/scripts/test_get_workflow_state.py
Normal file
53
tests/scripts/test_get_workflow_state.py
Normal file
@ -0,0 +1,53 @@
|
||||
from tests.base_test import BaseTest
|
||||
|
||||
from crc import session
|
||||
|
||||
|
||||
class TestGetWorkflowState(BaseTest):
|
||||
|
||||
def get_workflow_state(self, workflow_spec_id):
|
||||
|
||||
workflow = self.create_workflow('get_workflow_state')
|
||||
workflow_api = self.get_workflow_api(workflow)
|
||||
task = workflow_api.next_task
|
||||
|
||||
task_data = {'workflow_spec_id': workflow_spec_id}
|
||||
try:
|
||||
workflow_api = self.complete_form(workflow, task, task_data)
|
||||
except AssertionError:
|
||||
raise
|
||||
|
||||
task = workflow_api.next_task
|
||||
|
||||
workflow_state = task.data['workflow_state']
|
||||
return workflow_state
|
||||
|
||||
def test_get_workflow_state(self):
|
||||
|
||||
test_state = 'required'
|
||||
test_state_message = 'This workflow is required.'
|
||||
simple_form = self.create_workflow('simple_form')
|
||||
|
||||
# This runs the get_workflow_state script and returns the result from task data
|
||||
workflow_state = self.get_workflow_state('simple_form')
|
||||
|
||||
# At first, we have no state or state_message
|
||||
self.assertEqual(None, workflow_state['state'])
|
||||
self.assertEqual(None, workflow_state['message'])
|
||||
|
||||
# Set the state and state_message
|
||||
simple_form.state = test_state
|
||||
simple_form.state_message = test_state_message
|
||||
session.add(simple_form)
|
||||
session.commit()
|
||||
|
||||
# Get workflow_state again
|
||||
workflow_state = self.get_workflow_state('simple_form')
|
||||
|
||||
# Now, it should have a state and state_message
|
||||
self.assertEqual(test_state, workflow_state['state'])
|
||||
self.assertEqual(test_state_message, workflow_state['message'])
|
||||
|
||||
def test_get_workflow_state_bad_spec_id(self):
|
||||
with self.assertRaises(AssertionError) as ae:
|
||||
self.get_workflow_state('bad_spec_id')
|
Loading…
x
Reference in New Issue
Block a user