mirror of
https://github.com/sartography/spiff-arena.git
synced 2025-01-16 04:24:20 +00:00
e53d860b40
8d820dce1f Track spiff step details more granularly (#17) 426da26d8f Clear the remaining __init__.py imports in SpiffWorkflow (#14) 9a1d1c484a Fix FutureWarning in SpiffWorkflow (#16) git-subtree-dir: SpiffWorkflow git-subtree-split: 8d820dce1f439bb76bc07e39629832d998d6f634
76 lines
2.9 KiB
Python
76 lines
2.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
import unittest
|
|
|
|
from SpiffWorkflow.bpmn.specs.events.event_definitions import CancelEventDefinition, SignalEventDefinition
|
|
from SpiffWorkflow.task import TaskState
|
|
from SpiffWorkflow.bpmn.workflow import BpmnWorkflow
|
|
from tests.SpiffWorkflow.bpmn.BpmnWorkflowTestCase import BpmnWorkflowTestCase
|
|
|
|
__author__ = 'kellym'
|
|
|
|
|
|
class MultipleEventsTest(BpmnWorkflowTestCase):
|
|
|
|
def setUp(self):
|
|
self.spec, self.subprocesses = self.load_workflow_spec('multipleEvents.bpmn', 'SignalAndCancel')
|
|
self.workflow = BpmnWorkflow(self.spec, self.subprocesses)
|
|
self.workflow.do_engine_steps()
|
|
ready_tasks = self.workflow.get_tasks(TaskState.READY)
|
|
self.assertEqual("hello", ready_tasks[0].get_name())
|
|
|
|
def test_cancel_does_nothing_if_no_one_is_listening(self,save_restore = False):
|
|
|
|
# Send cancel notifications to the workflow
|
|
self.workflow.catch(SignalEventDefinition('cancel')) # generate a cancel signal.
|
|
self.workflow.catch(CancelEventDefinition())
|
|
|
|
# Nothing should have happened.
|
|
ready_tasks = self.workflow.get_tasks(TaskState.READY)
|
|
self.assertEqual("hello", ready_tasks[0].get_name())
|
|
|
|
def test_cancel_works_with_signal(self,save_restore = False):
|
|
|
|
task = self.workflow.get_tasks(TaskState.READY)[0]
|
|
|
|
# Move to User Task 1
|
|
self.workflow.complete_task_from_id(task.id)
|
|
self.workflow.do_engine_steps()
|
|
task = self.workflow.get_tasks(TaskState.READY)[0]
|
|
self.assertEqual('UserTaskOne', task.get_name())
|
|
|
|
# Send cancel notifications to the workflow
|
|
self.workflow.catch(SignalEventDefinition('cancel')) # generate a cancel signal.
|
|
self.workflow.catch(CancelEventDefinition())
|
|
self.workflow.do_engine_steps()
|
|
|
|
# The cancel event should have been called.
|
|
self.assertEqual("cancel_signal", self.workflow.last_task.data['cancel'])
|
|
|
|
|
|
def test_cancel_works_with_cancel_Event(self,save_restore = False):
|
|
|
|
task = self.workflow.get_tasks(TaskState.READY)[0]
|
|
|
|
# Move to User Task 2
|
|
self.workflow.complete_task_from_id(task.id)
|
|
self.workflow.do_engine_steps()
|
|
task = self.workflow.get_tasks(TaskState.READY)[0]
|
|
self.workflow.complete_task_from_id(task.id)
|
|
self.workflow.do_engine_steps()
|
|
task = self.workflow.get_tasks(TaskState.READY)[0]
|
|
self.assertEqual('UserTaskTwo', task.get_name())
|
|
|
|
# Send cancel notifications to the workflow
|
|
self.workflow.catch(SignalEventDefinition('cancel')) # generate a cancel signal.
|
|
self.workflow.catch(CancelEventDefinition())
|
|
self.workflow.do_engine_steps()
|
|
|
|
# The cancel event shave h
|
|
self.assertEqual("cancel_event", self.workflow.last_task.data['cancel'])
|
|
|
|
|
|
def suite():
|
|
return unittest.TestLoader().loadTestsFromTestCase(MultipleEventsTest)
|
|
if __name__ == '__main__':
|
|
unittest.TextTestRunner(verbosity=2).run(suite())
|