dodil/erp-brick-ar

DODIL ERP brick: accounts receivable

tests/test_composition.py

"""The brick composes: `erp-compose check` finds no table or tool collision, no version drift, and a process view."""
import pathlib

import pytest
from erp_platform import compose

HERE = pathlib.Path(__file__).parent


def test_the_composition_checks():
    pytest.importorskip("brick_bp", reason="brick-business-partner is not installed")
    report = compose.check(compose.load(HERE / "tier1.compose.yaml"))
    assert report["problems"] == []


def test_the_brick_alone_composes():
    report = compose.check(compose.load(HERE / "alone.compose.yaml"))
    assert report["problems"] == []


def test_the_brick_a_composition_loads_declares_every_route_the_app_serves():
    """compose.yaml points at `brick_ar.application.use_cases:AR`: importing that alone (a fresh interpreter, nothing else
    imported) must declare the same use cases as the deployable app."""
    import subprocess
    import sys
    code = ("import importlib; b = importlib.import_module('brick_ar.application.use_cases').AR; n = len(b.use_cases); "
            "importlib.import_module('brick_ar.app'); print(n, len(b.use_cases))")
    alone, with_app = subprocess.run([sys.executable, "-c", code], capture_output=True, text=True, check=True).stdout.split()
    assert alone == with_app, f"the composition's import declares {alone} use cases, the app {with_app}"