mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-11-02 21:34:32 +08:00
65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
"""
|
|
验证下载路径接口依据站点与媒体类型返回可用目录。
|
|
"""
|
|
|
|
from unittest.mock import patch
|
|
|
|
from app.api.endpoints import download as download_endpoint
|
|
from app.schemas.system import TransferDirectoryConf
|
|
from app.schemas.token import TokenPayload
|
|
|
|
|
|
def test_paths_returns_api_ready_save_paths() -> None:
|
|
"""
|
|
配置的本地和远程目录应转换为完整下载路径响应。
|
|
"""
|
|
mocked_dirs = [
|
|
TransferDirectoryConf(
|
|
name="电影目录",
|
|
priority=1,
|
|
storage="local",
|
|
download_path="/downloads/movies",
|
|
media_type="movie",
|
|
),
|
|
TransferDirectoryConf(
|
|
name="动漫远程目录",
|
|
priority=2,
|
|
storage="rclone",
|
|
download_path="/media/anime",
|
|
media_type="tv",
|
|
media_category="动漫",
|
|
media_category_id="tv.anime",
|
|
),
|
|
]
|
|
|
|
with patch.object(download_endpoint.DirectoryHelper, "get_download_dirs", return_value=mocked_dirs):
|
|
ret = download_endpoint.paths(_=TokenPayload())
|
|
|
|
assert len(ret) == 2
|
|
assert ret[0].name == "电影目录"
|
|
assert ret[0].storage == "local"
|
|
assert ret[0].download_path == "/downloads/movies"
|
|
assert ret[0].save_path == "/downloads/movies"
|
|
assert ret[0].priority == 1
|
|
assert ret[0].media_type == "movie"
|
|
assert ret[0].media_category is None
|
|
|
|
assert ret[1].name == "动漫远程目录"
|
|
assert ret[1].storage == "rclone"
|
|
assert ret[1].download_path == "/media/anime"
|
|
assert ret[1].save_path == "rclone:/media/anime"
|
|
assert ret[1].priority == 2
|
|
assert ret[1].media_type == "tv"
|
|
assert ret[1].media_category == "动漫"
|
|
assert ret[1].media_category_id == "tv.anime"
|
|
|
|
|
|
def test_paths_returns_empty_list_when_unconfigured() -> None:
|
|
"""
|
|
未配置目录时接口应返回空列表。
|
|
"""
|
|
with patch.object(download_endpoint.DirectoryHelper, "get_download_dirs", return_value=[]):
|
|
ret = download_endpoint.paths(_=TokenPayload())
|
|
|
|
assert ret == []
|