Fix API base URL, rate-limit paging, background refresh; verify live against official API

- Base URL corrected to https://www.fuel-finder.service.gov.uk (the
  api.fuelfinder.service.gov.uk host in the portal's examples is stale —
  it does not resolve; www.fuel-finder... resolves to CloudFront and is
  what the live spec uses). Verified: /health now reports source=api,
  8,010 stations, 0 failures.
- Fuel Finder is strictly sequential (30 rpm per client, 429 on overlap):
  added FUEL_API_BATCH_SLEEP (default 4.0s) between pages ≈ 15 rpm.
- Stale-cache refresh moved off the request path into a background
  thread — a multi-minute rate-limited sync no longer blows the app's
  5s timeout; stale data is served while it catches up.
- Multiple diesel variants (B7_STANDARD, B7_PREMIUM, B10) now map to
  DIESEL as the MINIMUM price, so a premium price can't inflate the
  cheapest-diesel reference (CSV relay took first-wins; min is safer).
- Added B7_PREMIUM (underscore) to the fuel map — official key.
- scripts/run.sh now prefers the project venv (bare python3 missed
  uvicorn when run outside an activated env).
- Tests updated for min-diesel + B7_PREMIUM; 12/12 pass.
This commit is contained in:
FuelBoard Contributor
2026-08-12 15:50:08 +01:00
parent b315f4dc47
commit bd3d3862ec
5 changed files with 87 additions and 23 deletions
+2 -1
View File
@@ -70,6 +70,7 @@ class TestNormaliseApiPayload:
{"price": "137.9000", "fuel_type": "E10", "price_last_updated": "2026-08-12T08:15:23"},
{"price": "144.9000", "fuel_type": "E5", "price_last_updated": "2026-08-12T08:15:24"},
{"price": "149.9000", "fuel_type": "B7_STANDARD", "price_last_updated": "2026-08-12T08:15:25"},
{"price": "151.9000", "fuel_type": "B7_PREMIUM", "price_last_updated": "2026-08-12T08:16:00"},
],
}]
@@ -82,7 +83,7 @@ class TestNormaliseApiPayload:
assert s["lat"] == 53.7265
assert s["lng"] == -1.8580
assert s["prices"] == {"E10": 137.9, "E5": 144.9, "DIESEL": 149.9}
assert s["price_updated"] == "2026-08-12T08:15:25"
assert s["price_updated"] == "2026-08-12T08:16:00"
def test_unpriced_fuel_dropped(self):
stations_info = [{