generated from coulomb/repo-seed
Add Coulomb observatory package with JSON registries (product, pricing models, costs, revenue, membership), economics snapshot engine, Economics Dashboard v1 CLI, sample report, and pytest coverage. Complete T01 and queue Sprint 2 Bubble.io integration.
57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
from decimal import Decimal
|
|
from pathlib import Path
|
|
|
|
from observatory.economics import active_members, build_snapshot, monthly_cost_total
|
|
from observatory.load import (
|
|
load_costs,
|
|
load_membership,
|
|
load_pricing_models,
|
|
load_product,
|
|
load_revenue,
|
|
)
|
|
|
|
DATA_DIR = Path(__file__).resolve().parent.parent / "data"
|
|
|
|
|
|
def test_active_members_counts_only_active_status() -> None:
|
|
members = load_membership(DATA_DIR)
|
|
assert active_members(members) == 3
|
|
|
|
|
|
def test_build_snapshot_uses_seed_revenue_for_period() -> None:
|
|
product = load_product(DATA_DIR)
|
|
models = load_pricing_models(DATA_DIR)
|
|
members = load_membership(DATA_DIR)
|
|
revenue = load_revenue(DATA_DIR)
|
|
_, costs, fx_rates = load_costs(DATA_DIR)
|
|
|
|
snapshot = build_snapshot("2026-06", product, models, members, revenue, costs, fx_rates)
|
|
|
|
assert snapshot.active_members == 3
|
|
assert snapshot.monthly_revenue == Decimal("80.91")
|
|
assert snapshot.revenue_source == "manual_estimate"
|
|
assert snapshot.pricing_model_count == 3
|
|
assert snapshot.monthly_cost > Decimal("0")
|
|
assert snapshot.cost_per_member == (snapshot.monthly_cost / 3).quantize(Decimal("0.01"))
|
|
assert snapshot.gross_margin == (snapshot.monthly_revenue - snapshot.monthly_cost).quantize(
|
|
Decimal("0.01")
|
|
)
|
|
|
|
|
|
def test_monthly_cost_includes_fixed_and_variable_components() -> None:
|
|
_, costs, fx_rates = load_costs(DATA_DIR)
|
|
total = monthly_cost_total(costs, fx_rates, Decimal("80.91"), 3)
|
|
# fixed: 35 USD -> 32.20 EUR + 15 EUR + 25 EUR = 72.20
|
|
# variable: 1.5% of 80.91 + 0.25 * 3 = 1.21 + 0.75 = 1.96
|
|
assert total == Decimal("74.16")
|
|
|
|
|
|
def test_dashboard_module_renders_markdown() -> None:
|
|
from observatory.dashboard import generate_dashboard
|
|
|
|
report = generate_dashboard(DATA_DIR, "2026-06")
|
|
assert "# Economics Dashboard v1" in report
|
|
assert "Pricing Model Registry" in report
|
|
assert "flat-899-eur-monthly" in report |