mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-29 20:17:13 +08:00
- 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 命名边界规范
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
from unittest.mock import MagicMock, patch
|
|
|
|
from app.testing.bootstrap import ensure_optional_stub
|
|
|
|
ensure_optional_stub("psutil")
|
|
ensure_optional_stub("dateparser")
|
|
ensure_optional_stub("Pinyin2Hanzi", is_pinyin=lambda value: False)
|
|
|
|
from app.domain.context import MediaInfo
|
|
from app.modules.feishu.feishu import Feishu
|
|
from app.schemas import Message
|
|
|
|
|
|
def _build_feishu_client() -> Feishu:
|
|
"""构造不会启动真实飞书长连接的测试客户端。"""
|
|
with (
|
|
patch.object(Feishu, "_build_api_client", return_value=MagicMock()),
|
|
patch.object(Feishu, "_start_ws_client"),
|
|
):
|
|
return Feishu(
|
|
FEISHU_APP_ID="test_app_id",
|
|
FEISHU_APP_SECRET="test_app_secret",
|
|
name="feishu-test",
|
|
)
|
|
|
|
|
|
def test_send_medias_message_passes_first_available_image() -> None:
|
|
"""飞书媒体列表应将首张可用媒体图片传入通知卡片。"""
|
|
client = _build_feishu_client()
|
|
first_media = MediaInfo()
|
|
first_media.title = "无海报媒体"
|
|
second_media = MediaInfo()
|
|
second_media.title = "有海报媒体"
|
|
second_media.poster_path = "https://example.com/poster.jpg"
|
|
|
|
with patch.object(
|
|
client,
|
|
"send_notification",
|
|
return_value={"success": True},
|
|
) as send_notification:
|
|
result = client.send_medias_message(
|
|
message=Message(title="搜索结果", userid="ou_test"),
|
|
medias=[first_media, second_media],
|
|
)
|
|
|
|
assert result == {"success": True}
|
|
proxy_message = send_notification.call_args.args[0]
|
|
assert proxy_message.image == "https://example.com/poster.jpg"
|
|
assert proxy_message.text == "1. 无海报媒体\n2. 有海报媒体"
|
|
assert send_notification.call_args.kwargs["userid"] == "ou_test"
|