mirror of
https://github.com/sartography/spiff-arena.git
synced 2025-01-18 05:21:35 +00:00
0892db6fa7
git-subtree-dir: SpiffWorkflow git-subtree-split: 63db3e45947ec66b8d0efc2c74064004f8ff482c
76 lines
2.7 KiB
Python
76 lines
2.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import sys
|
|
import unittest
|
|
import os
|
|
data_dir = os.path.join(os.path.dirname(__file__), 'data')
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
|
|
|
from SpiffWorkflow.workflow import Workflow
|
|
from SpiffWorkflow.specs import Cancel, Simple, WorkflowSpec
|
|
from SpiffWorkflow.task import TaskState
|
|
from SpiffWorkflow.serializer.prettyxml import XmlSerializer
|
|
|
|
|
|
class WorkflowTest(unittest.TestCase):
|
|
|
|
def testConstructor(self):
|
|
wf_spec = WorkflowSpec()
|
|
wf_spec.start.connect(Cancel(wf_spec, 'name'))
|
|
workflow = Workflow(wf_spec)
|
|
|
|
def testBeginWorkflowStepByStep(self):
|
|
"""
|
|
Simulates interactive calls, as would be issued by a user.
|
|
"""
|
|
xml_file = os.path.join(data_dir, 'spiff', 'workflow1.xml')
|
|
with open(xml_file) as fp:
|
|
xml = fp.read()
|
|
wf_spec = WorkflowSpec.deserialize(XmlSerializer(), xml)
|
|
workflow = Workflow(wf_spec)
|
|
|
|
tasks = workflow.get_tasks(TaskState.READY)
|
|
self.assertEqual(len(tasks), 1)
|
|
self.assertEqual(tasks[0].task_spec.name, 'Start')
|
|
workflow.complete_task_from_id(tasks[0].id)
|
|
self.assertEqual(tasks[0].state, TaskState.COMPLETED)
|
|
|
|
tasks = workflow.get_tasks(TaskState.READY)
|
|
self.assertEqual(len(tasks), 2)
|
|
task_a1 = tasks[0]
|
|
task_b1 = tasks[1]
|
|
self.assertEqual(task_a1.task_spec.__class__, Simple)
|
|
self.assertEqual(task_a1.task_spec.name, 'task_a1')
|
|
self.assertEqual(task_b1.task_spec.__class__, Simple)
|
|
self.assertEqual(task_b1.task_spec.name, 'task_b1')
|
|
workflow.complete_task_from_id(task_a1.id)
|
|
self.assertEqual(task_a1.state, TaskState.COMPLETED)
|
|
|
|
tasks = workflow.get_tasks(TaskState.READY)
|
|
self.assertEqual(len(tasks), 2)
|
|
self.assertTrue(task_b1 in tasks)
|
|
task_a2 = tasks[0]
|
|
self.assertEqual(task_a2.task_spec.__class__, Simple)
|
|
self.assertEqual(task_a2.task_spec.name, 'task_a2')
|
|
workflow.complete_task_from_id(task_a2.id)
|
|
|
|
tasks = workflow.get_tasks(TaskState.READY)
|
|
self.assertEqual(len(tasks), 1)
|
|
self.assertTrue(task_b1 in tasks)
|
|
|
|
workflow.complete_task_from_id(task_b1.id)
|
|
tasks = workflow.get_tasks(TaskState.READY)
|
|
self.assertEqual(len(tasks), 1)
|
|
workflow.complete_task_from_id(tasks[0].id)
|
|
|
|
tasks = workflow.get_tasks(TaskState.READY)
|
|
self.assertEqual(len(tasks), 1)
|
|
self.assertEqual(tasks[0].task_spec.name, 'synch_1')
|
|
# haven't reached the end of the workflow, but stopping at "synch_1"
|
|
|
|
|
|
def suite():
|
|
return unittest.TestLoader().loadTestsFromTestCase(WorkflowTest)
|
|
if __name__ == '__main__':
|
|
unittest.TextTestRunner(verbosity=2).run(suite())
|