mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
refactor: isolate pending transfer and config queries
This commit is contained in:
@@ -7,8 +7,10 @@
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from app.db import decorators
|
||||
from app.db.models.transferpending import TransferPending
|
||||
from app.db.oper.transferpending import TransferPendingOper
|
||||
from app.db.session import SessionFactory
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@@ -150,6 +152,40 @@ def test_oper_returns_plain_tuples_not_orm_instances(db):
|
||||
assert all(isinstance(item, tuple) for item in listed)
|
||||
|
||||
|
||||
def test_oper_reuses_explicit_query_session(db, monkeypatch):
|
||||
"""TransferPendingOper 查询必须复用调用方会话。"""
|
||||
db.add(TransferPending(
|
||||
storage="local",
|
||||
src_path="/mnt/explicit.mkv",
|
||||
created_at="2026-08-13 10:00:00",
|
||||
))
|
||||
monkeypatch.setattr(
|
||||
decorators,
|
||||
"ScopedSession",
|
||||
lambda: (_ for _ in ()).throw(AssertionError("不应创建额外同步会话")),
|
||||
)
|
||||
|
||||
assert ("local", "/mnt/explicit.mkv") in TransferPendingOper(db.session).list_all()
|
||||
|
||||
|
||||
def test_model_legacy_query_keeps_keyword_abi(db, monkeypatch):
|
||||
"""旧插件以关键字直调 TransferPending 时仍自动补入短会话。"""
|
||||
db.add(TransferPending(
|
||||
storage="local",
|
||||
src_path="/mnt/legacy.mkv",
|
||||
created_at="2026-08-13 10:00:00",
|
||||
))
|
||||
opened = []
|
||||
monkeypatch.setattr(
|
||||
decorators,
|
||||
"ScopedSession",
|
||||
lambda: (opened.append(True) or SessionFactory()),
|
||||
)
|
||||
|
||||
assert TransferPending.list_all(limit=1)
|
||||
assert opened == [True]
|
||||
|
||||
|
||||
def test_oper_drops_rows_with_missing_fields(db):
|
||||
"""
|
||||
回放时必须跳过字段残缺的历史遗留行,不能把空存储送进整理链。
|
||||
|
||||
Reference in New Issue
Block a user