Files
tableau-de-bord/tests/conftest.py
2026-08-13 17:25:48 +02:00

92 lines
1.7 KiB
Python

import pytest
from app import create_app
from app import db as _db
from tests.in_memory_db import IN_MEMORY_DATABASE_URI, in_memory_engine_options
@pytest.fixture
def app(tmp_path):
config_path = tmp_path / "config.toml"
config_path.write_text(
"""
[vehicles.citadine]
name = "Citadine électrique"
fuel = "electric"
co2_per_km = 0
cv = 3
type = "moteur"
[vehicles.familiale]
name = "Familiale thermique"
fuel = "diesel"
co2_per_km = 142
cv = 5
type = "moteur"
[vehicles.moto]
name = "Moto"
fuel = "essence"
co2_per_km = 90
cv = 3
type = "moteur"
[vehicles.velo]
name = "Vélo"
fuel = "none"
co2_per_km = 0
type = "velo"
[journeys.moteur_seul]
name = "Véhicule à moteur seul"
distances = { moteur = 25 }
[journeys.moteur_velo]
name = "Véhicule à moteur + Vélo"
distances = { moteur = 14, velo = 8 }
[journeys.velo_seul]
name = "Vélo seul"
distances = { velo = 24 }
[home_assistant]
timezone = "Europe/Paris"
default_day_type = "WORK"
default_journey_profile_id = "moteur_seul"
default_motor_vehicle_id = "citadine"
[[bareme_kilometrique.2025.cv_5.tranches]]
km_max = 3000
taux = 0.548
forfait = 0
[[bareme_kilometrique.2025.cv_5.tranches]]
km_max = 6000
taux = 0.316
forfait = 699
[[bareme_kilometrique.2025.cv_5.tranches]]
km_max = 0
taux = 0.364
forfait = 0
""",
encoding="utf-8",
)
application = create_app(
config_path=str(config_path),
database_uri=IN_MEMORY_DATABASE_URI,
engine_options=in_memory_engine_options(),
)
application.config["TESTING"] = True
with application.app_context():
_db.create_all()
yield application
_db.drop_all()
@pytest.fixture
def client(app):
return app.test_client()