Files
Auto_Bangumi/examples/plugins/manual-pick/tests/test_manual_pick.py
Estrella Pan f3359b17fd feat(examples): manual-pick 前端改由 web-src/ 构建,补充测试
插件市场要求带前端的插件以 web-src/ 源码提交、至少有 1 个测试。ab-plugin pack
不再打包 web-src/,运行时只需要构建出的 web/。
2026-10-09 10:07:37 +02:00

38 lines
1.1 KiB
Python

from fastapi import FastAPI
from fastapi.testclient import TestClient
from manual_pick import ManualPick, Picked
from ab_sdk.testing import create_plugin
def client():
plugin, ctx = create_plugin(ManualPick)
app = FastAPI()
app.include_router(plugin.api())
return TestClient(app), ctx
def test_get_pick_nothing_picked_returns_null():
http, _ = client()
assert http.get("/picks/1").json() == {"torrent_id": None}
def test_put_pick_saves_selection_per_bangumi():
http, ctx = client()
assert http.put("/picks/1", json={"torrent_id": 7}).json() == {"torrent_id": 7}
assert http.get("/picks/1").json() == {"torrent_id": 7}
assert http.get("/picks/2").json() == {"torrent_id": None}
assert ctx.kv.data == {"pick:1": 7}
def test_put_pick_publishes_picked_event():
http, ctx = client()
http.put("/picks/3", json={"torrent_id": 9})
assert ctx.bus.published == [Picked(bangumi_id=3, torrent_id=9)]
def test_put_pick_invalid_body_returns_422_and_publishes_nothing():
http, ctx = client()
assert http.put("/picks/1", json={"torrent_id": "x"}).status_code == 422
assert ctx.bus.published == []