feat: add get_motor_vehicles() and journey_has_motor() to config_loader
This commit is contained in:
@@ -5,10 +5,24 @@ def get_vehicles():
|
|||||||
return current_app.config.get("TOML", {}).get("vehicles", {})
|
return current_app.config.get("TOML", {}).get("vehicles", {})
|
||||||
|
|
||||||
|
|
||||||
|
def get_motor_vehicles():
|
||||||
|
"""Retourne uniquement les véhicules de type 'moteur'."""
|
||||||
|
return {k: v for k, v in get_vehicles().items() if v.get("type") == "moteur"}
|
||||||
|
|
||||||
|
|
||||||
def get_journeys():
|
def get_journeys():
|
||||||
return current_app.config.get("TOML", {}).get("journeys", {})
|
return current_app.config.get("TOML", {}).get("journeys", {})
|
||||||
|
|
||||||
|
|
||||||
|
def journey_has_motor(journey_profile_id: str | None) -> bool:
|
||||||
|
"""Retourne True si le profil de trajet inclut un véhicule à moteur."""
|
||||||
|
if not journey_profile_id:
|
||||||
|
return False
|
||||||
|
journeys = get_journeys()
|
||||||
|
profile = journeys.get(journey_profile_id, {})
|
||||||
|
return "moteur" in profile.get("distances", {})
|
||||||
|
|
||||||
|
|
||||||
def get_bareme(year: int, cv: int) -> list[dict]:
|
def get_bareme(year: int, cv: int) -> list[dict]:
|
||||||
bareme = current_app.config.get("TOML", {}).get("bareme_kilometrique", {})
|
bareme = current_app.config.get("TOML", {}).get("bareme_kilometrique", {})
|
||||||
year_data = bareme.get(str(year), {})
|
year_data = bareme.get(str(year), {})
|
||||||
|
|||||||
@@ -2,16 +2,40 @@ def test_get_vehicles_returns_configured_vehicles(app):
|
|||||||
with app.app_context():
|
with app.app_context():
|
||||||
from app.config_loader import get_vehicles
|
from app.config_loader import get_vehicles
|
||||||
vehicles = get_vehicles()
|
vehicles = get_vehicles()
|
||||||
assert "voiture" in vehicles
|
assert "familiale" in vehicles
|
||||||
assert vehicles["voiture"]["co2_per_km"] == 142
|
assert vehicles["familiale"]["co2_per_km"] == 142
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_motor_vehicles_excludes_velo(app):
|
||||||
|
with app.app_context():
|
||||||
|
from app.config_loader import get_motor_vehicles
|
||||||
|
motor = get_motor_vehicles()
|
||||||
|
assert "familiale" in motor
|
||||||
|
assert "citadine" in motor
|
||||||
|
assert "moto" in motor
|
||||||
|
assert "velo" not in motor
|
||||||
|
|
||||||
|
|
||||||
def test_get_journeys_returns_profiles(app):
|
def test_get_journeys_returns_profiles(app):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
from app.config_loader import get_journeys
|
from app.config_loader import get_journeys
|
||||||
journeys = get_journeys()
|
journeys = get_journeys()
|
||||||
assert "voiture_seule" in journeys
|
assert "moteur_seul" in journeys
|
||||||
assert journeys["voiture_seule"]["distances"]["voiture"] == 25
|
assert journeys["moteur_seul"]["distances"]["moteur"] == 25
|
||||||
|
|
||||||
|
|
||||||
|
def test_journey_has_motor_true(app):
|
||||||
|
with app.app_context():
|
||||||
|
from app.config_loader import journey_has_motor
|
||||||
|
assert journey_has_motor("moteur_seul") is True
|
||||||
|
assert journey_has_motor("moteur_velo") is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_journey_has_motor_false(app):
|
||||||
|
with app.app_context():
|
||||||
|
from app.config_loader import journey_has_motor
|
||||||
|
assert journey_has_motor("velo_seul") is False
|
||||||
|
assert journey_has_motor(None) is False
|
||||||
|
|
||||||
|
|
||||||
def test_get_bareme_returns_tranches(app):
|
def test_get_bareme_returns_tranches(app):
|
||||||
|
|||||||
Reference in New Issue
Block a user