Fuel Advisor: stations reelles avec Waze/Google Maps, liste depliable, enseignes sans monogramme, contexte marche et Brent quotidien FRED
57 stations renvoyees au lieu de 12; cout reel par option (carburant + detour marginal) et ecart en euros; bouton Afficher les N autres stations alimente par un compte serveur teste (0/1-2/3/>3); pictogramme neutre + nom complet, aucun logo de marque tierce; Brent DCOILBRENTEU (EIA via FRED) quotidien avec date d observation reelle; sections techniques repliees.
This commit is contained in:
83
tests/test_brent.py
Normal file
83
tests/test_brent.py
Normal file
@@ -0,0 +1,83 @@
|
||||
"""Brent quotidien : parsing, âge réel et absence de report de valeur."""
|
||||
|
||||
import sqlite3
|
||||
from datetime import date
|
||||
|
||||
import pytest
|
||||
|
||||
import brent
|
||||
|
||||
HEADER = "observation_date,DCOILBRENTEU\n"
|
||||
FIXTURE = HEADER + "2026-09-07,104.47\n2026-09-08,.\n2026-09-09,109.51\n2026-09-10,\n"
|
||||
|
||||
|
||||
def memory():
|
||||
db = sqlite3.connect(":memory:")
|
||||
db.row_factory = sqlite3.Row
|
||||
return db
|
||||
|
||||
|
||||
def test_parse_ignore_les_valeurs_manquantes():
|
||||
rows = brent.parse(FIXTURE)
|
||||
assert rows == [("2026-09-07", 104.47), ("2026-09-09", 109.51)]
|
||||
|
||||
|
||||
def test_parse_rejette_une_valeur_non_exploitable():
|
||||
assert brent.parse(HEADER + "2026-09-09,-3.2\n") == []
|
||||
assert brent.parse(HEADER + "2026-09-09,abc\n") == []
|
||||
|
||||
|
||||
def test_refresh_conserve_la_date_d_observation_et_fetched_at_distincts():
|
||||
db = memory()
|
||||
report = brent.refresh(db=db, text=FIXTURE, fetched_at="2026-09-11T06:00:00+00:00")
|
||||
assert report["stored"] == 2
|
||||
row = db.execute("SELECT * FROM brent_daily ORDER BY observed_at").fetchone()
|
||||
assert row["observed_at"] == "2026-09-07"
|
||||
assert row["available_at"] == "2026-09-08"
|
||||
assert row["fetched_at"] == "2026-09-11T06:00:00+00:00"
|
||||
assert row["source"] == "EIA via FRED"
|
||||
|
||||
|
||||
def test_aucun_report_de_valeur_sur_une_journee_absente():
|
||||
db = memory()
|
||||
brent.refresh(db=db, text=FIXTURE)
|
||||
days = [row[0] for row in db.execute("SELECT observed_at FROM brent_daily ORDER BY 1")]
|
||||
assert days == ["2026-09-07", "2026-09-09"] # le 08 et le 10 n'existent pas, pas de report
|
||||
|
||||
|
||||
def test_refresh_ne_reecrit_pas_une_observation_connue():
|
||||
db = memory()
|
||||
brent.refresh(db=db, text=FIXTURE)
|
||||
brent.refresh(db=db, text=FIXTURE)
|
||||
assert brent.count(db) == 2
|
||||
|
||||
|
||||
def test_latest_annonce_la_derniere_observation_disponible_quand_elle_vieillit():
|
||||
db = memory()
|
||||
brent.refresh(db=db, text=FIXTURE)
|
||||
block = brent.latest(db=db, today=date(2026, 9, 20))
|
||||
assert block["usd_per_barrel"] == 109.51
|
||||
assert block["age_days"] == 11
|
||||
assert block["stale"] is True
|
||||
assert block["summary"] == "Dernière observation disponible il y a 11 jours"
|
||||
assert block["summary"] != "cours du jour"
|
||||
|
||||
|
||||
def test_latest_affiche_la_date_quand_l_observation_est_recente():
|
||||
db = memory()
|
||||
brent.refresh(db=db, text=FIXTURE)
|
||||
block = brent.latest(db=db, today=date(2026, 9, 10))
|
||||
assert block["stale"] is False
|
||||
assert block["summary"] == "Observation du 09/09/2026"
|
||||
|
||||
|
||||
def test_latest_sans_donnee_ne_pretend_pas_a_un_prix():
|
||||
block = brent.latest(db=memory())
|
||||
assert block["available"] is False
|
||||
assert block["summary"] == "Brent spot temporairement indisponible"
|
||||
assert "usd_per_barrel" not in block
|
||||
|
||||
|
||||
def test_refresh_refuse_une_serie_vide():
|
||||
with pytest.raises(ValueError):
|
||||
brent.refresh(db=memory(), text="")
|
||||
109
tests/test_station_list.py
Normal file
109
tests/test_station_list.py
Normal file
@@ -0,0 +1,109 @@
|
||||
"""Liste des stations : découpe de l'affichage, coûts réels et liens de navigation."""
|
||||
|
||||
import pytest
|
||||
|
||||
import app as application
|
||||
|
||||
NAV = (44.777, -0.61)
|
||||
|
||||
|
||||
def station(identifier, price, distance=None):
|
||||
class Station:
|
||||
pass
|
||||
|
||||
item = Station()
|
||||
item.id = identifier
|
||||
item.price = price
|
||||
item.route_distance_km = distance
|
||||
return item
|
||||
|
||||
|
||||
def vehicle(consumption=5.0):
|
||||
return dict(consumption=consumption)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("total", "visible", "hidden"),
|
||||
[
|
||||
(0, 0, 0), # aucune station
|
||||
(1, 1, 0), # une seule
|
||||
(2, 2, 0), # deux
|
||||
(3, 3, 0), # exactement trois
|
||||
(4, 3, 1), # le bouton doit annoncer 1
|
||||
(57, 3, 54),
|
||||
],
|
||||
)
|
||||
def test_decoupe_de_la_liste(total, visible, hidden):
|
||||
block = application.station_display(total)
|
||||
assert (block["visible"], block["hidden"]) == (visible, hidden)
|
||||
assert block["total"] == total
|
||||
|
||||
|
||||
def test_le_bouton_n_est_jamais_relie_a_une_liste_vide():
|
||||
for total in range(0, 6):
|
||||
block = application.station_display(total)
|
||||
assert block["hidden"] == 0 if total <= 3 else block["hidden"] > 0
|
||||
|
||||
|
||||
def test_liens_de_navigation_exacts():
|
||||
links = application.navigation_links(*NAV)
|
||||
assert links["google_maps"] == (
|
||||
"https://www.google.com/maps/dir/?api=1&destination=44.777000,-0.610000&travelmode=driving"
|
||||
)
|
||||
assert links["waze"] == "https://waze.com/ul?ll=44.777000,-0.610000&navigate=yes"
|
||||
assert links["coordinates"] == "44.777000,-0.610000"
|
||||
|
||||
|
||||
def test_liens_de_navigation_transportes_par_chaque_station():
|
||||
class Station:
|
||||
pass
|
||||
|
||||
item = Station()
|
||||
item.id = "1"
|
||||
item.price = 1.7
|
||||
item.route_distance_km = 5.0
|
||||
item.navigation = application.navigation_links(*NAV)
|
||||
assert "destination=44.777000" in item.navigation["google_maps"]
|
||||
assert "ll=44.777000" in item.navigation["waze"]
|
||||
|
||||
|
||||
def test_cout_reel_du_detour_penalise_la_station_lointaine():
|
||||
stations = [station("proche", 1.80, 2.0), station("loin", 1.70, 12.0)]
|
||||
options = application.station_options(stations, vehicle(5.0), 30)
|
||||
proche, loin = options["proche"], options["loin"]
|
||||
assert proche["extra_km"] == 0.0 and loin["extra_km"] == 10.0
|
||||
assert proche["fuel_cost_eur"] == 54.0
|
||||
# 10 km de détour consomment 0,5 L au prix de la station lointaine
|
||||
assert loin["detour_cost_eur"] == 0.85
|
||||
assert loin["total_cost_eur"] == pytest.approx(51.0 + 0.85, abs=0.01)
|
||||
assert loin["total_cost_eur"] < proche["total_cost_eur"]
|
||||
assert proche["delta_eur"] > 0 and loin["delta_eur"] == 0
|
||||
assert loin["best"] is True and proche["best"] is False
|
||||
|
||||
|
||||
def test_une_station_plus_chere_et_plus_loin_perd():
|
||||
stations = [station("proche", 1.70, 1.0), station("loin", 1.79, 11.0)]
|
||||
options = application.station_options(stations, vehicle(6.0), 30)
|
||||
assert options["proche"]["best"] is True
|
||||
assert options["loin"]["delta_eur"] > 0
|
||||
|
||||
|
||||
def test_sans_distance_routiere_aucun_cout_invente():
|
||||
stations = [station("a", 1.70, None)]
|
||||
assert application.station_options(stations, vehicle(5.0), 30) == {}
|
||||
|
||||
|
||||
def test_composant_de_marque_ne_pretend_pas_a_un_logo():
|
||||
component = application.brand_component(dict(brand="TotalEnergies", brand_slug="totalenergies"))
|
||||
assert component["name"] == "TotalEnergies"
|
||||
assert component["slug"] == "totalenergies"
|
||||
assert component["logo_asset"] is None
|
||||
assert component["logo_source"] is None
|
||||
assert component["logo_usage_status"] == "neutre"
|
||||
|
||||
|
||||
def test_composant_de_marque_sans_enseigne_reste_neutre():
|
||||
component = application.brand_component({})
|
||||
assert component["name"] is None
|
||||
assert component["slug"] == "inconnue"
|
||||
assert component["logo_usage_status"] == "neutre"
|
||||
Reference in New Issue
Block a user