mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-01-09 17:55:48 +00:00
1bed0fb3ee
cd4da465 Merge pull request #264 from sartography/bugfix/dmn-equality-with-boolean 414a59eb disambiguate DMN expressions eea53c91 Merge pull request #263 from sartography/feature/cleanup-task-completion d248d5b1 execute postscript before other complete hook tasks c09f1a90 streamline predict & remove some duplicated calls to it 64c21791 remove duplicate calls to update 4ca1076d move task update to _on_complete to ensure data is copied consistently after task related activities are done d037a7eb small changes for readability 025bc30f Quick patch -- is_executable needs to be accurate immediately. 14d3d8c3 Merge pull request #262 from sartography/feature/parser_info_features 849c223e We are jumping through a lot of complex xml parsing in SpiffWorkflow-Backend because we need to know some basic information about a BPMN process at the moment it is saved. Rather than do that work in the backend, it seems better to have SpiffWorkflow handle parsing the xml and providing a bit of metadata, including: git-subtree-dir: SpiffWorkflow git-subtree-split: cd4da465e125ca1ae1b57d227bfa324d9d4c507c
132 lines
4.5 KiB
Python
132 lines
4.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import sys
|
|
import unittest
|
|
import os
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..'))
|
|
|
|
from SpiffWorkflow.specs.WorkflowSpec import WorkflowSpec
|
|
from SpiffWorkflow.specs.SubWorkflow import SubWorkflow
|
|
from SpiffWorkflow.serializer.prettyxml import XmlSerializer
|
|
from SpiffWorkflow.task import TaskState
|
|
from SpiffWorkflow.workflow import Workflow
|
|
|
|
|
|
class TaskSpecTest(unittest.TestCase):
|
|
CORRELATE = SubWorkflow
|
|
|
|
def testConstructor(self):
|
|
pass # FIXME
|
|
|
|
def testSerialize(self):
|
|
pass # FIXME
|
|
|
|
def testTest(self):
|
|
pass # FIXME
|
|
|
|
def load_workflow_spec(self, folder, f):
|
|
file = os.path.join(
|
|
os.path.dirname(__file__), '..', 'data', 'spiff', folder, f)
|
|
serializer = XmlSerializer()
|
|
with open(file) as fp:
|
|
xml = fp.read()
|
|
self.wf_spec = WorkflowSpec.deserialize(
|
|
serializer, xml, filename=file)
|
|
self.workflow = Workflow(self.wf_spec)
|
|
|
|
def do_next_unique_task(self, name):
|
|
# This method asserts that there is only one ready task! The specified
|
|
# one - and then completes it
|
|
for task in self.workflow.get_tasks(TaskState.WAITING):
|
|
task.task_spec._update(task)
|
|
ready_tasks = self.workflow.get_tasks(TaskState.READY)
|
|
self.assertEqual(1, len(ready_tasks))
|
|
task = ready_tasks[0]
|
|
self.assertEqual(name, task.task_spec.name)
|
|
task.complete()
|
|
|
|
def do_next_named_step(self, name, other_ready_tasks):
|
|
# This method completes a single task from the specified set of ready
|
|
# tasks
|
|
ready_tasks = self.workflow.get_tasks(TaskState.READY)
|
|
all_tasks = sorted([name] + other_ready_tasks)
|
|
self.assertEqual(
|
|
all_tasks, sorted([t.task_spec.name for t in ready_tasks]))
|
|
task = list([t for t in ready_tasks if t.task_spec.name == name])[0]
|
|
task.complete()
|
|
|
|
def test_block_to_subworkflow(self):
|
|
self.load_workflow_spec('data', 'block_to_subworkflow.xml')
|
|
self.do_next_unique_task('Start')
|
|
self.do_next_unique_task('first')
|
|
|
|
# Inner. The subworkflow task will complete automatically after the subwokflow completes
|
|
self.do_next_unique_task('Start')
|
|
self.do_next_unique_task('first')
|
|
self.do_next_unique_task('last')
|
|
self.do_next_unique_task('End')
|
|
|
|
# Back to outer:
|
|
self.do_next_unique_task('last')
|
|
self.do_next_unique_task('End')
|
|
|
|
def test_subworkflow_to_block(self):
|
|
self.load_workflow_spec('data', 'subworkflow_to_block.xml')
|
|
self.do_next_unique_task('Start')
|
|
self.do_next_unique_task('first')
|
|
|
|
# Inner:
|
|
self.do_next_unique_task('Start')
|
|
self.do_next_unique_task('first')
|
|
self.do_next_unique_task('last')
|
|
self.do_next_unique_task('End')
|
|
# Back to outer:
|
|
self.do_next_unique_task('last')
|
|
self.do_next_unique_task('End')
|
|
|
|
def test_subworkflow_to_join(self):
|
|
self.load_workflow_spec('control-flow', 'subworkflow_to_join.xml')
|
|
self.do_next_unique_task('Start')
|
|
self.do_next_unique_task('first')
|
|
# The subworkflow task now sets its child tasks to READY and waits
|
|
self.do_next_named_step('second', ['Start'])
|
|
|
|
# Inner:
|
|
self.do_next_unique_task('Start')
|
|
self.do_next_unique_task('first')
|
|
self.do_next_unique_task('last')
|
|
self.do_next_unique_task('End')
|
|
# Back to outer:
|
|
self.do_next_unique_task('join')
|
|
self.do_next_unique_task('last')
|
|
self.do_next_unique_task('End')
|
|
|
|
def test_subworkflow_to_join_refresh_waiting(self):
|
|
self.load_workflow_spec('control-flow', 'subworkflow_to_join.xml')
|
|
self.do_next_unique_task('Start')
|
|
self.do_next_unique_task('first')
|
|
self.do_next_named_step('second', ['Start'])
|
|
|
|
# Inner:
|
|
self.do_next_unique_task('Start')
|
|
self.do_next_unique_task('first')
|
|
|
|
# Now refresh waiting tasks:
|
|
# Update the state of every WAITING task.
|
|
for thetask in self.workflow._get_waiting_tasks():
|
|
thetask.task_spec._update(thetask)
|
|
|
|
self.do_next_unique_task('last')
|
|
self.do_next_unique_task('End')
|
|
# Back to outer:
|
|
self.do_next_unique_task('join')
|
|
self.do_next_unique_task('last')
|
|
self.do_next_unique_task('End')
|
|
|
|
|
|
def suite():
|
|
return unittest.TestLoader().loadTestsFromTestCase(TaskSpecTest)
|
|
if __name__ == '__main__':
|
|
unittest.TextTestRunner(verbosity=2).run(suite())
|