fix(ingest): raise ref cap to 50 and clarify invalid bvid error
This commit is contained in:
1 parent
b5bf7d9b8f
commit
b0c53e8a2f
7 files changed
+107
-9
No files matched your search
+49
-2
@@ -13,7 +13,10 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
|
||||
from fixtures import view_for # noqa: E402
|
||||
from reaction_board.bilibili.client import BilibiliError # noqa: E402
|
||||
from reaction_board.bilibili.client import ( # noqa: E402
|
||||
BilibiliAPIError,
|
||||
BilibiliError,
|
||||
)
|
||||
from reaction_board.bilibili.models import VideoDetail # noqa: E402
|
||||
from reaction_board.config import ConfigStore # noqa: E402
|
||||
from reaction_board.database import Database # noqa: E402
|
||||
@@ -51,14 +54,18 @@ def detail(
|
||||
|
||||
|
||||
class FakeReadClient:
|
||||
def __init__(self, by_bvid=None, by_aid=None, short_map=None, fail_bvids=()):
|
||||
def __init__(self, by_bvid=None, by_aid=None, short_map=None, fail_bvids=(),
|
||||
api_errors=None):
|
||||
self.by_bvid = by_bvid or {}
|
||||
self.by_aid = by_aid or {}
|
||||
self.short_map = short_map or {}
|
||||
self.fail_bvids = set(fail_bvids)
|
||||
self.api_errors = dict(api_errors or {})
|
||||
|
||||
def view_detail(self, *, aid=None, bvid=None):
|
||||
if bvid is not None:
|
||||
if bvid in self.api_errors:
|
||||
raise BilibiliAPIError(self.api_errors[bvid], "请求错误")
|
||||
if bvid in self.fail_bvids:
|
||||
raise BilibiliError(f"view 失败: {bvid}")
|
||||
if bvid in self.by_bvid:
|
||||
@@ -263,6 +270,44 @@ def test_snapshot_not_overwritten():
|
||||
db.close()
|
||||
|
||||
|
||||
def test_manual_ingest_truncation():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
bvs = {
|
||||
"BV1x8x166E00": detail(1, bvid="BV1x8x166E00"),
|
||||
"BV1x8x166E01": detail(2, bvid="BV1x8x166E01"),
|
||||
"BV1x8x166E02": detail(3, bvid="BV1x8x166E02"),
|
||||
}
|
||||
client = FakeReadClient(by_bvid=bvs)
|
||||
store = ConfigStore(write_config(tmp), env={})
|
||||
db = Database(Path(tmp) / "app.db", backup_dir=Path(tmp) / "backup")
|
||||
db.initialize()
|
||||
try:
|
||||
repo = Repository(db, clock=lambda: NOW)
|
||||
service = LibraryService(
|
||||
store, repo, FakeProvider(client), clock=lambda: NOW, max_refs=2
|
||||
)
|
||||
result = service.ingest_text(" ".join(bvs))
|
||||
assert result.refs == 2
|
||||
assert result.truncated == 1
|
||||
assert result.added == 2
|
||||
assert len(result.results) == 2
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def test_manual_ingest_invalid_bvid_message():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
client = FakeReadClient(api_errors={"BV1x8x166E00": -400})
|
||||
db, repo, service = setup(tmp, client)
|
||||
try:
|
||||
result = service.ingest_text("BV1x8x166E00")
|
||||
assert result.refs == 1
|
||||
assert result.results[0].state == "error"
|
||||
assert "无效或视频不存在" in result.results[0].message
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def test_ignore_and_blacklist():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
client = FakeReadClient()
|
||||
@@ -289,6 +334,8 @@ def main():
|
||||
test_manual_ingest_forms_and_multiple()
|
||||
test_manual_ingest_error_isolation()
|
||||
test_snapshot_not_overwritten()
|
||||
test_manual_ingest_truncation()
|
||||
test_manual_ingest_invalid_bvid_message()
|
||||
test_ignore_and_blacklist()
|
||||
print("OK: 入库、手动入库、忽略、拉黑测试全部通过")
|
||||
|
||||
|
||||
Reference in new issue
Block a user