dodil/erp-brick-consolidation

DODIL ERP brick: consolidation

tests/test_process.py

"""The process this brick serves is the process the customer SIGNED (consolidation v2): process.yaml is module.yaml's
workflows, copied, and the test compares the two — so a change to either side breaks it. A change to the process goes through
`erp-compose change propose` and a new signature first, then the code."""
import pathlib

import yaml
from contract_checks import METHOD_DIR
from erp_platform import bpmn

PROCESS = pathlib.Path(__file__).resolve().parents[1] / "src" / "brick_consolidation" / "application" / "process.yaml"
SPEC = yaml.safe_load((pathlib.Path(METHOD_DIR) / "modules" / "consolidation" / "module.yaml").read_text())


def test_the_served_process_is_the_signed_one():
    served = yaml.safe_load(PROCESS.read_text())
    assert (served["id"], served["name"], served["version"]) == (SPEC["id"], SPEC["name"], SPEC["version"])
    assert served["actors"] == SPEC["actors"]
    assert served["workflows"] == SPEC["workflows"]                  # every state, step id, gate and effect, as signed


def test_every_signed_step_is_drawn_under_its_signed_id():
    drawn = bpmn.to_bpmn(bpmn.from_module(yaml.safe_load(PROCESS.read_text()), "module.yaml"))
    for wf in SPEC["workflows"]:
        for t in wf["transitions"]:
            assert t["key"] in drawn, (wf["entity"], t["key"])


def test_a_changed_process_does_not_match():
    """The guard is real: one renamed step and the comparison fails."""
    changed = yaml.safe_load(PROCESS.read_text())
    changed["workflows"][0]["transitions"][0]["name"] = "Add whatever we like"
    assert changed["workflows"] != SPEC["workflows"]