Skip to content

Commit ab28c6f

Browse files
committed
Strengthen demo core row contract
1 parent ac65c9b commit ab28c6f

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎tests/integration/test_demo_contract.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
``meta.free_commodities`` is internally consistent).
2020
"""
2121

22+
import math
2223
import os
2324

2425
import httpx
@@ -68,15 +69,22 @@ def test_prices_envelope_and_parsing(self, demo: DemoResource) -> None:
6869
assert isinstance(prices, list)
6970

7071
by_code = {p["code"]: p for p in prices}
72+
assert len(by_code) == len(prices)
7173
# The demo catalogue may grow. Its original core must remain usable.
7274
assert CORE_DEMO_CODES <= by_code.keys()
7375

74-
brent = by_code["BRENT_CRUDE_USD"]
75-
# Each price row carries the documented fields.
76-
for field in ("code", "name", "price", "currency", "updated_at"):
77-
assert field in brent
76+
for code in CORE_DEMO_CODES:
77+
row = by_code[code]
78+
assert row["code"] == code
79+
assert isinstance(row["name"], str) and row["name"]
80+
assert isinstance(row["currency"], str) and row["currency"]
81+
assert isinstance(row["updated_at"], str) and row["updated_at"]
82+
price = float(row["price"])
83+
assert math.isfinite(price) and price > 0
84+
85+
brent_price = float(by_code["BRENT_CRUDE_USD"]["price"])
7886
# Sanity-check Brent is in a plausible band (~$80, allow wide drift).
79-
assert 30 < float(brent["price"]) < 200
87+
assert 30 < brent_price < 200
8088

8189
def test_prices_meta_demo_mode(self, demo: DemoResource) -> None:
8290
"""The demo prices meta block flags demo mode and lists free commodities."""

0 commit comments

Comments
 (0)