generated from coulomb/repo-seed
169 lines
5.8 KiB
Python
169 lines
5.8 KiB
Python
from __future__ import annotations
|
|
|
|
from decimal import Decimal
|
|
from pathlib import Path
|
|
|
|
from adaptive_pricing_core.boundary_engine import (
|
|
BoundaryPolicy,
|
|
CommitmentTerms,
|
|
PricingConfiguration,
|
|
validate_pricing_configuration,
|
|
)
|
|
from observatory.load import load_pricing_models
|
|
|
|
DATA_DIR = Path(__file__).resolve().parent.parent / "data"
|
|
|
|
|
|
def _model(model_id: str):
|
|
return next(item for item in load_pricing_models(DATA_DIR) if item.id == model_id)
|
|
|
|
|
|
def test_commitment_backed_discount_is_accepted_when_economics_stay_strong() -> None:
|
|
result = validate_pricing_configuration(
|
|
PricingConfiguration(
|
|
model=_model("membership-plus-overage"),
|
|
segment="coulomb-social-members",
|
|
expected_usage_units=Decimal("100200"),
|
|
expected_usage_variance_pct=Decimal("25"),
|
|
allocated_fixed_cost=Decimal("2.00"),
|
|
unit_cost=Decimal("0.00000125"),
|
|
payment_fee_rate_pct=Decimal("5"),
|
|
usage_unit_price=Decimal("0.0015"),
|
|
commitment_terms=CommitmentTerms(
|
|
contract_duration_months=6,
|
|
minimum_monthly_turnover=Decimal("9.30"),
|
|
),
|
|
),
|
|
BoundaryPolicy(),
|
|
)
|
|
|
|
assert result.decision == "accepted"
|
|
assert result.valid is True
|
|
assert result.requires_approval is False
|
|
commitment_result = next(
|
|
item for item in result.constraints if item.id == "commitment-backed-concession"
|
|
)
|
|
assert commitment_result.status == "pass"
|
|
assert "minimum_monthly_turnover" in commitment_result.details["signals"]
|
|
|
|
|
|
def test_discount_without_commitment_is_rejected() -> None:
|
|
result = validate_pricing_configuration(
|
|
PricingConfiguration(
|
|
model=_model("membership-plus-overage"),
|
|
segment="coulomb-social-members",
|
|
expected_usage_units=Decimal("100200"),
|
|
expected_usage_variance_pct=Decimal("25"),
|
|
allocated_fixed_cost=Decimal("2.00"),
|
|
unit_cost=Decimal("0.00000125"),
|
|
payment_fee_rate_pct=Decimal("5"),
|
|
usage_unit_price=Decimal("0.0015"),
|
|
),
|
|
BoundaryPolicy(),
|
|
)
|
|
|
|
assert result.decision == "rejected"
|
|
assert result.valid is False
|
|
failing_ids = {
|
|
item.id for item in result.constraints if item.status == "fail" and item.severity == "hard"
|
|
}
|
|
assert "commitment-backed-concession" in failing_ids
|
|
|
|
|
|
def test_weak_commitment_trade_is_rejected() -> None:
|
|
result = validate_pricing_configuration(
|
|
PricingConfiguration(
|
|
model=_model("membership-plus-overage"),
|
|
segment="coulomb-social-members",
|
|
expected_usage_units=Decimal("100200"),
|
|
expected_usage_variance_pct=Decimal("25"),
|
|
allocated_fixed_cost=Decimal("2.00"),
|
|
unit_cost=Decimal("0.00000125"),
|
|
payment_fee_rate_pct=Decimal("5"),
|
|
usage_unit_price=Decimal("0.0015"),
|
|
commitment_terms=CommitmentTerms(
|
|
contract_duration_months=2,
|
|
minimum_monthly_turnover=Decimal("9.00"),
|
|
),
|
|
),
|
|
BoundaryPolicy(),
|
|
)
|
|
|
|
assert result.decision == "rejected"
|
|
commitment_result = next(
|
|
item for item in result.constraints if item.id == "commitment-backed-concession"
|
|
)
|
|
assert commitment_result.status == "fail"
|
|
|
|
|
|
def test_large_but_supported_concession_requires_approval() -> None:
|
|
result = validate_pricing_configuration(
|
|
PricingConfiguration(
|
|
model=_model("flat-899-eur-monthly"),
|
|
segment="coulomb-social-members",
|
|
allocated_fixed_cost=Decimal("1.00"),
|
|
payment_fee_rate_pct=Decimal("5"),
|
|
access_fee_amount=Decimal("7.50"),
|
|
commitment_terms=CommitmentTerms(
|
|
contract_duration_months=6,
|
|
minimum_monthly_turnover=Decimal("8.00"),
|
|
),
|
|
),
|
|
BoundaryPolicy(),
|
|
)
|
|
|
|
assert result.decision == "requires_approval"
|
|
assert result.valid is True
|
|
assert result.requires_approval is True
|
|
review_ids = {item.id for item in result.constraints if item.status == "review"}
|
|
assert "discount-approval-threshold" in review_ids
|
|
|
|
|
|
def test_zero_usage_flat_configuration_can_pass() -> None:
|
|
result = validate_pricing_configuration(
|
|
PricingConfiguration(
|
|
model=_model("flat-899-eur-monthly"),
|
|
segment="coulomb-social-members",
|
|
expected_usage_units=Decimal("0"),
|
|
expected_usage_variance_pct=Decimal("0"),
|
|
allocated_fixed_cost=Decimal("3.00"),
|
|
payment_fee_rate_pct=Decimal("5"),
|
|
),
|
|
BoundaryPolicy(),
|
|
)
|
|
|
|
assert result.decision == "accepted"
|
|
assert result.metrics.billable_usage_units == Decimal("0")
|
|
|
|
|
|
def test_high_fee_configuration_is_rejected() -> None:
|
|
result = validate_pricing_configuration(
|
|
PricingConfiguration(
|
|
model=_model("flat-899-eur-monthly"),
|
|
segment="coulomb-social-members",
|
|
allocated_fixed_cost=Decimal("1.00"),
|
|
payment_fee_rate_pct=Decimal("30"),
|
|
),
|
|
BoundaryPolicy(),
|
|
)
|
|
|
|
assert result.decision == "rejected"
|
|
payment_fee_result = next(item for item in result.constraints if item.id == "payment-fee-limit")
|
|
assert payment_fee_result.status == "fail"
|
|
|
|
|
|
def test_unprofitable_configuration_is_rejected() -> None:
|
|
result = validate_pricing_configuration(
|
|
PricingConfiguration(
|
|
model=_model("flat-899-eur-monthly"),
|
|
segment="coulomb-social-members",
|
|
allocated_fixed_cost=Decimal("10.00"),
|
|
payment_fee_rate_pct=Decimal("5"),
|
|
),
|
|
BoundaryPolicy(),
|
|
)
|
|
|
|
assert result.decision == "rejected"
|
|
assert result.metrics.monthly_margin < Decimal("0")
|
|
assert any(item.id == "cost-floor-coverage" and item.status == "fail" for item in result.constraints)
|