Test for new script

This commit is contained in:
mike cullerton 2022-02-23 14:30:45 -05:00
parent b6a39dfd25
commit 679a875666
3 changed files with 164 additions and 0 deletions

View File

@ -0,0 +1,107 @@
<?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_1wrf54p" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
<bpmn:process id="Process_ModifySpreadsheet" name="Modify Spreadsheet" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_03wyga3</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_03wyga3" sourceRef="StartEvent_1" targetRef="Activity_FileUpload" />
<bpmn:sequenceFlow id="Flow_0msewj5" sourceRef="Activity_FileUpload" targetRef="Activity_GetModifyData" />
<bpmn:sequenceFlow id="Flow_0fpc32g" sourceRef="Activity_GetModifyData" targetRef="Activity_ModifySpreadsheet" />
<bpmn:sequenceFlow id="Flow_10ulj3l" sourceRef="Activity_ModifySpreadsheet" targetRef="Activity_DisplayResults" />
<bpmn:endEvent id="Event_1d07dls">
<bpmn:incoming>Flow_1tbcg16</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_1tbcg16" sourceRef="Activity_DisplayResults" targetRef="Event_1d07dls" />
<bpmn:userTask id="Activity_FileUpload" name="Upload Spreadsheet" camunda:formKey="FileUpload">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="Finance_BCA" label="&#39;File Upload&#39;" type="file">
<camunda:validation>
<camunda:constraint name="required" config="True" />
</camunda:validation>
</camunda:formField>
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_03wyga3</bpmn:incoming>
<bpmn:outgoing>Flow_0msewj5</bpmn:outgoing>
</bpmn:userTask>
<bpmn:scriptTask id="Activity_ModifySpreadsheet" name="Modify Spreadsheet">
<bpmn:incoming>Flow_0fpc32g</bpmn:incoming>
<bpmn:outgoing>Flow_10ulj3l</bpmn:outgoing>
<bpmn:script>result = modify_spreadsheet(upload_workflow_id, 'Finance_BCA', cell_indicator, input_text)</bpmn:script>
</bpmn:scriptTask>
<bpmn:manualTask id="Activity_DisplayResults" name="Display Modify Results">
<bpmn:documentation>## Modify Results
{{ results }}</bpmn:documentation>
<bpmn:incoming>Flow_10ulj3l</bpmn:incoming>
<bpmn:outgoing>Flow_1tbcg16</bpmn:outgoing>
</bpmn:manualTask>
<bpmn:userTask id="Activity_GetModifyData" name="Get Modify Data" camunda:formKey="ModifyData">
<bpmn:documentation>## File Upload
{{ Finance_BCA }}</bpmn:documentation>
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="upload_workflow_id" label="&#39;Upload Workflow ID&#39;" type="long">
<camunda:validation>
<camunda:constraint name="required" config="True" />
</camunda:validation>
</camunda:formField>
<camunda:formField id="cell_indicator" label="Cell Indicator" type="string">
<camunda:validation>
<camunda:constraint name="required" config="True" />
</camunda:validation>
</camunda:formField>
<camunda:formField id="input_text" label="Input Text" type="string">
<camunda:validation>
<camunda:constraint name="required" config="True" />
</camunda:validation>
</camunda:formField>
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_0msewj5</bpmn:incoming>
<bpmn:outgoing>Flow_0fpc32g</bpmn:outgoing>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_ModifySpreadsheet">
<bpmndi:BPMNEdge id="Flow_1tbcg16_di" bpmnElement="Flow_1tbcg16">
<di:waypoint x="850" y="117" />
<di:waypoint x="912" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_10ulj3l_di" bpmnElement="Flow_10ulj3l">
<di:waypoint x="691" y="117" />
<di:waypoint x="750" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0fpc32g_di" bpmnElement="Flow_0fpc32g">
<di:waypoint x="530" y="117" />
<di:waypoint x="591" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0msewj5_di" bpmnElement="Flow_0msewj5">
<di:waypoint x="370" y="117" />
<di:waypoint x="430" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_03wyga3_di" bpmnElement="Flow_03wyga3">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" 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_1d07dls_di" bpmnElement="Event_1d07dls">
<dc:Bounds x="912" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0jut75d_di" bpmnElement="Activity_FileUpload">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0nqp85l_di" bpmnElement="Activity_DisplayResults">
<dc:Bounds x="750" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0hn4ju2_di" bpmnElement="Activity_GetModifyData">
<dc:Bounds x="430" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0uk32ds_di" bpmnElement="Activity_ModifySpreadsheet">
<dc:Bounds x="591" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

Binary file not shown.

View File

@ -0,0 +1,57 @@
from tests.base_test import BaseTest
from crc import app, session
from crc.models.file import FileModel, FileDataModel
from crc.services.user_file_service import UserFileService
from io import BytesIO
from openpyxl import load_workbook
import os
class TestModifySpreadsheet(BaseTest):
@staticmethod
def get_sheet(workflow_id, irb_doc_code):
spreadsheet = session.query(FileModel). \
filter(FileModel.workflow_id == workflow_id). \
filter(FileModel.irb_doc_code == irb_doc_code). \
first()
spreadsheet_data = session.query(FileDataModel). \
filter(FileDataModel.file_model_id == spreadsheet.id). \
first()
workbook = load_workbook(BytesIO(spreadsheet_data.data))
sheet = workbook.active
return sheet
def test_modify_spreadsheet(self):
irb_doc_code = 'Finance_BCA'
cell_indicator = 'C4'
input_text = 'This is my input text.'
workflow = self.create_workflow('modify_spreadsheet')
workflow_api = self.get_workflow_api(workflow)
task = workflow_api.next_task
filepath = os.path.join(app.root_path, '..', 'tests', 'data',
'modify_spreadsheet', 'test_spreadsheet.xlsx')
with open(filepath, 'br') as f_open:
ss_data = f_open.read()
file_model = UserFileService.add_workflow_file(workflow_id=workflow.id,
task_spec_name=task.name,
name="test_spreadsheet.xlsx", content_type="text",
binary_data=ss_data, irb_doc_code=irb_doc_code)
workflow_api = self.complete_form(workflow, task, {irb_doc_code: {'id': file_model.id}})
sheet = self.get_sheet(workflow.id, irb_doc_code)
self.assertEqual(None, sheet[cell_indicator].value)
task = workflow_api.next_task
self.complete_form(workflow, task, {'upload_workflow_id': workflow.id,
'cell_indicator': cell_indicator,
'input_text': input_text})
sheet = self.get_sheet(workflow.id, irb_doc_code)
self.assertEqual(input_text, sheet[cell_indicator].value)