"""Smoke tests - run with: pytest -q These use httpx.AsyncClient against the FastAPI app directly, no live DB/Redis required. """ from __future__ import annotations import pytest from httpx import AsyncClient, ASGITransport from app.main import app @pytest.mark.asyncio async def test_root() -> None: async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac: r = await ac.get("/") assert r.status_code == 200 assert r.json()["service"] == "RastaAI" @pytest.mark.asyncio async def test_health() -> None: async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac: r = await ac.get("/api/v1/health") # may be degraded if DB/Redis not running - that's fine assert r.status_code == 200 assert r.json()["version"] == "0.1.0" @pytest.mark.asyncio async def test_cities() -> None: async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac: r = await ac.get("/api/v1/cities?q=lahore") assert r.status_code == 200 items = r.json() assert any(c["id"] == "lahore" for c in items) @pytest.mark.asyncio async def test_predict_route_synthetic() -> None: """Falls back to synthetic Bezier when OSRM is unreachable.""" async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac: payload = { "origin": {"id": "karachi"}, "destination": {"id": "lahore"}, "vehicle_type": "car", "preference": "balanced", } r = await ac.post("/api/v1/predict-route", json=payload) # 500 is acceptable if DB not up; otherwise must be 200 if r.status_code == 200: data = r.json() assert len(data["ranked_routes"]) >= 1 assert data["best_route_id"] == data["ranked_routes"][0]["route_id"] assert data["ranked_routes"][0]["is_best"] is True