mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
refactor: unify download chain data ports
This commit is contained in:
@@ -501,6 +501,27 @@ def test_mediaserver_chain_uses_explicit_data_port_getter():
|
||||
assert violations == []
|
||||
|
||||
|
||||
def test_download_chain_uses_explicit_data_port_getters():
|
||||
"""下载链不得把三个迁移期 PortProxy 伪装成数据库 Oper。"""
|
||||
path = APP_ROOT / "chain" / "download.py"
|
||||
tree = ast.parse(path.read_text(encoding="utf-8-sig"), filename=str(path))
|
||||
forbidden = {
|
||||
"DownloadFailurePortProxy",
|
||||
"DownloadHistoryPortProxy",
|
||||
"MediaServerPortProxy",
|
||||
}
|
||||
violations = [
|
||||
f"{path.relative_to(PROJECT_ROOT).as_posix()}:{node.lineno}:{alias.name}"
|
||||
for node in ast.walk(tree)
|
||||
if isinstance(node, ast.ImportFrom)
|
||||
and node.module == "app.application.chain.data"
|
||||
for alias in node.names
|
||||
if alias.name in forbidden
|
||||
]
|
||||
|
||||
assert violations == []
|
||||
|
||||
|
||||
def test_plugin_components_do_not_reexport_legacy_abi_names():
|
||||
"""新插件组件只提供 canonical 能力,不得复制旧 Helper、Manager 或 Oper 导出。"""
|
||||
violations: list[str] = []
|
||||
|
||||
@@ -142,7 +142,11 @@ def test_download_single_submits_download_added_to_background(monkeypatch):
|
||||
lambda _self: _download_dirs(),
|
||||
)
|
||||
monkeypatch.setattr(download_module, "ThreadHelper", _FakeThreadHelper)
|
||||
monkeypatch.setattr(download_module, "DownloadHistoryOper", _FakeDownloadHistoryOper)
|
||||
monkeypatch.setattr(
|
||||
download_module,
|
||||
"get_chain_download_history_port",
|
||||
_FakeDownloadHistoryOper,
|
||||
)
|
||||
monkeypatch.setattr(download_module, "TorrentHelper", _FakeTorrentHelper)
|
||||
|
||||
chain = DownloadChain.__new__(DownloadChain)
|
||||
@@ -268,7 +272,11 @@ def test_download_single_persists_custom_words_snapshot(monkeypatch):
|
||||
lambda _self: _download_dirs(),
|
||||
)
|
||||
monkeypatch.setattr(download_module, "ThreadHelper", _FakeThreadHelper)
|
||||
monkeypatch.setattr(download_module, "DownloadHistoryOper", _CapturingDownloadHistoryOper)
|
||||
monkeypatch.setattr(
|
||||
download_module,
|
||||
"get_chain_download_history_port",
|
||||
_CapturingDownloadHistoryOper,
|
||||
)
|
||||
monkeypatch.setattr(download_module, "TorrentHelper", _FakeTorrentHelper)
|
||||
|
||||
chain = DownloadChain.__new__(DownloadChain)
|
||||
@@ -791,7 +799,11 @@ def test_download_single_records_failure_cooldown_when_downloader_rejects(monkey
|
||||
lambda _self: _download_dirs(),
|
||||
)
|
||||
monkeypatch.setattr(download_module, "TorrentHelper", _FakeTorrentHelper)
|
||||
monkeypatch.setattr(download_module, "DownloadFailureOper", _CapturingDownloadFailureOper)
|
||||
monkeypatch.setattr(
|
||||
download_module,
|
||||
"get_chain_download_failure_port",
|
||||
_CapturingDownloadFailureOper,
|
||||
)
|
||||
monkeypatch.setattr(download_module.eventmanager, "send_event", lambda *args, **kwargs: None)
|
||||
|
||||
chain = DownloadChain.__new__(DownloadChain)
|
||||
@@ -924,7 +936,11 @@ def test_batch_download_skips_failed_subscription_resource_and_tries_next(monkey
|
||||
next_retry_at="2026-01-02 03:04:05",
|
||||
)}
|
||||
|
||||
monkeypatch.setattr(download_module, "DownloadFailureOper", _ActiveDownloadFailureOper)
|
||||
monkeypatch.setattr(
|
||||
download_module,
|
||||
"get_chain_download_failure_port",
|
||||
_ActiveDownloadFailureOper,
|
||||
)
|
||||
|
||||
chain = DownloadChain.__new__(DownloadChain)
|
||||
chain.download_single = MagicMock(return_value="hash")
|
||||
@@ -1157,7 +1173,7 @@ def test_downloading_includes_media_type_and_source_site(monkeypatch):
|
||||
monkeypatch.setattr(chain, "list_torrents", lambda **_kwargs: [torrent])
|
||||
monkeypatch.setattr(
|
||||
download_module,
|
||||
"DownloadHistoryOper",
|
||||
"get_chain_download_history_port",
|
||||
lambda: SimpleNamespace(get_by_hashes=lambda _hashes: {torrent.hash: history}),
|
||||
)
|
||||
|
||||
|
||||
@@ -217,7 +217,10 @@ def test_music_library_exists_uses_atomic_album_lookup():
|
||||
mediaserver = Mock()
|
||||
mediaserver.get_item_id.return_value = "album-item-1"
|
||||
|
||||
with patch("app.chain.download.MediaServerOper", return_value=mediaserver):
|
||||
with patch(
|
||||
"app.chain.download.get_chain_media_server_port",
|
||||
return_value=mediaserver,
|
||||
):
|
||||
exists, no_exists = chain.get_no_exists_info(
|
||||
meta=MetaMusic.from_music_info(album),
|
||||
mediainfo=album,
|
||||
|
||||
Reference in New Issue
Block a user