Test and BPMN file for new script
This commit is contained in:
parent
da914be3fa
commit
5f0db3f2fb
|
@ -0,0 +1,142 @@
|
|||
<?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_08a4c34" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0">
|
||||
<bpmn:process id="Process_DeleteTaskData" name="Delete Task Data" isExecutable="true">
|
||||
<bpmn:startEvent id="StartEvent_1">
|
||||
<bpmn:outgoing>SequenceFlow_12ulmn8</bpmn:outgoing>
|
||||
</bpmn:startEvent>
|
||||
<bpmn:endEvent id="Event_19ssfc0">
|
||||
<bpmn:incoming>SequenceFlow_1fgwvz0</bpmn:incoming>
|
||||
</bpmn:endEvent>
|
||||
<bpmn:userTask id="Activity_UploadSingle" name="Upload Single" camunda:formKey="SingleFile">
|
||||
<bpmn:extensionElements>
|
||||
<camunda:formData>
|
||||
<camunda:formField id="Study_Protocol_Document" label="Select File" type="file" />
|
||||
<camunda:formField id="ShortDesc" label="Short Description" type="textarea">
|
||||
<camunda:properties>
|
||||
<camunda:property id="file_data" value="Study_Protocol_Document" />
|
||||
</camunda:properties>
|
||||
</camunda:formField>
|
||||
<camunda:formField id="VerDate" label="Version Date" type="date">
|
||||
<camunda:properties>
|
||||
<camunda:property id="file_data" value="Study_Protocol_Document" />
|
||||
</camunda:properties>
|
||||
</camunda:formField>
|
||||
</camunda:formData>
|
||||
</bpmn:extensionElements>
|
||||
<bpmn:incoming>SequenceFlow_12ulmn8</bpmn:incoming>
|
||||
<bpmn:outgoing>SequenceFlow_06786ls</bpmn:outgoing>
|
||||
</bpmn:userTask>
|
||||
<bpmn:userTask id="Activity_UploadRepeat" name="Upload Repeat" camunda:formKey="RepeatFile">
|
||||
<bpmn:extensionElements>
|
||||
<camunda:formData>
|
||||
<camunda:formField id="Study_App_Doc" label="Select File" type="file">
|
||||
<camunda:properties>
|
||||
<camunda:property id="repeat" value="StudyAppDoc" />
|
||||
</camunda:properties>
|
||||
</camunda:formField>
|
||||
<camunda:formField id="ShortDesc" label="Short Description" type="textarea">
|
||||
<camunda:properties>
|
||||
<camunda:property id="repeat" value="StudyAppDoc" />
|
||||
<camunda:property id="file_data" value="Study_App_Doc" />
|
||||
</camunda:properties>
|
||||
</camunda:formField>
|
||||
<camunda:formField id="VerDate" label="Version Date" type="date">
|
||||
<camunda:properties>
|
||||
<camunda:property id="repeat" value="StudyAppDoc" />
|
||||
<camunda:property id="file_data" value="Study_App_Doc" />
|
||||
</camunda:properties>
|
||||
</camunda:formField>
|
||||
</camunda:formData>
|
||||
</bpmn:extensionElements>
|
||||
<bpmn:incoming>SequenceFlow_06786ls</bpmn:incoming>
|
||||
<bpmn:outgoing>SequenceFlow_0xo2jve</bpmn:outgoing>
|
||||
</bpmn:userTask>
|
||||
<bpmn:scriptTask id="Activity_DeleteSingle" name="Delete Single">
|
||||
<bpmn:incoming>SequenceFlow_17j00uv</bpmn:incoming>
|
||||
<bpmn:outgoing>SequenceFlow_0oa0av1</bpmn:outgoing>
|
||||
<bpmn:script>delete_task_file_data(task_id='Activity_UploadSingle')</bpmn:script>
|
||||
</bpmn:scriptTask>
|
||||
<bpmn:scriptTask id="Activity_DeleteRepeat" name="Delete Repeat">
|
||||
<bpmn:incoming>SequenceFlow_0oa0av1</bpmn:incoming>
|
||||
<bpmn:outgoing>SequenceFlow_0hxvd1d</bpmn:outgoing>
|
||||
<bpmn:script>delete_task_file_data(task_id='Activity_UploadRepeat')</bpmn:script>
|
||||
</bpmn:scriptTask>
|
||||
<bpmn:manualTask id="Activity_FilesUploaded" name="Files Uploaded">
|
||||
<bpmn:documentation>## Files Uploaded
|
||||
</bpmn:documentation>
|
||||
<bpmn:incoming>SequenceFlow_0xo2jve</bpmn:incoming>
|
||||
<bpmn:outgoing>SequenceFlow_17j00uv</bpmn:outgoing>
|
||||
</bpmn:manualTask>
|
||||
<bpmn:manualTask id="Activity_FilesDeleted" name="Files Deleted">
|
||||
<bpmn:documentation>## Files Deleted
|
||||
</bpmn:documentation>
|
||||
<bpmn:incoming>SequenceFlow_0hxvd1d</bpmn:incoming>
|
||||
<bpmn:outgoing>SequenceFlow_1fgwvz0</bpmn:outgoing>
|
||||
</bpmn:manualTask>
|
||||
<bpmn:sequenceFlow id="SequenceFlow_12ulmn8" sourceRef="StartEvent_1" targetRef="Activity_UploadSingle" />
|
||||
<bpmn:sequenceFlow id="SequenceFlow_06786ls" sourceRef="Activity_UploadSingle" targetRef="Activity_UploadRepeat" />
|
||||
<bpmn:sequenceFlow id="SequenceFlow_0xo2jve" sourceRef="Activity_UploadRepeat" targetRef="Activity_FilesUploaded" />
|
||||
<bpmn:sequenceFlow id="SequenceFlow_0oa0av1" sourceRef="Activity_DeleteSingle" targetRef="Activity_DeleteRepeat" />
|
||||
<bpmn:sequenceFlow id="SequenceFlow_0hxvd1d" sourceRef="Activity_DeleteRepeat" targetRef="Activity_FilesDeleted" />
|
||||
<bpmn:sequenceFlow id="SequenceFlow_1fgwvz0" sourceRef="Activity_FilesDeleted" targetRef="Event_19ssfc0" />
|
||||
<bpmn:sequenceFlow id="SequenceFlow_17j00uv" sourceRef="Activity_FilesUploaded" targetRef="Activity_DeleteSingle" />
|
||||
</bpmn:process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_DeleteTaskData">
|
||||
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
|
||||
<dc:Bounds x="179" y="102" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Event_19ssfc0_di" bpmnElement="Event_19ssfc0">
|
||||
<dc:Bounds x="772" y="332" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_1hrox53_di" bpmnElement="Activity_UploadSingle">
|
||||
<dc:Bounds x="277" y="80" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_04ypnfq_di" bpmnElement="Activity_UploadRepeat">
|
||||
<dc:Bounds x="444" y="80" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_1b1g8ix_di" bpmnElement="Activity_DeleteSingle">
|
||||
<dc:Bounds x="277" y="310" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_17by4en_di" bpmnElement="Activity_DeleteRepeat">
|
||||
<dc:Bounds x="444" y="310" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_1pqjcpj_di" bpmnElement="Activity_FilesUploaded">
|
||||
<dc:Bounds x="611" y="80" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_07qeio1_di" bpmnElement="Activity_FilesDeleted">
|
||||
<dc:Bounds x="611" y="310" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNEdge id="SequenceFlow_12ulmn8_di" bpmnElement="SequenceFlow_12ulmn8">
|
||||
<di:waypoint x="215" y="120" />
|
||||
<di:waypoint x="277" y="120" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="SequenceFlow_06786ls_di" bpmnElement="SequenceFlow_06786ls">
|
||||
<di:waypoint x="377" y="120" />
|
||||
<di:waypoint x="444" y="120" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="SequenceFlow_0xo2jve_di" bpmnElement="SequenceFlow_0xo2jve">
|
||||
<di:waypoint x="544" y="120" />
|
||||
<di:waypoint x="611" y="120" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="SequenceFlow_0oa0av1_di" bpmnElement="SequenceFlow_0oa0av1">
|
||||
<di:waypoint x="377" y="350" />
|
||||
<di:waypoint x="444" y="350" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="SequenceFlow_0hxvd1d_di" bpmnElement="SequenceFlow_0hxvd1d">
|
||||
<di:waypoint x="544" y="350" />
|
||||
<di:waypoint x="611" y="350" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="SequenceFlow_1fgwvz0_di" bpmnElement="SequenceFlow_1fgwvz0">
|
||||
<di:waypoint x="711" y="350" />
|
||||
<di:waypoint x="772" y="350" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="SequenceFlow_17j00uv_di" bpmnElement="SequenceFlow_17j00uv">
|
||||
<di:waypoint x="661" y="160" />
|
||||
<di:waypoint x="661" y="240" />
|
||||
<di:waypoint x="327" y="240" />
|
||||
<di:waypoint x="327" y="310" />
|
||||
</bpmndi:BPMNEdge>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</bpmn:definitions>
|
|
@ -0,0 +1,128 @@
|
|||
from tests.base_test import BaseTest
|
||||
|
||||
from crc import session
|
||||
|
||||
from crc.models.data_store import DataStoreModel
|
||||
from crc.models.file import FileModel
|
||||
from crc.models.task_event import TaskEventModel
|
||||
from crc.services.workflow_service import WorkflowService
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
class TestDeleteTaskFileData(BaseTest):
|
||||
|
||||
def test_delete_task_file_data_validation(self):
|
||||
self.load_example_data()
|
||||
spec_model = self.load_test_spec('delete_task_file_data')
|
||||
rv = self.app.get('/v1.0/workflow-specification/%s/validate' % spec_model.id, headers=self.logged_in_headers())
|
||||
# Make sure we don't get json returned. This would indicate an error.
|
||||
self.assertEqual([], rv.json)
|
||||
|
||||
def test_delete_task_file_data(self):
|
||||
|
||||
self.load_example_data()
|
||||
|
||||
doc_code_1 = 'Study_Protocol_Document'
|
||||
doc_code_2 = 'Study_App_Doc'
|
||||
|
||||
workflow = self.create_workflow('delete_task_file_data')
|
||||
|
||||
# Make sure there are no files uploaded for workflow yet
|
||||
files = session.query(FileModel).filter(FileModel.workflow_id == workflow.id).all()
|
||||
self.assertEqual(0, len(files))
|
||||
|
||||
workflow_api = self.get_workflow_api(workflow)
|
||||
first_task = workflow_api.next_task
|
||||
|
||||
# Upload Single File
|
||||
data = {'file': (BytesIO(b"abcdef"), 'test_file.txt')}
|
||||
rv = self.app.post('/v1.0/file?study_id=%i&workflow_id=%s&task_spec_name=%s&form_field_key=%s' %
|
||||
(workflow.study_id, workflow.id, first_task.name, doc_code_1), data=data, follow_redirects=True,
|
||||
content_type='multipart/form-data', headers=self.logged_in_headers())
|
||||
self.assert_success(rv)
|
||||
file_id = rv.json['id']
|
||||
self.complete_form(workflow, first_task, {doc_code_1: {'id': file_id},
|
||||
'VerDate': '20210721'})
|
||||
|
||||
# Make sure we have 1 file
|
||||
files = session.query(FileModel).filter(FileModel.workflow_id == workflow.id).all()
|
||||
self.assertEqual(1, len(files))
|
||||
|
||||
# Make sure data store is set
|
||||
data_store = session.query(DataStoreModel).filter(DataStoreModel.file_id == file_id).all()
|
||||
self.assertEqual('VerDate', data_store[0].key)
|
||||
self.assertEqual('20210721', data_store[0].value)
|
||||
|
||||
workflow_api = self.get_workflow_api(workflow)
|
||||
second_task = workflow_api.next_task
|
||||
|
||||
# Upload 2 Files
|
||||
data = {'file': (BytesIO(b"abcdef"), 'test_file_1.txt')}
|
||||
rv = self.app.post('/v1.0/file?study_id=%i&workflow_id=%s&task_spec_name=%s&form_field_key=%s' %
|
||||
(workflow.study_id, workflow.id, first_task.name, doc_code_2), data=data, follow_redirects=True,
|
||||
content_type='multipart/form-data', headers=self.logged_in_headers())
|
||||
self.assert_success(rv)
|
||||
file_id_1 = rv.json['id']
|
||||
data = {'file': (BytesIO(b"ghijk"), 'test_file_2.txt')}
|
||||
rv = self.app.post('/v1.0/file?study_id=%i&workflow_id=%s&task_spec_name=%s&form_field_key=%s' %
|
||||
(workflow.study_id, workflow.id, first_task.name, doc_code_2), data=data, follow_redirects=True,
|
||||
content_type='multipart/form-data', headers=self.logged_in_headers())
|
||||
self.assert_success(rv)
|
||||
file_id_2 = rv.json['id']
|
||||
|
||||
self.complete_form(workflow, second_task, {'StudyAppDoc': [{'Study_App_Doc': {'id': file_id_1},
|
||||
'VerDate': '20210701',
|
||||
'ShortDesc': 'Short Description 1'},
|
||||
{'Study_App_Doc': {'id': file_id_2},
|
||||
'VerDate': '20210702',
|
||||
'ShortDesc': 'Short Description 2'}
|
||||
]})
|
||||
|
||||
# Make sure we have 2 more files
|
||||
files = session.query(FileModel).filter(FileModel.workflow_id == workflow.id).all()
|
||||
self.assertEqual(3, len(files))
|
||||
|
||||
# Make sure data stores are set for new files
|
||||
data_stores_1 = session.query(DataStoreModel).filter(DataStoreModel.file_id == file_id_1).all()
|
||||
for data_store in data_stores_1:
|
||||
if data_store.key == 'VerDate':
|
||||
self.assertEqual('20210701', data_store.value)
|
||||
elif data_store.key == 'ShortDesc':
|
||||
self.assertEqual('Short Description 1', data_store.value)
|
||||
|
||||
data_stores_2 = session.query(DataStoreModel).filter(DataStoreModel.file_id == file_id_2).all()
|
||||
for data_store in data_stores_2:
|
||||
if data_store.key == 'VerDate':
|
||||
self.assertEqual('20210702', data_store.value)
|
||||
elif data_store.key == 'ShortDesc':
|
||||
self.assertEqual('Short Description 2', data_store.value)
|
||||
|
||||
# Make sure we have something in task_events
|
||||
task_events = session.query(TaskEventModel).\
|
||||
filter(TaskEventModel.workflow_id == workflow.id).\
|
||||
filter(TaskEventModel.action == WorkflowService.TASK_ACTION_COMPLETE).all()
|
||||
for task_event in task_events:
|
||||
self.assertNotEqual({}, task_event.form_data)
|
||||
|
||||
workflow_api = self.get_workflow_api(workflow)
|
||||
third_task = workflow_api.next_task
|
||||
# This calls the delete task file data script
|
||||
self.complete_form(workflow, third_task, {})
|
||||
self.get_workflow_api(workflow)
|
||||
|
||||
# Make sure files, data_stores, and task_events are deleted
|
||||
data_stores = session.query(DataStoreModel).filter(DataStoreModel.file_id == file_id).all()
|
||||
data_stores_1 = session.query(DataStoreModel).filter(DataStoreModel.file_id == file_id_1).all()
|
||||
data_stores_2 = session.query(DataStoreModel).filter(DataStoreModel.file_id == file_id_2).all()
|
||||
files = session.query(FileModel).filter(FileModel.workflow_id == workflow.id).all()
|
||||
task_events = session.query(TaskEventModel).\
|
||||
filter(TaskEventModel.workflow_id == workflow.id).\
|
||||
filter(TaskEventModel.action == WorkflowService.TASK_ACTION_COMPLETE).all()
|
||||
|
||||
self.assertEqual(0, len(data_stores))
|
||||
self.assertEqual(0, len(data_stores_1))
|
||||
self.assertEqual(0, len(data_stores_2))
|
||||
self.assertEqual(0, len(files))
|
||||
for task_event in task_events:
|
||||
self.assertEqual({}, task_event.form_data)
|
Loading…
Reference in New Issue