mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-23 21:28:32 +00:00
Tests and workflows
This commit is contained in:
parent
6322353c88
commit
629fe6f571
96
tests/data/get_logging/get_logging.bpmn
Normal file
96
tests/data/get_logging/get_logging.bpmn
Normal file
@ -0,0 +1,96 @@
|
||||
<?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:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_e3059e6" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
|
||||
<bpmn:process id="Process_LoggingTask" name="Logging Task" isExecutable="true">
|
||||
<bpmn:startEvent id="StartEvent_1">
|
||||
<bpmn:outgoing>Flow_0d5wpav</bpmn:outgoing>
|
||||
</bpmn:startEvent>
|
||||
<bpmn:scriptTask id="Activity_LogEvent" name="Log Event">
|
||||
<bpmn:incoming>Flow_0pc42yp</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_0n34cdi</bpmn:outgoing>
|
||||
<bpmn:script>log_model_info = log(level='info', code='test_code', message='You forgot to include the correct data.')
|
||||
log_model_debug = log(level='degug', code='debug_test_code', message='This is my debugging message')</bpmn:script>
|
||||
</bpmn:scriptTask>
|
||||
<bpmn:manualTask id="Activity_DisplayLog" name="DisplayLog">
|
||||
<bpmn:documentation># Logging Models Pre
|
||||
{{ logging_models_pre }}
|
||||
|
||||
# Log Model
|
||||
{{ log_model }}
|
||||
|
||||
# Logging Models All Post
|
||||
{{ logging_models_all_post }}
|
||||
|
||||
|
||||
# Logging Models Info Post
|
||||
{{ logging_models_info_post }}
|
||||
|
||||
|
||||
# Logging Models Debug Post
|
||||
{{ logging_models_debug_post }}</bpmn:documentation>
|
||||
<bpmn:incoming>Flow_07j4f0v</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_016ui0e</bpmn:outgoing>
|
||||
</bpmn:manualTask>
|
||||
<bpmn:endEvent id="Event_06g3ojm">
|
||||
<bpmn:incoming>Flow_016ui0e</bpmn:incoming>
|
||||
</bpmn:endEvent>
|
||||
<bpmn:sequenceFlow id="Flow_016ui0e" sourceRef="Activity_DisplayLog" targetRef="Event_06g3ojm" />
|
||||
<bpmn:scriptTask id="Activity_GetLoggingPre" name="Get Logging Pre">
|
||||
<bpmn:incoming>Flow_0d5wpav</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_0pc42yp</bpmn:outgoing>
|
||||
<bpmn:script>logging_models_pre = get_logs()</bpmn:script>
|
||||
</bpmn:scriptTask>
|
||||
<bpmn:scriptTask id="Activity_GetLoggingPost" name="Get Logging Post">
|
||||
<bpmn:incoming>Flow_0n34cdi</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_07j4f0v</bpmn:outgoing>
|
||||
<bpmn:script>logging_models_all_post = get_logs()
|
||||
logging_models_info_post = get_logs('test_code')
|
||||
logging_models_debug_post = get_logs('debug_test_code')</bpmn:script>
|
||||
</bpmn:scriptTask>
|
||||
<bpmn:sequenceFlow id="Flow_0d5wpav" sourceRef="StartEvent_1" targetRef="Activity_GetLoggingPre" />
|
||||
<bpmn:sequenceFlow id="Flow_0pc42yp" sourceRef="Activity_GetLoggingPre" targetRef="Activity_LogEvent" />
|
||||
<bpmn:sequenceFlow id="Flow_0n34cdi" sourceRef="Activity_LogEvent" targetRef="Activity_GetLoggingPost" />
|
||||
<bpmn:sequenceFlow id="Flow_07j4f0v" sourceRef="Activity_GetLoggingPost" targetRef="Activity_DisplayLog" />
|
||||
</bpmn:process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_LoggingTask">
|
||||
<bpmndi:BPMNEdge id="Flow_07j4f0v_di" bpmnElement="Flow_07j4f0v">
|
||||
<di:waypoint x="650" y="117" />
|
||||
<di:waypoint x="710" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_0n34cdi_di" bpmnElement="Flow_0n34cdi">
|
||||
<di:waypoint x="490" y="117" />
|
||||
<di:waypoint x="550" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_0pc42yp_di" bpmnElement="Flow_0pc42yp">
|
||||
<di:waypoint x="330" y="117" />
|
||||
<di:waypoint x="390" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_0d5wpav_di" bpmnElement="Flow_0d5wpav">
|
||||
<di:waypoint x="188" y="117" />
|
||||
<di:waypoint x="230" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_016ui0e_di" bpmnElement="Flow_016ui0e">
|
||||
<di:waypoint x="810" y="117" />
|
||||
<di:waypoint x="872" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
|
||||
<dc:Bounds x="152" y="99" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_08z1eq4_di" bpmnElement="Activity_LogEvent">
|
||||
<dc:Bounds x="390" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_0amiq7i_di" bpmnElement="Activity_DisplayLog">
|
||||
<dc:Bounds x="710" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Event_06g3ojm_di" bpmnElement="Event_06g3ojm">
|
||||
<dc:Bounds x="872" y="99" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_07mg1d2_di" bpmnElement="Activity_GetLoggingPre">
|
||||
<dc:Bounds x="230" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_167quv8_di" bpmnElement="Activity_GetLoggingPost">
|
||||
<dc:Bounds x="550" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</bpmn:definitions>
|
90
tests/data/get_logging_for_study/get_logging_for_study.bpmn
Normal file
90
tests/data/get_logging_for_study/get_logging_for_study.bpmn
Normal file
@ -0,0 +1,90 @@
|
||||
<?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:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0tt6u6r" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
|
||||
<bpmn:process id="Process_0jo811u" isExecutable="true">
|
||||
<bpmn:startEvent id="StartEvent_1">
|
||||
<bpmn:outgoing>Flow_0bbqksl</bpmn:outgoing>
|
||||
</bpmn:startEvent>
|
||||
<bpmn:sequenceFlow id="Flow_0bbqksl" sourceRef="StartEvent_1" targetRef="Activity_ManualTask" />
|
||||
<bpmn:manualTask id="Activity_ManualTask" name="Manual Task">
|
||||
<bpmn:documentation># Hello
|
||||
You may manipulate this in a test, as you see fit</bpmn:documentation>
|
||||
<bpmn:incoming>Flow_0bbqksl</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_0lh4lq8</bpmn:outgoing>
|
||||
</bpmn:manualTask>
|
||||
<bpmn:sequenceFlow id="Flow_0lh4lq8" sourceRef="Activity_ManualTask" targetRef="Activity_AddLogs" />
|
||||
<bpmn:scriptTask id="Activity_AddLogs" name="Add Logs">
|
||||
<bpmn:incoming>Flow_0lh4lq8</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_10fc3fk</bpmn:outgoing>
|
||||
<bpmn:script>some_text = 'variable'
|
||||
log('info', 'some_code', 'Some longer message')
|
||||
log('info', 'some_other_code', 'Another really long message')
|
||||
log('debug', 'debug_code', f'This message has a { some_text }!')</bpmn:script>
|
||||
</bpmn:scriptTask>
|
||||
<bpmn:sequenceFlow id="Flow_10fc3fk" sourceRef="Activity_AddLogs" targetRef="Activity_GetLogs" />
|
||||
<bpmn:scriptTask id="Activity_GetLogs" name="Get Logs">
|
||||
<bpmn:incoming>Flow_10fc3fk</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_1dfqchi</bpmn:outgoing>
|
||||
<bpmn:script>workflow_logs = get_logs()
|
||||
study_logs = get_logs_for_study()</bpmn:script>
|
||||
</bpmn:scriptTask>
|
||||
<bpmn:sequenceFlow id="Flow_1dfqchi" sourceRef="Activity_GetLogs" targetRef="Activity_DisplayInfo" />
|
||||
<bpmn:manualTask id="Activity_DisplayInfo" name="Display Info">
|
||||
<bpmn:documentation># Display Info
|
||||
|
||||
## Workflow Logs
|
||||
{{ workflow_logs }}
|
||||
|
||||
|
||||
## Study Logs
|
||||
{{ study_logs }}</bpmn:documentation>
|
||||
<bpmn:incoming>Flow_1dfqchi</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_0yxmlin</bpmn:outgoing>
|
||||
</bpmn:manualTask>
|
||||
<bpmn:endEvent id="Event_1dg0buo">
|
||||
<bpmn:incoming>Flow_0yxmlin</bpmn:incoming>
|
||||
</bpmn:endEvent>
|
||||
<bpmn:sequenceFlow id="Flow_0yxmlin" sourceRef="Activity_DisplayInfo" targetRef="Event_1dg0buo" />
|
||||
</bpmn:process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0jo811u">
|
||||
<bpmndi:BPMNEdge id="Flow_0bbqksl_di" bpmnElement="Flow_0bbqksl">
|
||||
<di:waypoint x="215" y="117" />
|
||||
<di:waypoint x="270" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_0lh4lq8_di" bpmnElement="Flow_0lh4lq8">
|
||||
<di:waypoint x="370" y="117" />
|
||||
<di:waypoint x="430" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_10fc3fk_di" bpmnElement="Flow_10fc3fk">
|
||||
<di:waypoint x="530" y="117" />
|
||||
<di:waypoint x="590" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_1dfqchi_di" bpmnElement="Flow_1dfqchi">
|
||||
<di:waypoint x="690" y="117" />
|
||||
<di:waypoint x="750" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_0yxmlin_di" bpmnElement="Flow_0yxmlin">
|
||||
<di:waypoint x="850" y="117" />
|
||||
<di:waypoint x="912" 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_0gphpwt_di" bpmnElement="Activity_ManualTask">
|
||||
<dc:Bounds x="270" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_0yb5wv4_di" bpmnElement="Activity_AddLogs">
|
||||
<dc:Bounds x="430" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_1d90rzn_di" bpmnElement="Activity_GetLogs">
|
||||
<dc:Bounds x="590" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_016wmmv_di" bpmnElement="Activity_DisplayInfo">
|
||||
<dc:Bounds x="750" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Event_1dg0buo_di" bpmnElement="Event_1dg0buo">
|
||||
<dc:Bounds x="912" y="99" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</bpmn:definitions>
|
@ -1,12 +1,17 @@
|
||||
from tests.base_test import BaseTest
|
||||
|
||||
from crc import session
|
||||
from crc.models.api_models import Task
|
||||
from crc.models.task_log import TaskLogModel
|
||||
from crc.models.study import StudyModel
|
||||
from crc.scripts.log import MyScript
|
||||
|
||||
import types
|
||||
|
||||
|
||||
class TestLoggingScript(BaseTest):
|
||||
class TestTaskLogging(BaseTest):
|
||||
|
||||
def test_logging_script(self):
|
||||
def test_add_log(self):
|
||||
workflow = self.create_workflow('logging_task')
|
||||
workflow_api = self.get_workflow_api(workflow)
|
||||
task = workflow_api.next_task
|
||||
@ -17,3 +22,66 @@ class TestLoggingScript(BaseTest):
|
||||
self.assertEqual('test_code', log_model.code)
|
||||
self.assertEqual('info', log_model.level)
|
||||
self.assertEqual('Activity_LogEvent', log_model.task)
|
||||
|
||||
def test_get_logs(self):
|
||||
workflow = self.create_workflow('get_logging')
|
||||
workflow_api = self.get_workflow_api(workflow)
|
||||
task = workflow_api.next_task
|
||||
|
||||
self.assertEqual(2, len(task.data['logging_models_all_post']))
|
||||
self.assertEqual(1, len(task.data['logging_models_info_post']))
|
||||
self.assertEqual(1, len(task.data['logging_models_debug_post']))
|
||||
self.assertIn(task.data['logging_models_info_post'][0], task.data['logging_models_all_post'])
|
||||
self.assertIn(task.data['logging_models_debug_post'][0], task.data['logging_models_all_post'])
|
||||
self.assertEqual('test_code', task.data['logging_models_info_post'][0]['code'])
|
||||
self.assertEqual('debug_test_code', task.data['logging_models_debug_post'][0]['code'])
|
||||
|
||||
def test_get_logs_for_study(self):
|
||||
self.load_example_data()
|
||||
study = session.query(StudyModel).first()
|
||||
|
||||
workflow = self.create_workflow('hello_world', study=study)
|
||||
workflow_api = self.get_workflow_api(workflow)
|
||||
task = workflow_api.next_task
|
||||
|
||||
task_model = Task(id=task.id,
|
||||
name=task.name,
|
||||
title=task.title,
|
||||
type=task.type,
|
||||
state=task.state,
|
||||
lane=task.lane,
|
||||
form=task.form,
|
||||
documentation=task.documentation,
|
||||
data=task.data,
|
||||
multi_instance_type=task.multi_instance_type,
|
||||
multi_instance_count=task.multi_instance_count,
|
||||
multi_instance_index=task.multi_instance_index,
|
||||
process_name=task.process_name,
|
||||
properties=task.properties)
|
||||
|
||||
task_model.get_name = types.MethodType(lambda x: x.name, task_model)
|
||||
|
||||
MyScript().do_task(task_model, study.id, workflow.id,
|
||||
level='critical',
|
||||
code='critical_code',
|
||||
message='This is my critical message.')
|
||||
|
||||
MyScript().do_task(task_model, study.id, workflow.id,
|
||||
level='debug',
|
||||
code='debug_code',
|
||||
message='This is my debug message.')
|
||||
|
||||
# This workflow adds 3 logs
|
||||
# some_text = 'variable'
|
||||
# log('info', 'some_code', 'Some longer message')
|
||||
# log('info', 'some_other_code', 'Another really long message')
|
||||
# log('debug', 'debug_code', f'This message has a { some_text }!')
|
||||
workflow = self.create_workflow('get_logging_for_study', study=study)
|
||||
workflow_api = self.get_workflow_api(workflow)
|
||||
task = workflow_api.next_task
|
||||
workflow_api = self.complete_form(workflow, task, {})
|
||||
task = workflow_api.next_task
|
||||
workflow_logs = task.data['workflow_logs']
|
||||
study_logs = task.data['study_logs']
|
||||
self.assertEqual(3, len(workflow_logs))
|
||||
self.assertEqual(5, len(study_logs))
|
||||
|
Loading…
x
Reference in New Issue
Block a user