spiff-arena/tests/SpiffWorkflow/bpmn/CallActivityEndEventTest.py
burnettk c4f4e008d8 Squashed 'SpiffWorkflow/' changes from 96ad2a2b0..73886584b
73886584b Merge pull request #315 from sartography/feature/new-task-states
a04fdd311 Merge remote-tracking branch 'origin/main' into feature/new-task-states
3d376bf9a documentation and comment updates
7e368ee4b copy edit
e7b9fe91c typo
eceef15a7 Called elements (#316)
5a0fd2774 add serialization migration
7211e67ee Merge pull request #314 from sartography/bugfix/data-object-references
403acc1f5 use same data objects & references in subprocesses after deserialization
c54091dee add two more states to spiff
fa04a14a7 clean up script engine a little bit
162a1c5f5 override create parser in spiff package to allow duplicate process names
98a1b37e0 Merge pull request #312 from sartography/bugfix/run-boundary-events-from-engine-steps
067d6a723 do not execute boundary events in catch
1c877dd76 send external events to top level workflow

git-subtree-dir: SpiffWorkflow
git-subtree-split: 73886584b17c7d11a9713d0c4526ed41e411fc45
2023-04-21 11:22:52 -04:00

78 lines
3.2 KiB
Python

# -*- coding: utf-8 -*-
import unittest
from SpiffWorkflow.bpmn.PythonScriptEngine import PythonScriptEngine
from SpiffWorkflow.bpmn.workflow import BpmnWorkflow
from SpiffWorkflow.exceptions import WorkflowTaskException
from SpiffWorkflow.task import TaskState
from .BpmnWorkflowTestCase import BpmnWorkflowTestCase
__author__ = 'kellym'
class CallActivityTest(BpmnWorkflowTestCase):
def setUp(self):
self.spec, self.subprocesses = self.load_workflow_spec('call_activity_*.bpmn', 'Process_8200379')
def testRunThroughHappy(self):
self.workflow = BpmnWorkflow(self.spec, self.subprocesses)
self.workflow.do_engine_steps()
def testCallActivityHasSameScriptEngine(self):
self.runCallActivityWithCustomScript()
def testCallActivityHasSameScriptEngineAfterSaveRestore(self):
self.runCallActivityWithCustomScript(save_restore=True)
def runCallActivityWithCustomScript(self, save_restore=False):
class CustomScriptEngine(PythonScriptEngine):
pass
self.workflow = BpmnWorkflow(self.spec, self.subprocesses,
script_engine=CustomScriptEngine())
self.workflow.do_engine_steps()
self.complete_subworkflow()
self.assertTrue(self.workflow.is_completed())
self.assertIsInstance(self.workflow.script_engine, CustomScriptEngine)
if save_restore:
self.save_restore()
# Get the subworkflow
sub_task = self.workflow.get_tasks_from_spec_name('Sub_Bpmn_Task')[0]
sub_workflow = sub_task.workflow
self.assertNotEqual(sub_workflow, self.workflow)
self.assertIsInstance(self.workflow.script_engine, CustomScriptEngine)
self.assertEqual(sub_workflow.script_engine, self.workflow.script_engine)
def test_call_activity_allows_removal_of_data(self):
# If a call activity alters the data - removing existing keys, that
# data should be removed in the final output as well.
self.workflow = BpmnWorkflow(self.spec, self.subprocesses)
self.workflow.do_engine_steps()
self.complete_subworkflow()
self.assertTrue(self.workflow.is_completed())
self.assertNotIn('remove_this_var', self.workflow.last_task.data.keys())
def test_call_acitivity_errors_include_task_trace(self):
error_spec = self.subprocesses.get('ErroringBPMN')
error_spec, subprocesses = self.load_workflow_spec('call_activity_*.bpmn', 'ErroringBPMN')
with self.assertRaises(WorkflowTaskException) as context:
self.workflow = BpmnWorkflow(error_spec, subprocesses)
self.workflow.do_engine_steps()
self.assertEquals(2, len(context.exception.task_trace))
self.assertRegexpMatches(context.exception.task_trace[0], 'Create Data \(.*?call_activity_call_activity.bpmn\)')
self.assertRegexpMatches(context.exception.task_trace[1], 'Get Data Call Activity \(.*?call_activity_with_error.bpmn\)')
task = self.workflow.get_tasks_from_spec_name('Sub_Bpmn_Task')[0]
self.assertEqual(task.state, TaskState.ERROR)
def suite():
return unittest.TestLoader().loadTestsFromTestCase(CallActivityTest)
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())