spiff-arena/tests/SpiffWorkflow/camunda/ResetTokenNestedParallelTes...

215 lines
7.7 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
import unittest
from SpiffWorkflow.bpmn.workflow import BpmnWorkflow
from tests.SpiffWorkflow.camunda.BaseTestCase import BaseTestCase
__author__ = 'kellym'
class ResetTokenTestNestedParallel(BaseTestCase):
"""The example bpmn diagram tests both a set cardinality from user input
as well as looping over an existing array."""
def setUp(self):
spec, subprocesses = self.load_workflow_spec('token_trial_nested_parallel.bpmn', 'token')
self.workflow = BpmnWorkflow(spec, subprocesses)
def testRunThroughHappy(self):
self.actual_test(save_restore=False)
def testRunThroughSaveRestore(self):
self.actual_test(save_restore=True)
def testRunThroughHappyAlt(self):
self.actual_test2(save_restore=False)
def testRunThroughSaveRestoreAlt(self):
self.actual_test2(save_restore=True)
def actual_test(self, save_restore=False,reset_data=False):
"""
Test a complicated parallel matrix, complete the matrix and
Reset somewhere in the middle. It should complete the row that we
Reset to, and retain all previous answers.
"""
self.workflow.do_engine_steps()
firsttaskid = None
steps = [{'taskname':'First',
'formvar': 'First',
'answer': 'Yes'},
{'taskname': 'FormA1',
'formvar': 'A1',
'answer': 'xa1'},
{'taskname': 'FormA2',
'formvar': 'A2',
'answer': 'xa2'},
{'taskname': 'FormA3',
'formvar': 'A3',
'answer': 'xa3'},
{'taskname': 'FormB1',
'formvar': 'B1',
'answer': 'xb1'},
{'taskname': 'FormB2',
'formvar': 'B2',
'answer': 'xb2'},
{'taskname': 'FormB3',
'formvar': 'B3',
'answer': 'xb3'},
{'taskname': 'FormC1',
'formvar': 'C1',
'answer': 'xc1'},
{'taskname': 'FormC2',
'formvar': 'C2',
'answer': 'xc2'},
{'taskname': 'FormC3',
'formvar': 'C3',
'answer': 'xc3'},
]
for step in steps:
task = self.workflow.get_ready_user_tasks()[0]
if firsttaskid == None and step['taskname']=='FormB2':
firsttaskid = task.id
self.assertEqual(step['taskname'], task.task_spec.name)
task.update_data({step['formvar']: step['answer']})
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
self.workflow.run_task_from_id(task.id)
self.workflow.do_engine_steps()
if save_restore: self.save_restore()
self.workflow.reset_task_from_id(firsttaskid)
self.workflow.do_engine_steps()
#NB - this won't test random access
steps = [{'taskname': 'FormB2',
'formvar': 'B2',
'answer': 'b2'},
{'taskname': 'FormD',
'formvar': 'D',
'answer': 'd'},
]
for step in steps:
task = self.workflow.get_ready_user_tasks()[0]
self.assertEqual(step['taskname'], task.task_spec.name)
task.update_data({step['formvar']: step['answer']})
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
self.workflow.run_task_from_id(task.id)
self.workflow.do_engine_steps()
if save_restore: self.save_restore()
notworking = self.workflow.get_ready_user_tasks()
self.assertTrue(self.workflow.is_completed())
self.assertEqual({'First': 'Yes',
'A1': 'xa1',
'A2': 'xa2',
'A3': 'xa3',
'B1': 'xb1',
'B2': 'b2',
'B3': 'xb3',
'C1': 'xc1',
'C2': 'xc2',
'C3': 'xc3',
'D': 'd'},
self.workflow.last_task.data)
def actual_test2(self, save_restore=False,reset_data=False):
"""
Test a complicated parallel matrix,
Complete several items in the parallel matrix, but do not complete it,
Reset to a previous version on another branch of the parallel, it should
complete that branch and then pick up where we left off.
Also, after we reset the branch, there should then be three tasks ready,
A2,B3,and C1
"""
self.workflow.do_engine_steps()
firsttaskid = None
steps = [{'taskname':'First',
'formvar': 'First',
'answer': 'Yes'},
{'taskname': 'FormA1',
'formvar': 'A1',
'answer': 'xa1'},
{'taskname': 'FormA2',
'formvar': 'A2',
'answer': 'xa2'},
{'taskname': 'FormA3',
'formvar': 'A3',
'answer': 'xa3'},
{'taskname': 'FormB1',
'formvar': 'B1',
'answer': 'xb1'},
{'taskname': 'FormB2',
'formvar': 'B2',
'answer': 'xb2'},
]
for step in steps:
task = self.workflow.get_ready_user_tasks()[0]
if firsttaskid == None and step['taskname']=='FormA2':
firsttaskid = task.id
self.assertEqual(step['taskname'], task.task_spec.name)
task.update_data({step['formvar']: step['answer']})
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
self.workflow.run_task_from_id(task.id)
self.workflow.do_engine_steps()
if save_restore: self.save_restore()
self.workflow.reset_task_from_id(firsttaskid)
#NB - this won't test random access
steps = [{'taskname': 'FormA2',
'formvar': 'A2',
'answer': 'a2'},
{'taskname': 'FormB3',
'formvar': 'B3',
'answer': 'b3'},
{'taskname': 'FormC1',
'formvar': 'C1',
'answer': 'c1'},
{'taskname': 'FormC2',
'formvar': 'C2',
'answer': 'c2'},
{'taskname': 'FormC3',
'formvar': 'C3',
'answer': 'c3'},
{'taskname': 'FormD',
'formvar': 'D',
'answer': 'd'},
]
readytasks = [t.task_spec.name for t in self.workflow.get_ready_user_tasks()]
self.assertEqual(readytasks,['FormA2','FormB3','FormC1','FormC2','FormC3'])
for step in steps:
task = self.workflow.get_ready_user_tasks()[0]
self.assertEqual(step['taskname'], task.task_spec.name)
task.update_data({step['formvar']: step['answer']})
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
self.workflow.run_task_from_id(task.id)
self.workflow.do_engine_steps()
if save_restore: self.save_restore()
self.assertTrue(self.workflow.is_completed())
self.assertEqual({'First': 'Yes',
'A1': 'xa1',
'A2': 'a2',
'A3': 'xa3',
'B1': 'xb1',
'B2': 'xb2',
'B3': 'b3',
'C1': 'c1',
'C2': 'c2',
'C3': 'c3',
'D': 'd'},
self.workflow.last_task.data)
def suite():
return unittest.TestLoader().loadTestsFromTestCase(ResetTokenTestNestedParallel)
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())