File size: 1,845 Bytes
ea63c1f
 
61a9b93
 
 
 
 
ea63c1f
4bb26eb
ea63c1f
 
4bb26eb
ea63c1f
 
 
4bb26eb
 
 
 
 
 
 
 
 
 
 
 
 
 
61a9b93
 
 
 
 
 
 
 
 
de2956c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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