mediastorm / tests /test_api.py
remdms's picture
feat(api): replace SSE chat with sync POST /api/search
4bb26eb
import os
import pytest
from httpx import AsyncClient, ASGITransport
from mediastorm.api import app
@pytest.mark.asyncio
async def test_search_requires_query():
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
resp = await client.post("/api/search", json={})
assert resp.status_code == 422
@pytest.mark.asyncio
async def test_search_returns_stories():
"""Integration test — requires GEMINI_API_KEY and populated ChromaDB."""
if not os.environ.get("GEMINI_API_KEY"):
pytest.skip("GEMINI_API_KEY not set")
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
resp = await client.post("/api/search", json={"query": "Emmy winning documentaries"})
assert resp.status_code == 200
data = resp.json()
assert "stories" in data
assert isinstance(data["stories"], list)
@pytest.mark.asyncio
async def test_health():
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
resp = await client.get("/api/health")
assert resp.status_code == 200
data = resp.json()
assert "status" in data
assert data["status"] == "ok"
@pytest.mark.asyncio
async def test_stories_returns_list():
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
resp = await client.get("/api/stories")
assert resp.status_code == 200
data = resp.json()
assert "stories" in data
assert isinstance(data["stories"], list)
if data["stories"]:
story = data["stories"][0]
assert "uid" in story
assert "name" in story
assert "slug" in story
assert "poster" in story