|
19 | 19 | ``meta.free_commodities`` is internally consistent). |
20 | 20 | """ |
21 | 21 |
|
| 22 | +import math |
22 | 23 | import os |
23 | 24 |
|
24 | 25 | import httpx |
@@ -68,15 +69,22 @@ def test_prices_envelope_and_parsing(self, demo: DemoResource) -> None: |
68 | 69 | assert isinstance(prices, list) |
69 | 70 |
|
70 | 71 | by_code = {p["code"]: p for p in prices} |
| 72 | + assert len(by_code) == len(prices) |
71 | 73 | # The demo catalogue may grow. Its original core must remain usable. |
72 | 74 | assert CORE_DEMO_CODES <= by_code.keys() |
73 | 75 |
|
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"]) |
78 | 86 | # 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 |
80 | 88 |
|
81 | 89 | def test_prices_meta_demo_mode(self, demo: DemoResource) -> None: |
82 | 90 | """The demo prices meta block flags demo mode and lists free commodities.""" |
|
0 commit comments