Executing workflows from the test json specs, sanity testing before we move on
This commit is contained in:
parent
7ca888ff32
commit
7baf35a177
2
Makefile
2
Makefile
|
@ -26,7 +26,7 @@ dev-env:
|
|||
|
||||
.PHONY: tests
|
||||
tests:
|
||||
$(DEV_AS_ME) unittest-parallel -vs $(TESTS) -p test_*.py -t .
|
||||
$(DEV_AS_ME) unittest-parallel -vs $(TESTS) -p test_\*.py -t .
|
||||
|
||||
#
|
||||
# used to copy in/parse files from my process-models, probably will want to move these to
|
||||
|
|
|
@ -32,8 +32,7 @@ def _to_dict(bpmn_file):
|
|||
return {k: SPEC_CONVERTER.convert(v) for k, v in specs.items()}
|
||||
|
||||
def _write_dict_as_json(bpmn_file, dct):
|
||||
# correct, this is not very robust
|
||||
json_filename = bpmn_file.replace("process-models", "specs-json").replace(".bpmn", ".json")
|
||||
json_filename = bpmn_file.replace("/process-models/", "/specs-json/").replace(".bpmn", ".json")
|
||||
os.makedirs(os.path.dirname(json_filename), exist_ok=True)
|
||||
with open(json_filename, "w") as f:
|
||||
f.write(json.dumps(dct, indent=4, sort_keys=True))
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
def this_returns_true():
|
||||
return True
|
|
@ -0,0 +1,36 @@
|
|||
import json
|
||||
|
||||
from SpiffWorkflow.bpmn.serializer.workflow import BpmnWorkflowSerializer
|
||||
from SpiffWorkflow.bpmn.workflow import BpmnWorkflow
|
||||
from SpiffWorkflow.spiff.parser.process import SpiffBpmnParser
|
||||
from SpiffWorkflow.spiff.serializer.config import SPIFF_SPEC_CONFIG
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
# TODO: most likely will want these moves to a test helper file
|
||||
SPEC_CONVERTER = BpmnWorkflowSerializer.configure_workflow_spec_converter(SPIFF_SPEC_CONFIG)
|
||||
|
||||
def _load_specs_json(relname):
|
||||
with open(f"tests/data/specs-json/test-cases/{relname}") as f:
|
||||
return json.load(f)
|
||||
|
||||
def _converted_specs(specs, process_id):
|
||||
converted_specs = {k: SPEC_CONVERTER.restore(v) for k, v in specs.items()}
|
||||
top_level = converted_specs.pop(process_id)
|
||||
subprocesses = converted_specs
|
||||
return (top_level, subprocesses)
|
||||
|
||||
def _workflow_from_specs_json(relname, process_id):
|
||||
specs = _load_specs_json(relname)
|
||||
top_level, subprocesses = _converted_specs(specs, process_id)
|
||||
return BpmnWorkflow(top_level, subprocesses)
|
||||
|
||||
# TODO: to leverage the unittest-parallel, is it better to have many small test suites?
|
||||
# does the number of files matter or just the TestCase classes?
|
||||
class ExecuteSpecJsonFilesTest(TestCase):
|
||||
def test_no_tasks_executes(self):
|
||||
workflow = _workflow_from_specs_json("no-tasks/no-tasks.json", "no_tasks")
|
||||
workflow.do_engine_steps()
|
||||
|
||||
assert workflow.is_completed()
|
||||
assert workflow.data == {}
|
Loading…
Reference in New Issue