mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
refactor(string): split utilities by responsibility
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
from importlib.machinery import EXTENSION_SUFFIXES, PathFinder
|
||||
from pathlib import Path
|
||||
|
||||
from app.application.site import _include_legacy_resource_directory
|
||||
from app.runtime.config import settings
|
||||
from app.adapters.system.resource import (
|
||||
ResourceHelper,
|
||||
@@ -13,41 +11,6 @@ from app.startup import modules_initializer
|
||||
ROOT_DIR = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_legacy_docker_updater_resource_directory_remains_importable(tmp_path):
|
||||
"""旧镜像把资源写入 helper 时,canonical 站点包仍应找到对应扩展。"""
|
||||
package_dir = tmp_path / "app" / "application" / "site"
|
||||
legacy_dir = tmp_path / "app" / "helper"
|
||||
package_dir.mkdir(parents=True)
|
||||
legacy_dir.mkdir(parents=True)
|
||||
extension_path = legacy_dir / f"sites{EXTENSION_SUFFIXES[0]}"
|
||||
extension_path.touch()
|
||||
package_paths = [str(package_dir)]
|
||||
|
||||
_include_legacy_resource_directory(package_paths, package_dir)
|
||||
|
||||
assert (ROOT_DIR / "app" / "helper" / ".resource-compat").is_file()
|
||||
assert package_paths == [str(package_dir), str(legacy_dir)]
|
||||
spec = PathFinder.find_spec("app.application.site.sites", package_paths)
|
||||
assert spec is not None
|
||||
assert spec.origin == str(extension_path)
|
||||
|
||||
|
||||
def test_canonical_site_extension_takes_priority_over_legacy_directory(tmp_path):
|
||||
"""canonical 扩展存在时不得把旧资源目录加入站点包搜索路径。"""
|
||||
package_dir = tmp_path / "app" / "application" / "site"
|
||||
legacy_dir = tmp_path / "app" / "helper"
|
||||
package_dir.mkdir(parents=True)
|
||||
legacy_dir.mkdir(parents=True)
|
||||
extension_name = f"sites{EXTENSION_SUFFIXES[0]}"
|
||||
(package_dir / extension_name).touch()
|
||||
(legacy_dir / extension_name).touch()
|
||||
package_paths = [str(package_dir)]
|
||||
|
||||
_include_legacy_resource_directory(package_paths, package_dir)
|
||||
|
||||
assert package_paths == [str(package_dir)]
|
||||
|
||||
|
||||
def test_resource_helper_uses_v3_only():
|
||||
"""在线资源更新器必须只请求 V3 清单、目录和站点索引文件。"""
|
||||
assert settings.VERSION_FLAG == "v3"
|
||||
|
||||
Reference in New Issue
Block a user