dodil/erp-brick-product

tests/test_scenarios.py

"""The scenario catalogue covers every scenario in the spec (module.yaml tests.scenarios)."""
import pathlib
import sys

sys.path.insert(0, str(pathlib.Path(__file__).parent / "scenarios"))

import catalogue  # noqa: E402

SPEC = ["SC-PRD-01", "SC-PRD-02", "SC-PRD-06", "SC-PRD-04", "SC-PRD-03"]            # the order of module.yaml tests.scenarios
EXTRA = ["SC-PRD-05"]                       # the audit's: a late publish never back-dates a price


def test_the_catalogue_covers_the_spec():
    assert sorted(sc.id for sc in catalogue.CAT.scenarios) == sorted(SPEC + EXTRA)


def test_the_catalogue_runs_in_process():
    """The whole composition in process: storage wires, every scenario and every generated probe PASSES — none is
    skipped, none xfails — including PROBE-WILD (`*:*:*` and `product:*:*` run every person use case and no machine one)."""
    from erp_platform.scenarios.inprocess import InProcessRunner
    runner = InProcessRunner(catalogue.CAT)
    runner.start()
    try:
        results = runner.run_all()
    finally:
        runner.stop()
    assert [(r.id, r.outcome, r.message[:300]) for r in results if r.outcome != "passed"] == []
    ids = {r.id for r in results}
    assert set(SPEC + EXTRA) <= ids
    assert {"PROBE-PERM-CATALOGUE_MANAGER", "PROBE-PERM-PRICING_MANAGER", "PROBE-PERM-SALES_REP", "PROBE-PERM-SYSTEM",
            "PROBE-PERM-ANONYMOUS", "PROBE-WILD-STAR", "PROBE-WILD-PRODUCT", "PROBE-WILD-MALFORMED"} <= ids


def test_the_scenarios_roles_are_the_bricks_default_roles_plus_the_partner_steward():
    import yaml
    here = pathlib.Path(__file__).resolve().parent
    shipped = yaml.safe_load((here.parent / "src" / "brick_product" / "roles.yaml").read_text())
    scenarios = yaml.safe_load((here / "scenarios" / "roles.yaml").read_text())
    assert {k: v for k, v in scenarios["roles"].items() if k not in ("partner_steward", "selling_service")} == shipped["roles"]
    assert scenarios["service_clients"] == shipped["service_clients"] + ["selling_service"]