Spaces:
Runtime error
Runtime error
Download tests/test_smoke.py from devmurtaza/RastaAI: direct link, hf CLI and curl.
- Browser
- Download file 1.97 kB
-
https://huggingface.co/spaces/devmurtaza/RastaAI/resolve/main/tests/test_smoke.py
- Command line
-
hf download hf://spaces/devmurtaza/RastaAI/tests/test_smoke.py
-
curl -L -o test_smoke.py https://huggingface.co/spaces/devmurtaza/RastaAI/resolve/main/tests/test_smoke.py
1.97 kB
| """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 | |
| 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" | |
| 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" | |
| 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) | |
| 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 | |