File size: 2,233 Bytes
bf34e9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pytest


@pytest.mark.asyncio
async def test_list_vods_empty(client):
    resp = await client.get("/user/vod")
    assert resp.status_code == 200
    body = resp.json()
    assert body["code"] == 0
    assert body["data"]["total"] == 0
    assert body["data"]["list"] == []


@pytest.mark.asyncio
async def test_list_vods_with_data(client, db_session):
    from app.models.vod import Vod
    from app.models.category import Category

    cat = Category(name="电影", sort_order=1, is_active=True)
    db_session.add(cat)
    await db_session.flush()

    vod = Vod(name="测试影片", category_id=cat.id, is_hidden=False)
    db_session.add(vod)
    await db_session.commit()

    resp = await client.get("/user/vod")
    assert resp.status_code == 200
    body = resp.json()
    assert body["code"] == 0
    assert body["data"]["total"] >= 1


@pytest.mark.asyncio
async def test_search_vods(client, db_session):
    from app.models.vod import Vod
    from app.models.category import Category

    cat = Category(name="剧集", sort_order=2, is_active=True)
    db_session.add(cat)
    await db_session.flush()

    vod = Vod(name="搜索测试剧", category_id=cat.id, is_hidden=False)
    db_session.add(vod)
    await db_session.commit()

    resp = await client.get("/user/vod/search?keyword=搜索测试")
    assert resp.status_code == 200
    body = resp.json()
    assert body["code"] == 0
    assert body["data"]["total"] >= 1


@pytest.mark.asyncio
async def test_get_vod_not_found(client):
    resp = await client.get("/user/vod/99999")
    assert resp.status_code == 200
    assert resp.json()["code"] == 40401


@pytest.mark.asyncio
async def test_get_vod_detail(client, db_session):
    from app.models.vod import Vod
    from app.models.category import Category

    cat = Category(name="综艺", sort_order=3, is_active=True)
    db_session.add(cat)
    await db_session.flush()

    vod = Vod(name="详情测试影片", category_id=cat.id, is_hidden=False)
    db_session.add(vod)
    await db_session.commit()

    resp = await client.get(f"/user/vod/{vod.id}")
    assert resp.status_code == 200
    body = resp.json()
    assert body["code"] == 0
    assert body["data"]["name"] == "详情测试影片"