mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-07 16:36:53 +08:00
chore: remove unused imports and fix function name conflicts (#5764)
- Remove unused imports in anthropic.py, tmdbv3api/__init__.py, tv.py, test files - Rename conflicting function names in subscribe.py and webhook.py - Clean up unused re-exports in tmdbv3api/__init__.py (15 unused exports) - Apply consistent formatting across API endpoints
This commit is contained in:
+51
-18
@@ -3,7 +3,7 @@ import sys
|
||||
import types
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import call, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
def _load_jellyfin_module():
|
||||
@@ -58,8 +58,12 @@ def _load_jellyfin_module():
|
||||
return urljoin(host, path)
|
||||
|
||||
log_module.logger = _Logger()
|
||||
config_module.settings = types.SimpleNamespace(SUPERUSER="admin", USER_AGENT="MoviePilot")
|
||||
schemas_module.MediaType = types.SimpleNamespace(MOVIE=types.SimpleNamespace(value="movie"))
|
||||
config_module.settings = types.SimpleNamespace(
|
||||
SUPERUSER="admin", USER_AGENT="MoviePilot"
|
||||
)
|
||||
schemas_module.MediaType = types.SimpleNamespace(
|
||||
MOVIE=types.SimpleNamespace(value="movie")
|
||||
)
|
||||
schemas_module.MediaServerItem = object
|
||||
schemas_module.MediaServerLibrary = object
|
||||
schemas_module.Statistic = object
|
||||
@@ -90,7 +94,13 @@ def _load_jellyfin_module():
|
||||
for stub_module in stub_modules.values():
|
||||
stub_module._jellyfin_test_stub = True
|
||||
|
||||
jellyfin_path = Path(__file__).resolve().parents[1] / "app" / "modules" / "jellyfin" / "jellyfin.py"
|
||||
jellyfin_path = (
|
||||
Path(__file__).resolve().parents[1]
|
||||
/ "app"
|
||||
/ "modules"
|
||||
/ "jellyfin"
|
||||
/ "jellyfin.py"
|
||||
)
|
||||
spec = importlib.util.spec_from_file_location(module_name, jellyfin_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec and spec.loader
|
||||
@@ -114,9 +124,15 @@ class _FakeResponse:
|
||||
class JellyfinUserResolutionTest(unittest.TestCase):
|
||||
def test_loader_does_not_leave_stub_modules_in_sys_modules(self):
|
||||
self.assertNotIn("_test_jellyfin_module", sys.modules)
|
||||
self.assertFalse(getattr(sys.modules.get("app.log"), "_jellyfin_test_stub", False))
|
||||
self.assertFalse(getattr(sys.modules.get("app.core.config"), "_jellyfin_test_stub", False))
|
||||
self.assertFalse(getattr(sys.modules.get("app.utils.http"), "_jellyfin_test_stub", False))
|
||||
self.assertFalse(
|
||||
getattr(sys.modules.get("app.log"), "_jellyfin_test_stub", False)
|
||||
)
|
||||
self.assertFalse(
|
||||
getattr(sys.modules.get("app.core.config"), "_jellyfin_test_stub", False)
|
||||
)
|
||||
self.assertFalse(
|
||||
getattr(sys.modules.get("app.utils.http"), "_jellyfin_test_stub", False)
|
||||
)
|
||||
|
||||
def _build_client(self) -> Jellyfin:
|
||||
client = Jellyfin.__new__(Jellyfin)
|
||||
@@ -134,9 +150,10 @@ class JellyfinUserResolutionTest(unittest.TestCase):
|
||||
{"Id": "alice-id", "Name": "alice", "Policy": {"IsAdministrator": False}},
|
||||
]
|
||||
|
||||
with patch.object(jellyfin_module, "RequestUtils") as request_utils_cls, patch.object(
|
||||
jellyfin_module.logger, "warning"
|
||||
) as warning_mock:
|
||||
with (
|
||||
patch.object(jellyfin_module, "RequestUtils") as request_utils_cls,
|
||||
patch.object(jellyfin_module.logger, "warning") as warning_mock,
|
||||
):
|
||||
request_utils_cls.return_value.get_res.return_value = _FakeResponse(payload)
|
||||
|
||||
user_id = client.get_user("alice")
|
||||
@@ -150,7 +167,10 @@ class JellyfinUserResolutionTest(unittest.TestCase):
|
||||
{
|
||||
"Id": "visible-admin-id",
|
||||
"Name": "visible",
|
||||
"Policy": {"IsAdministrator": True, "EnabledFolders": ["lib-1", "lib-2", "lib-3"]},
|
||||
"Policy": {
|
||||
"IsAdministrator": True,
|
||||
"EnabledFolders": ["lib-1", "lib-2", "lib-3"],
|
||||
},
|
||||
},
|
||||
{
|
||||
"Id": "full-admin-id",
|
||||
@@ -177,14 +197,18 @@ class JellyfinUserResolutionTest(unittest.TestCase):
|
||||
{
|
||||
"Id": "large-admin-id",
|
||||
"Name": "large",
|
||||
"Policy": {"IsAdministrator": True, "EnabledFolders": ["lib-1", "lib-2", "lib-3"]},
|
||||
"Policy": {
|
||||
"IsAdministrator": True,
|
||||
"EnabledFolders": ["lib-1", "lib-2", "lib-3"],
|
||||
},
|
||||
},
|
||||
{"Id": "user-id", "Name": "normal", "Policy": {"IsAdministrator": False}},
|
||||
]
|
||||
|
||||
with patch.object(jellyfin_module, "RequestUtils") as request_utils_cls, patch.object(
|
||||
jellyfin_module.logger, "warning"
|
||||
) as warning_mock:
|
||||
with (
|
||||
patch.object(jellyfin_module, "RequestUtils") as request_utils_cls,
|
||||
patch.object(jellyfin_module.logger, "warning") as warning_mock,
|
||||
):
|
||||
request_utils_cls.return_value.get_res.return_value = _FakeResponse(payload)
|
||||
|
||||
user_id = client.get_user("admin")
|
||||
@@ -193,7 +217,9 @@ class JellyfinUserResolutionTest(unittest.TestCase):
|
||||
self.assertGreaterEqual(warning_mock.call_count, 2)
|
||||
|
||||
warning_messages = [
|
||||
call.args[0] for call in warning_mock.call_args_list if call.args and isinstance(call.args[0], str)
|
||||
call.args[0]
|
||||
for call in warning_mock.call_args_list
|
||||
if call.args and isinstance(call.args[0], str)
|
||||
]
|
||||
self.assertTrue(any("超级管理员" in message for message in warning_messages))
|
||||
self.assertTrue(
|
||||
@@ -205,7 +231,12 @@ class JellyfinUserResolutionTest(unittest.TestCase):
|
||||
for message in warning_messages
|
||||
)
|
||||
)
|
||||
self.assertTrue(any(("回退" in message) or ("fallback" in message.lower()) for message in warning_messages))
|
||||
self.assertTrue(
|
||||
any(
|
||||
("回退" in message) or ("fallback" in message.lower())
|
||||
for message in warning_messages
|
||||
)
|
||||
)
|
||||
|
||||
def test_get_jellyfin_librarys_returns_empty_when_user_missing(self):
|
||||
client = self._build_client()
|
||||
@@ -223,7 +254,9 @@ class JellyfinUserResolutionTest(unittest.TestCase):
|
||||
client.user = "user-id"
|
||||
|
||||
with patch.object(jellyfin_module, "RequestUtils") as request_utils_cls:
|
||||
request_utils_cls.return_value.get_res.return_value = _FakeResponse({"Items": []})
|
||||
request_utils_cls.return_value.get_res.return_value = _FakeResponse(
|
||||
{"Items": []}
|
||||
)
|
||||
|
||||
libraries = client._Jellyfin__get_jellyfin_librarys()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user