feat: refactor ZSpace media server integration and enhance item management methods

This commit is contained in:
jxxghp
2026-05-11 18:21:21 +08:00
parent 6db1dd2067
commit ed9116d81e
3 changed files with 940 additions and 94 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -160,9 +160,9 @@ class MediaServerTvStaleItemIdTest(unittest.TestCase):
client._apikey = "api-key"
client.user = "user-id"
client.get_iteminfo = Mock(side_effect=[None, SimpleNamespace(tmdbid=12345)])
client._Emby__get_emby_series_id_by_name = Mock(return_value="new-series-id")
client._ZSpace__get_emby_series_id_by_name = Mock(return_value="new-series-id")
with patch("app.modules.emby.emby.RequestUtils") as request_utils_cls:
with patch("app.modules.zspace.zspace.RequestUtils") as request_utils_cls:
request_utils_cls.return_value.get_res.return_value = _FakeResponse({
"Items": [{"ParentIndexNumber": 1, "IndexNumber": 1}]
})
@@ -176,7 +176,7 @@ class MediaServerTvStaleItemIdTest(unittest.TestCase):
self.assertEqual(item_id, "new-series-id")
self.assertEqual(episodes, {1: [1]})
client._Emby__get_emby_series_id_by_name.assert_called_once_with("测试剧集", "2026")
client._ZSpace__get_emby_series_id_by_name.assert_called_once_with("测试剧集", "2026")
def test_ugreen_tv_episodes_fallback_when_cached_item_id_missing(self):
"""绿联缓存ID失效时应重新搜索剧集ID后再查询集信息。"""

View File

@@ -14,20 +14,17 @@ class _FakeResponse:
class ZSpaceMediaServerTest(unittest.TestCase):
def test_reconnect_uses_username_password_login(self):
login_request_utils = Mock()
login_request_utils.post_res.return_value = _FakeResponse({
request_utils = Mock()
request_utils.post_res.return_value = _FakeResponse({
"AccessToken": "zspace-token",
"User": {"Id": "user-id"},
})
emby_request_utils = Mock()
emby_request_utils.get_res.side_effect = [
request_utils.get_res.side_effect = [
_FakeResponse([]),
_FakeResponse({"Id": "server-id"}),
]
with patch("app.modules.zspace.zspace.RequestUtils", return_value=login_request_utils), patch(
"app.modules.emby.emby.RequestUtils", return_value=emby_request_utils
):
with patch("app.modules.zspace.zspace.RequestUtils", return_value=request_utils):
client = ZSpace(
host="http://zspace.local",
username="admin",
@@ -40,11 +37,14 @@ class ZSpaceMediaServerTest(unittest.TestCase):
def test_get_user_falls_back_to_current_login_user(self):
client = ZSpace.__new__(ZSpace)
client._host = "http://zspace.local/"
client._apikey = "zspace-token"
client._username = "admin"
client.user = "current-user-id"
client._ZSpace__get_current_user = Mock(return_value={"Id": "current-user-id", "Name": "admin"})
with patch("app.modules.emby.emby.Emby.get_user", return_value=None):
with patch("app.modules.zspace.zspace.RequestUtils") as request_utils_cls:
request_utils_cls.return_value.get_res.return_value = _FakeResponse({"invalid": True})
user_id = client.get_user("admin")
self.assertEqual(user_id, "current-user-id")