ForcePilot/backend/test/unit/channels/test_heartbeat.py
Kris 3264900bc9 test: 新增多渠道单元测试用例并配置测试环境变量
新增了Twitch、Telegram、Discord、Slack、Mattermost、WeChat、Zalo等多渠道的单元测试用例,覆盖了令牌处理、速率限制、消息去重、会话解析、格式转换、安全策略等模块
同时在测试配置中添加了测试用的OpenAI API密钥环境变量
2026-05-12 00:56:47 +08:00

41 lines
1.1 KiB
Python

from __future__ import annotations
import pytest
from yuxi.channels.policy.heartbeat import BaseHeartbeatAdapter
def _make_demo():
class DemoHeartbeat(BaseHeartbeatAdapter):
async def check_ready(self):
return True
async def send_typing(self, chat_id: str):
pass
async def clear_typing(self, chat_id: str):
pass
return DemoHeartbeat()
class TestBaseHeartbeatAdapter:
def test_cannot_instantiate_abstract(self):
with pytest.raises(TypeError):
BaseHeartbeatAdapter()
def test_can_instantiate_concrete_impl(self):
instance = _make_demo()
assert isinstance(instance, BaseHeartbeatAdapter)
@pytest.mark.asyncio
async def test_resolve_recipients_default(self):
instance = _make_demo()
result = await instance.resolve_recipients("chat-123")
assert result == ["chat-123"]
@pytest.mark.asyncio
async def test_on_unhealthy_noop(self):
instance = _make_demo()
result = await instance.on_unhealthy("chat-123")
assert result is None