mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-02-19 13:14:25 +00:00
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
85 lines
3.6 KiB
Python
85 lines
3.6 KiB
Python
from SpiffWorkflow.exceptions import SpiffWorkflowException
|
|
from SpiffWorkflow.task import TaskState
|
|
from .BaseTestCase import BaseTestCase
|
|
from SpiffWorkflow.bpmn.workflow import BpmnWorkflow
|
|
|
|
|
|
class PrescriptPostsciptTest(BaseTestCase):
|
|
|
|
def testTask(self):
|
|
self.task_test()
|
|
|
|
def testCallActivity(self):
|
|
self.call_activity_test()
|
|
|
|
def testTaskSaveRestore(self):
|
|
self.task_test(True)
|
|
|
|
def testCallActivitySaveRestore(self):
|
|
self.call_activity_test(True)
|
|
|
|
def testDataObject(self):
|
|
|
|
spec, subprocesses = self.load_workflow_spec('prescript_postscript_data_object.bpmn', 'Process_1')
|
|
self.workflow = BpmnWorkflow(spec, subprocesses)
|
|
# Set a on the workflow and b in the first task.
|
|
self.workflow.data['a'] = 1
|
|
self.set_process_data({'b': 2})
|
|
ready_tasks = self.workflow.get_tasks(TaskState.READY)
|
|
# This execute the same script as task_test
|
|
ready_tasks[0].complete()
|
|
# a should be removed, b should be unchanged, and c and z should be present (but not x & y)
|
|
self.assertDictEqual({'b': 2, 'c': 12, 'z': 6}, ready_tasks[0].data)
|
|
|
|
def task_test(self, save_restore=False):
|
|
|
|
spec, subprocesses = self.load_workflow_spec('prescript_postscript.bpmn', 'Process_1')
|
|
self.workflow = BpmnWorkflow(spec, subprocesses)
|
|
if save_restore:
|
|
self.save_restore()
|
|
|
|
self.set_process_data({'a': 1, 'b': 2})
|
|
ready_tasks = self.workflow.get_tasks(TaskState.READY)
|
|
# The prescript sets x, y = a * 2, b * 2 and creates the variable z = x + y
|
|
# The postscript sets c = z * 2 and deletes x and y
|
|
# a and b should remain unchanged, and c and z should be added
|
|
ready_tasks[0].complete()
|
|
self.assertDictEqual({'a': 1, 'b': 2, 'c': 12, 'z': 6}, ready_tasks[0].data)
|
|
|
|
def test_for_error(self, save_restore=False):
|
|
|
|
spec, subprocesses = self.load_workflow_spec('prescript_postscript.bpmn', 'Process_1')
|
|
self.workflow = BpmnWorkflow(spec, subprocesses)
|
|
if save_restore:
|
|
self.save_restore()
|
|
ready_tasks = self.workflow.get_tasks(TaskState.READY)
|
|
# Calling do-engine steps without setting variables will raise an exception.
|
|
with self.assertRaises(SpiffWorkflowException) as se:
|
|
self.workflow.do_engine_steps()
|
|
ex = se.exception
|
|
self.assertIn("Error occurred in the Pre-Script", str(ex))
|
|
|
|
def call_activity_test(self, save_restore=False):
|
|
|
|
spec, subprocesses = self.load_workflow_spec('prescript_postscript_*.bpmn', 'parent')
|
|
self.workflow = BpmnWorkflow(spec, subprocesses)
|
|
if save_restore:
|
|
self.save_restore()
|
|
|
|
# Set the data and proceed. The call activity needs in_data and creates out_data
|
|
# The prescript sets in_data = old and creates out_data; the postscript copies out_data into new
|
|
# in_data and out_data remain (they're created my the calling task NOT the subprocess) and
|
|
# we did not explicitly remove them. We don't implicitly remove them because this would be
|
|
# the wrong behavior for regular tasks.
|
|
self.set_process_data({'old': 'hello'})
|
|
task = self.workflow.get_tasks_from_spec_name('Activity_0g9bcsc')[0]
|
|
# The original data is still present and unchanged
|
|
self.assertEqual(task.data.get('old'), 'hello')
|
|
# The new data has been added
|
|
self.assertEqual(task.data.get('new'), 'HELLO')
|
|
|
|
def set_process_data(self, data):
|
|
ready_tasks = self.workflow.get_tasks(TaskState.READY)
|
|
ready_tasks[0].set_data(**data)
|
|
self.workflow.do_engine_steps()
|