dodil/erp-brick-gl
DODIL ERP brick: general ledger
tests/test_process.py
"""The process this brick serves is module.yaml's workflows (application/process.yaml, the BPMN at GET /process/bpmn), and the use
cases are NAMED as its transitions: a tool name is unique across the method, and an agent finds a step by the name the customer's
diagram gives it."""
import pathlib
import pytest
import yaml
from conftest import ACCOUNTANT, api
from erp_platform import bpmn
from brick_gl.application.use_cases import GL
PROCESS = pathlib.Path(__file__).resolve().parents[1] / "src" / "brick_gl" / "application" / "process.yaml"
# transitions the system performs INSIDE another use case: they are not a separate tool
INSIDE = {"mark_close_ready": None}
def test_every_transition_of_the_process_is_a_use_case_of_that_name():
data = yaml.safe_load(PROCESS.read_text())
keys = [t["key"] for w in data["workflows"] for t in w["transitions"]]
names = {u.name for u in GL.use_cases}
assert [k for k in keys if k not in names] == [], "a transition of the signed process has no use case of its name"
assert len(keys) == len(set(keys))
def test_the_process_is_drawn_as_bpmn_with_a_task_per_transition():
data = yaml.safe_load(PROCESS.read_text())
xml = bpmn.to_bpmn(bpmn.from_module(data, "module.yaml"))
for w in data["workflows"]:
for t in w["transitions"]:
assert f"Task_{t['key']}" in xml, t["key"]
s, body = api("GET", "/process/bpmn", ACCOUNTANT)
assert s == 200
SPEC = pathlib.Path(__file__).resolve().parents[2] / "erp-method" / "modules" / "gl" / "module.yaml"
@pytest.mark.skipif(not SPEC.exists(), reason="erp-method is not checked out beside this brick")
def test_the_served_process_is_the_signed_module_yaml_version_and_workflows():
served, spec = yaml.safe_load(PROCESS.read_text()), yaml.safe_load(SPEC.read_text())
assert served["version"] == spec["version"] == 7 # a seams-only bump moves both
for key in ("id", "name", "workflows"):
assert served[key] == spec[key], key