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:
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