Assert that we have the correct file name, depending on whether we pass the optional file_name parameter

Modify the bpmn file to accept the optional file_name
This commit is contained in:
mike cullerton 2022-05-23 14:22:14 -04:00
parent 03384789d4
commit e92be44b6c
2 changed files with 38 additions and 14 deletions

View File

@ -8,13 +8,14 @@
<bpmn:userTask id="Activity_GetData" name="Get Data" camunda:formKey="DataForm">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="file_name" label="'File Name'" type="string" />
<camunda:formField id="irb_doc_code" label="'IRB Doc Code'" type="enum">
<camunda:formField id="template_file_name" label="&#39;File Name&#39;" type="string" />
<camunda:formField id="irb_doc_code" label="&#39;IRB Doc Code&#39;" type="enum">
<camunda:value id="Study_App_Doc" name="Study_App_Doc" />
<camunda:value id="Study_Protocol" name="Study_Protocol" />
</camunda:formField>
<camunda:formField id="name" label="'Name'" type="string" defaultValue="World" />
<camunda:formField id="name" label="&#39;Name&#39;" type="string" defaultValue="World" />
<camunda:formField id="include_me" type="string" />
<camunda:formField id="file_name" label="&#39;File Name&#39;" type="string" />
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1lthj06</bpmn:incoming>
@ -26,7 +27,10 @@
<bpmn:outgoing>Flow_0ltznd4</bpmn:outgoing>
<bpmn:script>print(f'name is {name}.')
print(f'include_me is {include_me}')
result = complete_template(file_name, irb_doc_code)</bpmn:script>
if 'file_name' in globals():
result = complete_template(template_file_name, irb_doc_code, file_name)
else:
result = complete_template(template_file_name, irb_doc_code)</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_0ltznd4" sourceRef="Activity_CompleteTemplate" targetRef="Activity_DisplayData" />
<bpmn:manualTask id="Activity_DisplayData" name="Display Data">
@ -61,18 +65,18 @@ result = complete_template(file_name, irb_doc_code)</bpmn:script>
<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_10trg2t_di" bpmnElement="Activity_GetData">
<dc:Bounds x="273" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1u6kbns_di" bpmnElement="Activity_CompleteTemplate">
<dc:Bounds x="432" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_14dp1gz_di" bpmnElement="Activity_DisplayData">
<dc:Bounds x="590" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0edltir_di" bpmnElement="Event_0edltir">
<dc:Bounds x="752" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1u6kbns_di" bpmnElement="Activity_CompleteTemplate">
<dc:Bounds x="432" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_10trg2t_di" bpmnElement="Activity_GetData">
<dc:Bounds x="273" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -39,25 +39,45 @@ class TestCompleteTemplate(unittest.TestCase):
class TestEmbeddedTemplate(BaseTest):
def test_embedded_template(self):
def run_docx_embedded_workflow(self, data):
self.create_reference_document()
workflow = self.create_workflow('docx_embedded')
workflow_api = self.get_workflow_api(workflow)
task = workflow_api.next_task
workflow_api = self.complete_form(workflow, task, data)
return workflow_api
def test_embedded_template(self):
data = {'include_me': 'Hello {{ name }}!',
'name': 'World',
'file_name': 'simple.docx',
'template_file_name': 'simple.docx',
'irb_doc_code': 'Study_App_Doc'}
self.complete_form(workflow, task, data)
workflow_api = self.run_docx_embedded_workflow(data)
# Get the file data created for us in the workflow
file_model = session.query(FileModel).\
filter(FileModel.workflow_id == workflow.id).\
filter(FileModel.workflow_id == workflow_api.id).\
filter(FileModel.irb_doc_code == 'Study_App_Doc').\
first()
# If we don't pass file_name, name should be set to template_file_name
self.assertEqual(data['template_file_name'], file_model.name)
# read the data as a word document
document = docx.Document(BytesIO(file_model.data))
# Make sure 'Hello World!' is there
self.assertEqual('Hello World!', document.paragraphs[4].text)
data = {'include_me': 'Hello {{ name }}!',
'name': 'World',
'template_file_name': 'simple.docx',
'irb_doc_code': 'Study_App_Doc',
'file_name': 'test_file_name.docx'}
workflow_api = self.run_docx_embedded_workflow(data)
file_model = session.query(FileModel).\
filter(FileModel.workflow_id == workflow_api.id).\
filter(FileModel.irb_doc_code == 'Study_App_Doc').\
first()
# If we do pass file_name, name should be set to file_name
self.assertEqual(data['file_name'], file_model.name)