Download tests/test_api.py from binhugg2/api: direct link, hf CLI and curl.
- Browser
- Download file 2.23 kB
-
https://huggingface.co/spaces/binhugg2/api/resolve/main/tests/test_api.py
- Command line
-
hf download hf://spaces/binhugg2/api/tests/test_api.py
-
curl -L -o test_api.py https://huggingface.co/spaces/binhugg2/api/resolve/main/tests/test_api.py
2.23 kB
| import pytest | |
| 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"] == [] | |
| 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 | |
| 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 | |
| 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 | |
| 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"] == "详情测试影片" | |