spb/satelliteindex
Public
TypeScript 66.5%
Python 30.9%
JavaScript 1.4%
CSS 0.7%
1"""API integration smoke tests (need the local database with ingested data; skipped otherwise)."""2from __future__ import annotations34import asyncio56import httpx7import pytest89from satelliteindex.api.main import app10from satelliteindex.db import connection, dispose, fetch_val1112pytestmark = pytest.mark.asyncio131415async def _db_ready() -> bool:16 try:17 async with connection() as conn:18 return int(await fetch_val(conn, "select count(*) from satellites")) > 100019 except Exception: # noqa: BLE00120 return False21 finally:22 await dispose()232425@pytest.fixture(scope="module")26def has_db() -> bool:27 return asyncio.run(_db_ready())282930@pytest.fixture31async def client(has_db):32 if not has_db:33 pytest.skip("database not available / not ingested")34 async with app.router.lifespan_context(app):35 transport = httpx.ASGITransport(app=app)36 async with httpx.AsyncClient(transport=transport, base_url="http://test") as c:37 yield c383940async def test_health(client):41 r = await client.get("/api/v1/health")42 assert r.status_code == 200 and r.json()["components"]["database"]["status"] == "ok"434445async def test_satellite_detail_and_position(client):46 r = await client.get("/api/v1/satellites/25544")47 assert r.status_code == 20048 d = r.json()["data"]49 assert d["norad_id"] == 25544 and d["object_type"] == "STATION" and d["orbit_class"] == "LEO"50 assert d["live"] is None or 350 < d["live"]["altitude_km"] < 46051 r = await client.get("/api/v1/satellites/25544/position")52 assert r.status_code == 200 and "lat" in r.json()["data"]53 r = await client.get(f"/api/v1/satellites/{d['slug']}")54 assert r.status_code == 20055 r = await client.get("/api/v1/satellites/does-not-exist-0")56 assert r.status_code == 404 and "error" in r.json()575859async def test_search_and_list(client):60 r = await client.get("/api/v1/search", params={"q": "ISS"})61 assert r.status_code == 20062 hits = r.json()["data"]["results"]63 assert any(h["entity_type"] == "satellite" and "ISS" in h["title"] for h in hits)64 r = await client.get("/api/v1/satellites", params={"constellation": "starlink", "status": "ACTIVE", "page_size": 5})65 body = r.json()66 assert r.status_code == 200 and body["pagination"]["total"] > 1000 and len(body["data"]) == 5676869async def test_stats_and_positions(client):70 r = await client.get("/api/v1/stats")71 assert r.status_code == 200 and int(r.json()["data"]["global"]["active_satellites"]) > 500072 r = await client.get("/api/v1/orbit/positions")73 assert r.status_code == 20074 snap = r.json()["data"]75 assert snap["count"] > 5000 and len(snap["pos"]) == snap["count"] * 6767778async def test_admin_requires_token(client):79 r = await client.get("/api/v1/admin/overview")80 assert r.status_code == 40181