We now raise an error if the spreadsheet does not exist.
Added test for case where the spreadsheet does not exist
This commit is contained in:
parent
1fe1ce2e22
commit
0b3187889d
|
@ -35,10 +35,10 @@ class ModifySpreadsheet(Script):
|
|||
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
|
||||
parameters = self.get_parameters(args, kwargs)
|
||||
if len(parameters) == 3:
|
||||
return parameters
|
||||
return True
|
||||
else:
|
||||
raise ApiError(code='missing_parameters',
|
||||
message='The modify_spreadsheet script requires 4 parameters: upload_workflow_id, irb_doc_code, cell, and text')
|
||||
message='The modify_spreadsheet script requires 3 parameters: irb_doc_code, cell, and text')
|
||||
|
||||
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
|
||||
parameters = self.get_parameters(args, kwargs)
|
||||
|
@ -48,16 +48,19 @@ class ModifySpreadsheet(Script):
|
|||
filter(FileModel.workflow_id == workflow_id). \
|
||||
filter(FileModel.irb_doc_code == parameters['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
|
||||
sheet[parameters['cell']] = parameters['text']
|
||||
data_string = save_virtual_workbook(workbook)
|
||||
spreadsheet_data.data = data_string
|
||||
session.commit()
|
||||
return parameters
|
||||
if spreadsheet:
|
||||
spreadsheet_data = session.query(FileDataModel).\
|
||||
filter(FileDataModel.file_model_id==spreadsheet.id).\
|
||||
first()
|
||||
workbook = load_workbook(BytesIO(spreadsheet_data.data))
|
||||
sheet = workbook.active
|
||||
sheet[parameters['cell']] = parameters['text']
|
||||
data_string = save_virtual_workbook(workbook)
|
||||
spreadsheet_data.data = data_string
|
||||
session.commit()
|
||||
else:
|
||||
raise ApiError(code='missing_spreadsheet',
|
||||
message=f"The spreadshhet you want to modify does not exist. Workflow ID is {workflow_id}, and IRB Doc Code is {parameters['irb_doc_code']}")
|
||||
else:
|
||||
raise ApiError(code='missing_parameters',
|
||||
message='The modify_spreadsheet script requires 4 parameters: upload_workflow_id, irb_doc_code, cell, and text')
|
||||
message='The modify_spreadsheet script requires 3 parameters: irb_doc_code, cell, and text')
|
||||
|
|
|
@ -7,11 +7,10 @@
|
|||
<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:sequenceFlow id="Flow_10ulj3l" sourceRef="Activity_ModifySpreadsheet" targetRef="Event_1d07dls" />
|
||||
<bpmn:endEvent id="Event_1d07dls">
|
||||
<bpmn:incoming>Flow_1tbcg16</bpmn:incoming>
|
||||
<bpmn:incoming>Flow_10ulj3l</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>
|
||||
|
@ -28,14 +27,8 @@
|
|||
<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('Finance_BCA', cell_indicator, input_text)</bpmn:script>
|
||||
<bpmn:script>modify_spreadsheet('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>
|
||||
|
@ -59,13 +52,9 @@
|
|||
</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" />
|
||||
<di:waypoint x="912" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_0fpc32g_di" bpmnElement="Flow_0fpc32g">
|
||||
<di:waypoint x="530" y="117" />
|
||||
|
@ -88,15 +77,12 @@
|
|||
<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 id="Activity_0uk32ds_di" bpmnElement="Activity_ModifySpreadsheet">
|
||||
<dc:Bounds x="591" 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>
|
||||
|
|
|
@ -12,6 +12,19 @@ import os
|
|||
|
||||
class TestModifySpreadsheet(BaseTest):
|
||||
|
||||
def upload_spreadsheet(self, workflow, task, irb_doc_code):
|
||||
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}})
|
||||
return workflow_api
|
||||
|
||||
@staticmethod
|
||||
def get_sheet(workflow_id, irb_doc_code):
|
||||
spreadsheet = session.query(FileModel). \
|
||||
|
@ -34,16 +47,7 @@ class TestModifySpreadsheet(BaseTest):
|
|||
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}})
|
||||
workflow_api = self.upload_spreadsheet(workflow, task, irb_doc_code)
|
||||
|
||||
sheet = self.get_sheet(workflow.id, irb_doc_code)
|
||||
self.assertEqual(None, sheet[cell_indicator].value)
|
||||
|
@ -54,3 +58,21 @@ class TestModifySpreadsheet(BaseTest):
|
|||
|
||||
sheet = self.get_sheet(workflow.id, irb_doc_code)
|
||||
self.assertEqual(input_text, sheet[cell_indicator].value)
|
||||
|
||||
def test_missing_spreadsheet(self):
|
||||
"""The modify_spreadsheet has Finance_BCA hard-coded as the spreadsheet to modify.
|
||||
In this test we upload a spreadsheet with a different doc code,
|
||||
and assert that we raise an error when the Finance_BCA spreadsheet does not exist"""
|
||||
irb_doc_code = 'Finance_GPRF'
|
||||
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
|
||||
|
||||
workflow_api = self.upload_spreadsheet(workflow, task, irb_doc_code)
|
||||
task = workflow_api.next_task
|
||||
with self.assertRaises(AssertionError):
|
||||
self.complete_form(workflow, task, {'cell_indicator': cell_indicator,
|
||||
'input_text': input_text})
|
||||
|
|
Loading…
Reference in New Issue