mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-10 07:54:14 +08:00
fix https://github.com/jxxghp/MoviePilot/issues/6205
This commit is contained in:
50
tests/test_file_uri.py
Normal file
50
tests/test_file_uri.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from app.schemas.file import FileURI
|
||||
|
||||
|
||||
def test_from_uri_keeps_windows_drive_path() -> None:
|
||||
"""Windows 盘符路径已是绝对路径,不能再补根斜杠,否则映射网络驱动器整理会报 WinError 123。"""
|
||||
file_uri = FileURI.from_uri("Z:/Downloads/电视剧/国产剧")
|
||||
|
||||
assert file_uri.storage == "local"
|
||||
assert file_uri.path == "Z:/Downloads/电视剧/国产剧"
|
||||
assert file_uri.uri == "Z:/Downloads/电视剧/国产剧"
|
||||
|
||||
|
||||
def test_from_uri_keeps_windows_drive_path_with_backslash() -> None:
|
||||
"""反斜杠写法的盘符路径同样不能补根斜杠。"""
|
||||
file_uri = FileURI.from_uri("Z:\\Downloads\\电视剧")
|
||||
|
||||
assert file_uri.storage == "local"
|
||||
assert not file_uri.path.startswith("/")
|
||||
|
||||
|
||||
def test_from_uri_keeps_posix_absolute_path() -> None:
|
||||
"""POSIX 绝对路径保持原样。"""
|
||||
file_uri = FileURI.from_uri("/downloads/movies")
|
||||
|
||||
assert file_uri.storage == "local"
|
||||
assert file_uri.path == "/downloads/movies"
|
||||
|
||||
|
||||
def test_from_uri_adds_root_for_relative_path() -> None:
|
||||
"""无前导斜杠的相对路径仍补全为绝对路径。"""
|
||||
file_uri = FileURI.from_uri("downloads/movies")
|
||||
|
||||
assert file_uri.path == "/downloads/movies"
|
||||
|
||||
|
||||
def test_from_uri_parses_storage_prefix() -> None:
|
||||
"""带存储前缀的 URI 应拆分出存储类型并保留 POSIX 路径。"""
|
||||
file_uri = FileURI.from_uri("u115:/media/anime")
|
||||
|
||||
assert file_uri.storage == "u115"
|
||||
assert file_uri.path == "/media/anime"
|
||||
assert file_uri.uri == "u115:/media/anime"
|
||||
|
||||
|
||||
def test_from_uri_storage_prefix_with_relative_path() -> None:
|
||||
"""远端存储的无前导斜杠路径补全为绝对路径。"""
|
||||
file_uri = FileURI.from_uri("rclone:media/anime")
|
||||
|
||||
assert file_uri.storage == "rclone"
|
||||
assert file_uri.path == "/media/anime"
|
||||
29
tests/test_mediaserver_conf_sync_interval.py
Normal file
29
tests/test_mediaserver_conf_sync_interval.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from app.helper.service import ServiceConfigHelper
|
||||
from app.schemas.system import MediaServerConf
|
||||
from app.schemas.types import SystemConfigKey
|
||||
|
||||
|
||||
def test_mediaserver_conf_tolerates_blank_sync_interval():
|
||||
"""自动同步间隔为空字符串等非法值时应回退为 None 而不是抛出校验错误。"""
|
||||
assert MediaServerConf(name="blank", sync_interval="").sync_interval is None
|
||||
assert MediaServerConf(name="spaces", sync_interval=" ").sync_interval is None
|
||||
assert MediaServerConf(name="invalid", sync_interval="abc").sync_interval is None
|
||||
assert MediaServerConf(name="text", sync_interval="12").sync_interval == 12
|
||||
assert MediaServerConf(name="number", sync_interval=6).sync_interval == 6
|
||||
assert MediaServerConf(name="none", sync_interval=None).sync_interval is None
|
||||
|
||||
|
||||
def test_get_configs_skips_invalid_entries(monkeypatch):
|
||||
"""单条配置校验失败时应跳过该条,不影响其它服务配置的加载。"""
|
||||
monkeypatch.setattr(
|
||||
"app.helper.service.SystemConfigOper.get",
|
||||
lambda self, key: [
|
||||
{"name": "good", "type": "emby", "enabled": True},
|
||||
"bad-format",
|
||||
{"name": "bad-type", "type": "plex", "enabled": "maybe"},
|
||||
],
|
||||
)
|
||||
|
||||
configs = ServiceConfigHelper.get_configs(SystemConfigKey.MediaServers, MediaServerConf)
|
||||
|
||||
assert [conf.name for conf in configs] == ["good"]
|
||||
Reference in New Issue
Block a user