spiff-arena/tests/SpiffWorkflow/bpmn/CallActivityEndEventTest.py

74 lines
3.1 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
import unittest
from SpiffWorkflow.bpmn.PythonScriptEngine import PythonScriptEngine
from SpiffWorkflow.bpmn.workflow import BpmnWorkflow
Squashed 'SpiffWorkflow/' changes from 4195453a4..1f51db962 1f51db962 Merge pull request #283 from sartography/feature/better_errors 69fb4967e Patching up some bugs and logical disconnects as I test out the errors. cf5be0096 * Making a few more things consistent in the error messages -- so there isn't filename for validation errors, and file_name for WorkflowExceptions. Same for line_number vs sourceline. * Assure than an error_type is consistently set on exceptions. * ValidationExceptions should not bild up a detailed error message that replicates information available within it. 440ee16c8 Responding to some excellent suggestions from Elizabeth: 655e415e1 Merge pull request #282 from subhakarks/fix-workfowspec-dump 1f6d3cf4e Explain that the error happened in a pre-script or post script. 8119abd14 Added a top level SpiffWorklowException that all exceptions inherit from. Aside from a message string you can append information to these exceptions with "add_note", which is a new method that all exceptions have starting in python 3.11 Switched arguments to the WorkflowException, WorkflowTaskException - which now always takes a string message as the first argument, and named arguments thereafter to be consistent with all other error messages in Python. Consistently raise ValidationExceptions whenever we encounter an error anywhere during parsing of xml. The BPMN/WorkflowTaskExecException is removed, in favor of just calling a WorkflowTaskException. There is nothing BPMN Specific in the logic, so no need for this. Consolidated error message logic so that things like "Did you mean" just get added by default if possible. So we don't have to separately deal with that logic each time. Better Error messages for DMN (include row number as a part of the error information) 13463b5c5 fix for workflowspec dump be26100bc Merge pull request #280 from sartography/feature/remove-unused-bpmn-attributes-and-methods 23a5c1d70 remove 'entering_* methods 4e5875ec8 remove sequence flow 5eed83ab1 Merge pull request #278 from sartography/feature/remove-old-serializer 614f1c68a remove compact serializer and references e7e410d4a remove old serializer and references git-subtree-dir: SpiffWorkflow git-subtree-split: 1f51db962ccaed5810f5d0f7d76a932f056430ab
2023-01-19 15:47:07 +00:00
from SpiffWorkflow.exceptions import WorkflowTaskException
Squashed 'SpiffWorkflow/' changes from bee868d38..96ad2a2b0 96ad2a2b0 Merge pull request #311 from sartography/feature/error-message-on-bad-child-task 3fb69038d Merge remote-tracking branch 'origin/main' into feature/error-message-on-bad-child-task df703ebb8 Merge remote-tracking branch 'origin/feature/add_task_not_found_error' d6e244bcf also raise TaskNotFoundException from bpmn workflow w/ burnettk 37d7ae679 Merge pull request #310 from sartography/feature/add_task_not_found_error 7f4d38ce2 give us a better error if for some reason a task does not exist b98efbd20 added an exception for task not found w/ burnettk e1add839d Merge pull request #308 from sartography/bugfix/execute-event-gateways-on-ready 964c0231a do not predict tasks when deserializing, add method to predict all unfinished tasks 114f87aa9 update event gateway 62454c99c Merge pull request #307 from sartography/feature/standardize-task-execution a087d29ea update task_spec._run to return a boolean & misc cleanup 9864d753d reenable recursion test 1bb1246a0 rename methods & move ready_before tasks from run to ready 12ce08519 move event task execution to run d51bb68eb cleanup predictions 5e05458a3 make all tasks execute when run rather than completed (except bpmn events) 273d7b325 create a run method for tasks 3c3345c85 Merge pull request #306 from sartography/feature/create-core-test-package ed85547d7 hopefully fix CI job, also update some deprecated assertions 80d68c231 cleanup around finding tasks ea5ffff41 create tests based on individual patterns afe41fba1 move core tests into one package c075d52bc remove locks from task spec -- they don't do anything d78c7cc04 reorganize so that related methods are near each other f162aac43 Merge pull request #305 from sartography/feature/remove-loop-reset 6cad29817 'fix' old serializer to remove loop resets -- or at least get the tests to pass a95d2fc12 add serialization migration that removes loop resets c076175c8 account for DST in timers 42b483054 Merge pull request #303 from sartography/bugfix/execute-tasks-on-ready 2bb08aae1 update script/service tasks to execute on ready 0bd23a0ab fix scripts in business rule tasks 13034aaf1 prevent loop reset tasks from being inserted 3fb80518d update join execution model git-subtree-dir: SpiffWorkflow git-subtree-split: 96ad2a2b060deb445c39374f065690023351de19
2023-04-07 15:46:14 +00:00
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.assertTrue(self.workflow.is_completed())
self.assertIsInstance(self.workflow.script_engine, CustomScriptEngine)
if save_restore:
self.save_restore()
# We have to reset the script engine after deserialize.
self.workflow.script_engine = CustomScriptEngine()
# 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.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')
Squashed 'SpiffWorkflow/' changes from 4195453a4..1f51db962 1f51db962 Merge pull request #283 from sartography/feature/better_errors 69fb4967e Patching up some bugs and logical disconnects as I test out the errors. cf5be0096 * Making a few more things consistent in the error messages -- so there isn't filename for validation errors, and file_name for WorkflowExceptions. Same for line_number vs sourceline. * Assure than an error_type is consistently set on exceptions. * ValidationExceptions should not bild up a detailed error message that replicates information available within it. 440ee16c8 Responding to some excellent suggestions from Elizabeth: 655e415e1 Merge pull request #282 from subhakarks/fix-workfowspec-dump 1f6d3cf4e Explain that the error happened in a pre-script or post script. 8119abd14 Added a top level SpiffWorklowException that all exceptions inherit from. Aside from a message string you can append information to these exceptions with "add_note", which is a new method that all exceptions have starting in python 3.11 Switched arguments to the WorkflowException, WorkflowTaskException - which now always takes a string message as the first argument, and named arguments thereafter to be consistent with all other error messages in Python. Consistently raise ValidationExceptions whenever we encounter an error anywhere during parsing of xml. The BPMN/WorkflowTaskExecException is removed, in favor of just calling a WorkflowTaskException. There is nothing BPMN Specific in the logic, so no need for this. Consolidated error message logic so that things like "Did you mean" just get added by default if possible. So we don't have to separately deal with that logic each time. Better Error messages for DMN (include row number as a part of the error information) 13463b5c5 fix for workflowspec dump be26100bc Merge pull request #280 from sartography/feature/remove-unused-bpmn-attributes-and-methods 23a5c1d70 remove 'entering_* methods 4e5875ec8 remove sequence flow 5eed83ab1 Merge pull request #278 from sartography/feature/remove-old-serializer 614f1c68a remove compact serializer and references e7e410d4a remove old serializer and references git-subtree-dir: SpiffWorkflow git-subtree-split: 1f51db962ccaed5810f5d0f7d76a932f056430ab
2023-01-19 15:47:07 +00:00
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\)')
def suite():
return unittest.TestLoader().loadTestsFromTestCase(CallActivityTest)
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())