Test: Added automatic seeding for sample taxis in lifespan to verify frontend

This commit is contained in:
2026-02-22 10:59:26 -05:00
parent e0cd9662c2
commit ed98d8c182

View File

@ -5,7 +5,9 @@ from fastapi.staticfiles import StaticFiles
import os
from app.core.config import settings
from app.core.database import init_db
from app.core.database import init_db, engine
from sqlmodel import Session, select
from app.models.taxi import Taxi
from app.api.routes import router as routes_router
from app.api.bus_stops import router as bus_stops_router
from app.api.schedules import router as schedules_router
@ -26,6 +28,33 @@ from contextlib import asynccontextmanager
async def lifespan(app: FastAPI):
# Initialize database
init_db()
# Seed sample data if empty
with Session(engine) as session:
taxi_count = session.exec(select(Taxi)).first()
if not taxi_count:
sample_taxis = [
Taxi(
owner_name="Don José (Sibu Demo)",
phone_number="+507 6000-0001",
license_plate="T-001-SIBU",
corregimiento="Boquete",
shift="dia",
rating=4.9,
english_speaking=True
),
Taxi(
owner_name="María C. (Sibu Demo)",
phone_number="+507 6000-0002",
license_plate="T-002-SIBU",
corregimiento="Boquete",
shift="tarde",
rating=5.0,
english_speaking=False
)
]
session.add_all(sample_taxis)
session.commit()
yield
app = FastAPI(