spiff-arena/tests/SpiffWorkflow/bpmn/BpmnLoaderForTests.py
burnettk c237e218b2 Squashed 'SpiffWorkflow/' changes from 98c6294f..0e61be85
0e61be85 Merge pull request #289 from sartography/improvement/execution-and-serialization-cleanup
527684da fix some typos in the class & method docs
0dff44a4 Merge branch 'main' into improvement/execution-and-serialization-cleanup
64737498 Allow for other PythonScriptEngine environments besides task data (#288)
dd63e916 remove some unused tests & diagrams
24aae519 clean up various small stuff
3b2dc35d use context when opening files for parsing
69eec3eb update class/method docs
24528dfb move all spec conversion classes to top level
5af33b11 remove some unused methods related to old serializer
931b90fb reorganize serializer
4e81ed29 consolidate pointless serializer classes
d62acf02 change task_spec._update_hook to return a boolean indicating whether the task is ready

git-subtree-dir: SpiffWorkflow
git-subtree-split: 0e61be85c47474a33037e6f398e64c96e02f13ad
2023-02-02 20:59:28 -05:00

68 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
from SpiffWorkflow.bpmn.specs.ExclusiveGateway import ExclusiveGateway
from SpiffWorkflow.bpmn.specs.UserTask import UserTask
from SpiffWorkflow.bpmn.parser.BpmnParser import BpmnParser
from SpiffWorkflow.bpmn.parser.TaskParser import TaskParser
from SpiffWorkflow.bpmn.parser.task_parsers import ConditionalGatewayParser
from SpiffWorkflow.bpmn.parser.util import full_tag
from SpiffWorkflow.bpmn.serializer.helpers.spec import TaskSpecConverter
# Many of our tests relied on the Packager to set the calledElement attribute on
# Call Activities. I've moved that code to a customized parser.
from SpiffWorkflow.signavio.parser.tasks import CallActivityParser
from SpiffWorkflow.bpmn.specs.SubWorkflowTask import CallActivity
__author__ = 'matth'
# This provides some extensions to the BPMN parser that make it easier to
# implement testcases
class TestUserTask(UserTask):
def get_user_choices(self):
if not self.outputs:
return []
assert len(self.outputs) == 1
next_node = self.outputs[0]
if isinstance(next_node, ExclusiveGateway):
return next_node.get_outgoing_sequence_names()
return self.get_outgoing_sequence_names()
def do_choice(self, task, choice):
task.set_data(choice=choice)
task.complete()
class TestExclusiveGatewayParser(ConditionalGatewayParser):
def parse_condition(self, sequence_flow_node):
cond = super().parse_condition(sequence_flow_node)
if cond is not None:
return cond
return "choice == '%s'" % sequence_flow_node.get('name', None)
class TestUserTaskConverter(TaskSpecConverter):
def __init__(self, data_converter=None):
super().__init__(TestUserTask, data_converter)
def to_dict(self, spec):
dct = self.get_default_attributes(spec)
dct.update(self.get_bpmn_attributes(spec))
return dct
def from_dict(self, dct):
return self.task_spec_from_dict(dct)
class TestBpmnParser(BpmnParser):
OVERRIDE_PARSER_CLASSES = {
full_tag('userTask'): (TaskParser, TestUserTask),
full_tag('exclusiveGateway'): (TestExclusiveGatewayParser, ExclusiveGateway),
full_tag('callActivity'): (CallActivityParser, CallActivity)
}