Apply suggestions from code review

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
奕凡
2026-05-01 18:39:01 +08:00
committed by jxxghp
parent bcf8116172
commit 76c5f54465
2 changed files with 22 additions and 3 deletions

View File

@@ -243,7 +243,12 @@ class Jellyfin:
best_admin_id = user.get("Id")
best_admin_name = user.get("Name")
best_admin_library_count = current_count
if best_admin_id:
if best_admin_id is None:
logger.warning("未找到可用的管理员账号无法获取管理员用户请检查Jellyfin用户及权限配置")
return None
logger.warning(
f"未找到具备全库访问权限的管理员账号,回退使用仅可访问{best_admin_library_count}/{total_library_count}个媒体库的管理员账号{best_admin_name}"
)
logger.warning(f"未找到具备全库访问权限的管理员账号,回退使用仅可访问{best_admin_library_count}/{total_library_count}个媒体库的管理员账号{best_admin_name}")
return best_admin_id
else:

View File

@@ -179,8 +179,22 @@ class JellyfinUserResolutionTest(unittest.TestCase):
user_id = client.get_user("admin")
self.assertEqual(user_id, "large-admin-id")
warning_mock.assert_called_once()
self.assertIn("默认超级管理员状态流失", warning_mock.call_args.args[0])
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)
]
self.assertTrue(any("超级管理员" in message for message in warning_messages))
self.assertTrue(
any(
("部分" in message)
or ("可见" in message)
or ("访问范围" in message)
or ("EnabledFolders" in message)
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()