mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
refactor: use explicit system config getter
This commit is contained in:
@@ -303,7 +303,7 @@ def test_install_plugin_runtime_reloads_in_threadpool() -> None:
|
||||
|
||||
with (
|
||||
patch(
|
||||
"app.agent.tools.impl._plugin_tool_utils.SystemConfigOper",
|
||||
"app.agent.tools.impl._plugin_tool_utils.get_configured_system_config",
|
||||
return_value=config_oper,
|
||||
),
|
||||
patch(
|
||||
@@ -394,7 +394,7 @@ def test_sealed_agent_uninstall_rejects_before_persistence() -> None:
|
||||
return_value=plugin_manager,
|
||||
),
|
||||
patch(
|
||||
"app.agent.tools.impl._plugin_tool_utils.SystemConfigOper",
|
||||
"app.agent.tools.impl._plugin_tool_utils.get_configured_system_config",
|
||||
return_value=config_oper,
|
||||
) as config_provider,
|
||||
pytest.raises(PluginMutationRejectedError),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"""Agent 资源流程工具权限测试。"""
|
||||
|
||||
# pylint: disable=no-name-in-module
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
from types import SimpleNamespace
|
||||
@@ -308,7 +310,7 @@ def test_query_downloaders_hides_sensitive_fields_for_non_admin_user():
|
||||
]
|
||||
|
||||
with patch(
|
||||
"app.agent.tools.impl.query_downloaders.SystemConfigOper"
|
||||
"app.agent.tools.impl.query_downloaders.get_configured_system_config"
|
||||
) as system_config_oper:
|
||||
system_config_oper.return_value.get.return_value = downloaders
|
||||
result = asyncio.run(tool.run())
|
||||
@@ -345,7 +347,7 @@ def test_query_downloaders_keeps_full_fields_for_admin_context():
|
||||
]
|
||||
|
||||
with patch(
|
||||
"app.agent.tools.impl.query_downloaders.SystemConfigOper"
|
||||
"app.agent.tools.impl.query_downloaders.get_configured_system_config"
|
||||
) as system_config_oper:
|
||||
system_config_oper.return_value.get.return_value = downloaders
|
||||
result = asyncio.run(tool.run())
|
||||
|
||||
@@ -35,7 +35,7 @@ class TestAgentSystemSettingsTools(unittest.TestCase):
|
||||
tool = QuerySystemSettingsTool(session_id="session-1", user_id="10001")
|
||||
|
||||
with patch(
|
||||
"app.agent.tools.impl.query_system_settings.SystemConfigOper"
|
||||
"app.agent.tools.impl.query_system_settings.get_configured_system_config"
|
||||
) as system_config_oper:
|
||||
system_config_oper.return_value.get.return_value = [{"name": "qb", "enabled": True}]
|
||||
result = asyncio.run(tool.run(setting_key="Downloaders"))
|
||||
@@ -54,7 +54,7 @@ class TestAgentSystemSettingsTools(unittest.TestCase):
|
||||
tool = QuerySystemSettingsTool(session_id="session-1", user_id="10001")
|
||||
|
||||
with patch(
|
||||
"app.agent.tools.impl.query_system_settings.SystemConfigOper"
|
||||
"app.agent.tools.impl.query_system_settings.get_configured_system_config"
|
||||
) as system_config_oper:
|
||||
system_config_oper.return_value.get.return_value = [
|
||||
{
|
||||
@@ -84,7 +84,7 @@ class TestAgentSystemSettingsTools(unittest.TestCase):
|
||||
tool.set_agent_context({"is_admin": True})
|
||||
|
||||
with patch(
|
||||
"app.agent.tools.impl.query_system_settings.SystemConfigOper"
|
||||
"app.agent.tools.impl.query_system_settings.get_configured_system_config"
|
||||
) as system_config_oper:
|
||||
system_config_oper.return_value.get.return_value = [
|
||||
{"name": "site-a", "apikey": "site-api-key"}
|
||||
@@ -156,7 +156,7 @@ class TestAgentSystemSettingsTools(unittest.TestCase):
|
||||
tool = QuerySystemSettingsTool(session_id="session-1", user_id="10001")
|
||||
|
||||
with patch(
|
||||
"app.agent.tools.impl.query_system_settings.SystemConfigOper"
|
||||
"app.agent.tools.impl.query_system_settings.get_configured_system_config"
|
||||
) as system_config_oper:
|
||||
system_config_oper.return_value.get.return_value = []
|
||||
result = asyncio.run(tool.run(group="systemconfig"))
|
||||
@@ -231,7 +231,7 @@ class TestAgentSystemSettingsTools(unittest.TestCase):
|
||||
config_oper.async_set = AsyncMock(return_value=True)
|
||||
|
||||
with patch(
|
||||
"app.agent.tools.impl.update_system_settings.SystemConfigOper",
|
||||
"app.agent.tools.impl.update_system_settings.get_configured_system_config",
|
||||
return_value=config_oper,
|
||||
), patch(
|
||||
"app.agent.tools.impl.update_system_settings.eventmanager.async_send_event",
|
||||
@@ -264,7 +264,7 @@ class TestAgentSystemSettingsTools(unittest.TestCase):
|
||||
config_oper.async_set = AsyncMock(return_value=True)
|
||||
|
||||
with patch(
|
||||
"app.agent.tools.impl.update_system_settings.SystemConfigOper",
|
||||
"app.agent.tools.impl.update_system_settings.get_configured_system_config",
|
||||
return_value=config_oper,
|
||||
), patch(
|
||||
"app.agent.tools.impl.update_system_settings.eventmanager.async_send_event",
|
||||
@@ -297,7 +297,7 @@ class TestAgentSystemSettingsTools(unittest.TestCase):
|
||||
config_oper.async_set = AsyncMock(return_value=True)
|
||||
|
||||
with patch(
|
||||
"app.agent.tools.impl.update_system_settings.SystemConfigOper",
|
||||
"app.agent.tools.impl.update_system_settings.get_configured_system_config",
|
||||
return_value=config_oper,
|
||||
), patch(
|
||||
"app.agent.tools.impl.update_system_settings.eventmanager.async_send_event",
|
||||
|
||||
@@ -368,6 +368,18 @@ def test_host_code_uses_explicit_runtime_facade_getters():
|
||||
continue
|
||||
tree = ast.parse(path.read_text(encoding="utf-8-sig"), filename=str(path))
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.Assign) and isinstance(node.value, ast.Name):
|
||||
target_names = {
|
||||
target.id for target in node.targets if isinstance(target, ast.Name)
|
||||
}
|
||||
if (
|
||||
"SystemConfigOper" in target_names
|
||||
and node.value.id == "get_configured_system_config"
|
||||
):
|
||||
violations.append(
|
||||
f"{relative.as_posix()}:{node.lineno}:SystemConfigOper"
|
||||
)
|
||||
continue
|
||||
if not isinstance(node, ast.ImportFrom) or not node.module:
|
||||
continue
|
||||
forbidden_names = forbidden_imports.get(node.module, set())
|
||||
@@ -377,7 +389,16 @@ def test_host_code_uses_explicit_runtime_facade_getters():
|
||||
and alias.name == "get_plugin_manager"
|
||||
and alias.asname is not None
|
||||
)
|
||||
if alias.name in forbidden_names or class_shaped_plugin_getter:
|
||||
class_shaped_config_getter = (
|
||||
node.module == "app.application.configuration"
|
||||
and alias.name == "get_configured_system_config"
|
||||
and alias.asname is not None
|
||||
)
|
||||
if (
|
||||
alias.name in forbidden_names
|
||||
or class_shaped_plugin_getter
|
||||
or class_shaped_config_getter
|
||||
):
|
||||
imported_name = alias.asname or alias.name
|
||||
violations.append(
|
||||
f"{relative.as_posix()}:{node.lineno}:{imported_name}"
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# pylint: disable=no-name-in-module
|
||||
|
||||
import pytest
|
||||
|
||||
from app.modules.indexer.spider import haidan as haidan_module
|
||||
@@ -21,7 +23,7 @@ def _build_indexer() -> dict:
|
||||
@pytest.fixture()
|
||||
def haidan_spider(monkeypatch):
|
||||
"""构造不依赖真实数据库配置的 HaiDanSpider。"""
|
||||
monkeypatch.setattr(haidan_module, "SystemConfigOper", lambda: None)
|
||||
monkeypatch.setattr(haidan_module, "get_configured_system_config", lambda: None)
|
||||
return HaiDanSpider(_build_indexer())
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# pylint: disable=no-name-in-module
|
||||
|
||||
import pytest
|
||||
|
||||
from app.modules.indexer.spider import hddolby as hddolby_module
|
||||
@@ -21,7 +23,7 @@ def _build_indexer() -> dict:
|
||||
@pytest.fixture()
|
||||
def hddolby_spider(monkeypatch):
|
||||
"""构造不依赖真实数据库配置的 HddolbySpider。"""
|
||||
monkeypatch.setattr(hddolby_module, "SystemConfigOper", lambda: None)
|
||||
monkeypatch.setattr(hddolby_module, "get_configured_system_config", lambda: None)
|
||||
return HddolbySpider(_build_indexer())
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# pylint: disable=no-name-in-module
|
||||
|
||||
import pytest
|
||||
|
||||
from app.modules.indexer.spider import mtorrent as mtorrent_module
|
||||
@@ -21,7 +23,7 @@ def _build_indexer() -> dict:
|
||||
@pytest.fixture()
|
||||
def mteam_spider(monkeypatch):
|
||||
"""构造不依赖真实数据库配置的 MTorrentSpider。"""
|
||||
monkeypatch.setattr(mtorrent_module, "SystemConfigOper", lambda: None)
|
||||
monkeypatch.setattr(mtorrent_module, "get_configured_system_config", lambda: None)
|
||||
return MTorrentSpider(_build_indexer())
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# pylint: disable=no-name-in-module
|
||||
|
||||
import pytest
|
||||
|
||||
from app.modules.indexer.spider import rousi as rousi_module
|
||||
@@ -21,7 +23,7 @@ def _build_indexer() -> dict:
|
||||
@pytest.fixture()
|
||||
def rousi_spider(monkeypatch):
|
||||
"""构造不依赖真实数据库配置的 RousiSpider。"""
|
||||
monkeypatch.setattr(rousi_module, "SystemConfigOper", lambda: None)
|
||||
monkeypatch.setattr(rousi_module, "get_configured_system_config", lambda: None)
|
||||
return RousiSpider(_build_indexer())
|
||||
|
||||
|
||||
|
||||
@@ -1056,7 +1056,7 @@ class SubscribeChainTest(TestCase):
|
||||
|
||||
with patch.object(SUBSCRIBE_CHAIN_MODULE, "SubscribeOper", _SubscribeOper), patch.object(
|
||||
SUBSCRIBE_CHAIN_MODULE,
|
||||
"SystemConfigOper",
|
||||
"get_configured_system_config",
|
||||
_SystemConfigOper,
|
||||
), patch.object(
|
||||
SUBSCRIBE_CHAIN_MODULE,
|
||||
|
||||
Reference in New Issue
Block a user