mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-10-29 19:37:54 +08:00
56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
"""
|
|
验证严格存储查询的成功、缺失与错误覆盖。
|
|
"""
|
|
|
|
import importlib
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from app.modules.filemanager.storages import StorageBase
|
|
from app.schemas.exception import StorageQueryError
|
|
|
|
# 在树存储模块,全部必须实现严格查询
|
|
BUILTIN_STORAGE_MODULES = ["alipan", "alist", "local", "rclone", "smb", "u115"]
|
|
|
|
|
|
def test_base_get_item_strict_fails_conservatively():
|
|
"""
|
|
未覆写严格查询的存储必须保守失败,而不是回退到宽松查询。
|
|
"""
|
|
stub = SimpleNamespace(schema="dummy")
|
|
|
|
with pytest.raises(StorageQueryError):
|
|
StorageBase.get_item_strict(stub, Path("/media/示例.mkv"))
|
|
|
|
|
|
def test_base_list_strict_fails_conservatively():
|
|
"""
|
|
未适配严格目录查询的存储不能把宽松查询的空结果当作完整快照。
|
|
"""
|
|
stub = SimpleNamespace(schema="dummy")
|
|
|
|
with pytest.raises(StorageQueryError):
|
|
StorageBase.list_strict(stub, SimpleNamespace(path="/media"))
|
|
|
|
|
|
@pytest.mark.parametrize("module_name", BUILTIN_STORAGE_MODULES)
|
|
def test_builtin_storage_overrides_strict_query(module_name):
|
|
"""
|
|
每个在树存储都必须覆写严格查询,否则整理会被基类保守拒绝。
|
|
"""
|
|
module = importlib.import_module(f"app.modules.filemanager.storages.{module_name}")
|
|
storage_classes = [
|
|
obj for obj in vars(module).values()
|
|
if isinstance(obj, type)
|
|
and issubclass(obj, StorageBase)
|
|
and obj is not StorageBase
|
|
and obj.__module__ == module.__name__
|
|
]
|
|
|
|
assert storage_classes, f"{module_name} 未定义存储类"
|
|
for storage_class in storage_classes:
|
|
assert "get_item_strict" in vars(storage_class), \
|
|
f"{storage_class.__name__} 未实现 get_item_strict"
|