Harden resource cost evidence contract
This commit is contained in:
parent
080f756fff
commit
00343307fd
22 changed files with 1623 additions and 130 deletions
|
|
@ -21,8 +21,11 @@ def test_build_service_cost_report_groups_by_service():
|
|||
report = build_service_cost_report(lines)
|
||||
assert report["signal"] == "service_cost_attribution"
|
||||
assert len(report["services"]) == 2
|
||||
assert report["totals_by_month"]["2026-06"] == pytest.approx(99.8)
|
||||
assert report["totals_by_period_currency"] == [
|
||||
{"period_month": "2026-06", "currency": "EUR", "total": pytest.approx(99.8)}
|
||||
]
|
||||
assert report["attributions"][0]["cost_attribution_key"] is None
|
||||
assert report["unattributed"][0]["total"] == pytest.approx(99.8)
|
||||
|
||||
|
||||
def test_build_service_cost_report_groups_by_client_attribution():
|
||||
|
|
@ -49,6 +52,7 @@ def test_build_service_cost_report_groups_by_client_attribution():
|
|||
"client_id": "acme",
|
||||
"application_id": "portal",
|
||||
"app_instance_id": "prod-01",
|
||||
"environment": "production",
|
||||
"currency": "EUR",
|
||||
"months": {"2026-07": 42.0},
|
||||
"total": 42.0,
|
||||
|
|
@ -77,3 +81,31 @@ def test_client_attribution_totals_do_not_mix_currencies():
|
|||
("EUR", 42.0),
|
||||
("USD", 50.0),
|
||||
}
|
||||
|
||||
|
||||
def test_service_totals_do_not_mix_currency_or_environment():
|
||||
common = {
|
||||
"service_id": "cluster",
|
||||
"period_month": "2026-07",
|
||||
"source": "fixture",
|
||||
}
|
||||
report = build_service_cost_report(
|
||||
[
|
||||
ServiceCostLine(amount=10.0, currency="EUR", environment="production", **common),
|
||||
ServiceCostLine(amount=20.0, currency="USD", environment="production", **common),
|
||||
ServiceCostLine(amount=30.0, currency="EUR", environment="development", **common),
|
||||
]
|
||||
)
|
||||
|
||||
assert {
|
||||
(row["environment"], row["currency"], row["total"])
|
||||
for row in report["services"]
|
||||
} == {
|
||||
("production", "EUR", 10.0),
|
||||
("production", "USD", 20.0),
|
||||
("development", "EUR", 30.0),
|
||||
}
|
||||
assert report["totals_by_period_currency"] == [
|
||||
{"period_month": "2026-07", "currency": "EUR", "total": 40.0},
|
||||
{"period_month": "2026-07", "currency": "USD", "total": 20.0},
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue