Files
MoviePilot/tests/test_agent_add_subscribe_tool.py
T
jxxghp 240a4dffe6 refactor(schemas): 统一 message/notification 命名边界,旧名收敛至兼容映射表
- notification 域:渠道能力(MessageChannel→NotificationChannel、ChannelCapability* 迁入 notification.py)
- message 域:消息收发(Notification→Message、NotificationType→MessageType、CommingMessage→IncomingMessage、NotificationHistoryItem→MessageHistoryItem、NotificationClear*→MessageClear*)
- Agent 工具契约:send_notification_message→send_message、notification_callback→message_callback
- 源码不保留旧名物理别名,旧导入经 app/runtime/compat/manifest.py SYMBOL_ALIASES 惰性解析
- API 路径与持久化键冻结不变,前端零改动
- 新增兼容守护测试与 docs/rules/07 命名边界规范
2026-08-16 19:32:20 +08:00

97 lines
3.6 KiB
Python

import asyncio
import unittest
from unittest.mock import AsyncMock, patch
from app.agent.tools.impl.add_subscribe import AddSubscribeTool
from app.schemas.types import NotificationChannel
class TestAgentAddSubscribeTool(unittest.TestCase):
def test_tool_message_displays_special_season_zero(self):
"""Agent 提示必须把显式季 0 显示为特别季,而不是默认第一季。"""
tool = AddSubscribeTool(session_id="session-1", user_id="10001")
message = tool.get_tool_message(title="测试剧", media_type="tv", season=0)
self.assertIn("第0季", message)
self.assertNotIn("第1季(默认)", message)
def test_tv_subscription_without_season_reports_default_first_season(self):
tool = AddSubscribeTool(session_id="session-1", user_id="10001")
tool.set_message_attr(
channel=NotificationChannel.Telegram.value,
source="telegram-main",
username="tg_display_name",
)
with patch(
"app.agent.tools.impl.add_subscribe.SubscribeChain.async_add",
new=AsyncMock(return_value=(1, "")),
) as async_add, patch(
"app.agent.tools.impl.add_subscribe.UserOper.get_name",
return_value="moviepilot-user",
):
result = asyncio.run(
tool.run(
title="Breaking Bad",
year="2008",
media_type="tv",
)
)
self.assertEqual(async_add.await_args.kwargs["username"], "moviepilot-user")
self.assertIn("第1季", result)
self.assertIn("默认按第一季订阅", result)
def test_subscription_falls_back_to_channel_username_when_no_binding_exists(self):
tool = AddSubscribeTool(session_id="session-1", user_id="10001")
tool.set_message_attr(
channel=NotificationChannel.Telegram.value,
source="telegram-main",
username="tg_display_name",
)
with patch(
"app.agent.tools.impl.add_subscribe.SubscribeChain.async_add",
new=AsyncMock(return_value=(1, "")),
) as async_add, patch(
"app.agent.tools.impl.add_subscribe.UserOper.get_name",
return_value=None,
):
result = asyncio.run(
tool.run(
title="The Matrix",
year="1999",
media_type="movie",
)
)
self.assertEqual(async_add.await_args.kwargs["username"], "tg_display_name")
self.assertIn("成功添加订阅:The Matrix (1999)", result)
def test_feishu_subscription_uses_pre_resolved_username_when_openid_lookup_misses(self):
tool = AddSubscribeTool(session_id="session-1", user_id="ou_feishu_user")
tool.set_message_attr(
channel=NotificationChannel.Feishu.value,
source="feishu-main",
username="moviepilot-user",
)
with patch(
"app.agent.tools.impl.add_subscribe.SubscribeChain.async_add",
new=AsyncMock(return_value=(1, "")),
) as async_add, patch(
"app.agent.tools.impl.add_subscribe.UserOper.get_name",
return_value=None,
):
result = asyncio.run(
tool.run(
title="The Matrix",
year="1999",
media_type="movie",
)
)
self.assertEqual(async_add.await_args.kwargs["username"], "moviepilot-user")
self.assertIn("成功添加订阅:The Matrix (1999)", result)