ForcePilot/backend/test/unit/channel/startup/test_feishu_adapter.py
Kris 6c95dc006a test: 新增渠道模块全链路单元测试用例与目录结构
完成渠道模块的单元测试目录搭建,新增多个领域模型、端口、中间件、事件、服务以及基础设施层的单元测试文件,同时补充了conftest.py的环境变量配置,完善测试基础环境。
2026-05-30 21:55:35 +08:00

75 lines
2.4 KiB
Python

from __future__ import annotations
from unittest.mock import AsyncMock, MagicMock
import pytest
from yuxi.channel.channels.feishu.adapter import FeishuAdapter
from yuxi.channel.domain.model.message.unified_message import UnifiedMessage
from yuxi.channel.domain.model.message.peer import Peer
from yuxi.channel.domain.model.message.dispatch_result import SendResult
class TestFeishuAdapter:
@pytest.fixture
def adapter(self):
return FeishuAdapter(config={"app_id": "test", "app_secret": "test"})
@pytest.mark.asyncio
async def test_open(self, adapter):
await adapter.open()
assert adapter.is_open is True
@pytest.mark.asyncio
async def test_close(self, adapter):
await adapter.open()
await adapter.close()
assert adapter.is_open is False
@pytest.mark.asyncio
async def test_send_message(self, adapter):
await adapter.open()
msg = UnifiedMessage(
message_id="msg123",
channel_type="feishu",
sender=Peer(id="bot", name="Bot"),
content="Hello",
)
result = await adapter.send_message("thread123", msg)
assert isinstance(result, SendResult)
@pytest.mark.asyncio
async def test_send_media(self, adapter):
await adapter.open()
result = await adapter.send_media("thread123", "http://example.com/image.png", "image")
assert isinstance(result, SendResult)
@pytest.mark.asyncio
async def test_send_typing(self, adapter):
await adapter.open()
result = await adapter.send_typing("thread123")
assert isinstance(result, SendResult)
def test_capabilities(self, adapter):
assert adapter.capabilities.text is True
assert adapter.capabilities.media is True
assert adapter.capabilities.typing is True
assert adapter.capabilities.group is True
def test_bot_id(self, adapter):
assert adapter.bot_id is None
def test_ws_connection(self, adapter):
assert adapter.ws_connection is None
@pytest.mark.asyncio
async def test_send_message_not_open(self, adapter):
msg = UnifiedMessage(
message_id="msg123",
channel_type="feishu",
sender=Peer(id="bot", name="Bot"),
content="Hello",
)
result = await adapter.send_message("thread123", msg)
assert result.success is False