spiff-arena/tests/SpiffWorkflow/dmn/DecisionRunner.py
jasquat 69e814758e Squashed 'SpiffWorkflow/' changes from 12f81480a..d27519a36
d27519a36 Merge pull request #259 from sartography/bugfix/spiff-postscript-execution
21aa8a12c update execution order for postscripts
d83fd3d81 Merge pull request #256 from sartography/feature/xml-validation
8303aaab5 uping the sleep time in a test slightly to see if we can get this test to pass consistently in CI.
1d251d55d determine whether to validate by passing in a validator instead of a parameter
2d3daad2d add spiff schema
f8c65dc60 Minor changes to BPMN diagrams to assure all tests are run against valid BPMN Diagrams. Changes required:
9e06b25bf add DMN validation
1b7cbeba0 set parser to validate by default
53fdbba52 add schemas & validation option
a212d9c5d general cleanup

git-subtree-dir: SpiffWorkflow
git-subtree-split: d27519a3631b9772094e5f24dba2f478b0c47135
2022-10-27 10:50:48 -04:00

52 lines
1.5 KiB
Python

import os
from lxml import etree
from SpiffWorkflow.bpmn.PythonScriptEngine import Box
from SpiffWorkflow.dmn.engine.DMNEngine import DMNEngine
from SpiffWorkflow.dmn.parser.DMNParser import DMNParser, get_dmn_ns
class Workflow:
def __init__(self, script_engine):
self.script_engine = script_engine
self.outer_workflow = self
self.spec = Box({'file': 'my_mock_file'})
class TaskSpec:
def __init__(self):
self.name = "MockTestSpec"
self.description = "Mock Test Spec"
class Task:
def __init__(self, script_engine, data):
self.data = data
self.workflow = Workflow(script_engine)
self.task_spec = TaskSpec()
class DecisionRunner:
def __init__(self, script_engine, filename, path=''):
self.script_engine = script_engine
fn = os.path.join(os.path.dirname(__file__), path, 'data', filename)
with open(fn) as fh:
node = etree.parse(fh)
self.dmnParser = DMNParser(None, node.getroot(), get_dmn_ns(node.getroot()))
self.dmnParser.parse()
decision = self.dmnParser.decision
assert len(decision.decisionTables) == 1, \
'Exactly one decision table should exist! (%s)' \
% (len(decision.decisionTables))
self.dmnEngine = DMNEngine(decision.decisionTables[0])
def decide(self, context):
if not isinstance(context, dict):
context = {'input': context}
task = Task(self.script_engine, context)
return self.dmnEngine.decide(task)