Harden resource cost evidence contract
This commit is contained in:
parent
080f756fff
commit
00343307fd
22 changed files with 1623 additions and 130 deletions
|
|
@ -1,5 +1,10 @@
|
|||
"""Smoke tests for fin-hub model registration."""
|
||||
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from fin_hub.models import (
|
||||
Budget,
|
||||
BurnRate,
|
||||
|
|
@ -9,6 +14,8 @@ from fin_hub.models import (
|
|||
ServiceCost,
|
||||
TokenSpend,
|
||||
)
|
||||
from fin_hub.models.engagement_price import _validate_engagement_price
|
||||
from fin_hub.models.service_cost import _normalize_service_cost_attribution
|
||||
from hub_core.models.base import Base
|
||||
|
||||
|
||||
|
|
@ -39,3 +46,41 @@ def test_service_cost_has_external_attribution_seam():
|
|||
assert columns["application_id"].nullable is True
|
||||
assert columns["app_instance_id"].nullable is True
|
||||
assert columns["cost_attribution_key"].nullable is True
|
||||
|
||||
|
||||
def test_service_cost_orm_uses_shared_money_and_period_invariants():
|
||||
cost = ServiceCost(
|
||||
service_id="cluster",
|
||||
environment="production",
|
||||
period_month="2026-07",
|
||||
amount=Decimal("10.005"),
|
||||
currency="eur",
|
||||
source=" invoice ",
|
||||
)
|
||||
_normalize_service_cost_attribution(None, None, cost)
|
||||
assert cost.amount == Decimal("10.00")
|
||||
assert cost.currency == "EUR"
|
||||
assert cost.source == "invoice"
|
||||
|
||||
cost.period_month = "2026-13"
|
||||
with pytest.raises(ValueError, match="YYYY-MM"):
|
||||
_normalize_service_cost_attribution(None, None, cost)
|
||||
|
||||
|
||||
def test_engagement_price_orm_normalizes_same_basis_as_sqlite():
|
||||
price = EngagementPrice(
|
||||
client_id="acme",
|
||||
application_id="portal",
|
||||
app_instance_id="prod-01",
|
||||
cost_attribution_key=None,
|
||||
period_month="placeholder",
|
||||
effective_from=date(2026, 7, 15),
|
||||
amount=Decimal("100.005"),
|
||||
currency="eur",
|
||||
source=" agreement ",
|
||||
)
|
||||
_validate_engagement_price(None, None, price)
|
||||
assert price.period_month == "2026-07"
|
||||
assert price.amount == Decimal("100.00")
|
||||
assert price.currency == "EUR"
|
||||
assert price.source == "agreement"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue