mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
test: 测试套件自隔离与全量离线化(collection 清零 + 杜绝真实网络) (#5873)
This commit is contained in:
+2
-113
@@ -1,116 +1,9 @@
|
||||
import importlib.util
|
||||
import sys
|
||||
import types
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
def _load_jellyfin_module():
|
||||
module_name = "_test_jellyfin_module"
|
||||
app_module = types.ModuleType("app")
|
||||
core_module = types.ModuleType("app.core")
|
||||
utils_module = types.ModuleType("app.utils")
|
||||
log_module = types.ModuleType("app.log")
|
||||
config_module = types.ModuleType("app.core.config")
|
||||
schemas_module = types.ModuleType("app.schemas")
|
||||
http_module = types.ModuleType("app.utils.http")
|
||||
url_module = types.ModuleType("app.utils.url")
|
||||
|
||||
class _Logger:
|
||||
def info(self, *_args, **_kwargs):
|
||||
pass
|
||||
|
||||
def warning(self, *_args, **_kwargs):
|
||||
pass
|
||||
|
||||
def error(self, *_args, **_kwargs):
|
||||
pass
|
||||
|
||||
def debug(self, *_args, **_kwargs):
|
||||
pass
|
||||
|
||||
class _RequestUtils:
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def get_res(self, *args, **kwargs):
|
||||
return None
|
||||
|
||||
class _UrlUtils:
|
||||
@staticmethod
|
||||
def standardize_base_url(host):
|
||||
if not host:
|
||||
return host
|
||||
if not host.endswith("/"):
|
||||
host += "/"
|
||||
if not host.startswith("http://") and not host.startswith("https://"):
|
||||
host = "http://" + host
|
||||
return host
|
||||
|
||||
@staticmethod
|
||||
def combine_url(host, path=None, query=None):
|
||||
from urllib.parse import urljoin
|
||||
|
||||
if path is None:
|
||||
path = "/"
|
||||
host = _UrlUtils.standardize_base_url(host)
|
||||
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")
|
||||
)
|
||||
schemas_module.MediaServerItem = object
|
||||
schemas_module.MediaServerLibrary = object
|
||||
schemas_module.Statistic = object
|
||||
schemas_module.WebhookEventInfo = object
|
||||
schemas_module.MediaServerItemUserState = object
|
||||
schemas_module.MediaServerPlayItem = object
|
||||
http_module.RequestUtils = _RequestUtils
|
||||
url_module.UrlUtils = _UrlUtils
|
||||
|
||||
app_module.schemas = schemas_module
|
||||
app_module.log = log_module
|
||||
app_module.core = core_module
|
||||
app_module.utils = utils_module
|
||||
core_module.config = config_module
|
||||
utils_module.http = http_module
|
||||
utils_module.url = url_module
|
||||
|
||||
stub_modules = {
|
||||
"app": app_module,
|
||||
"app.log": log_module,
|
||||
"app.core": core_module,
|
||||
"app.core.config": config_module,
|
||||
"app.schemas": schemas_module,
|
||||
"app.utils": utils_module,
|
||||
"app.utils.http": http_module,
|
||||
"app.utils.url": url_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"
|
||||
)
|
||||
spec = importlib.util.spec_from_file_location(module_name, jellyfin_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec and spec.loader
|
||||
with patch.dict(sys.modules, stub_modules):
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
jellyfin_module = _load_jellyfin_module()
|
||||
Jellyfin = jellyfin_module.Jellyfin
|
||||
from app.modules.jellyfin import jellyfin as jellyfin_module
|
||||
from app.modules.jellyfin.jellyfin import Jellyfin
|
||||
|
||||
|
||||
class _FakeResponse:
|
||||
@@ -265,7 +158,3 @@ class JellyfinUserResolutionTest(unittest.TestCase):
|
||||
"http://jellyfin.local:8096/Users/user-id/Views",
|
||||
{"api_key": "api-key"},
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user