1. 移除Telegram格式化测试中未使用的导入项 2. 修复Teams测试用例,添加monkeypatch参数并配置通配符开关 3. 更新钉钉适配器测试,替换弃用的流属性检查 4. 修正Twitch规范化测试,更新ROOMSTATE测试逻辑 5. 重构会话映射测试,完善数据库执行结果模拟 6. 格式化Slack块构建测试的长参数调用 7. 修复LINE适配器测试,更新能力断言和异步锁使用 8. 修正Slack会话解析测试,修复聊天类型判断错误 9. 更新能力测试,补充缺失的字段检查 10. 修复Matrix适配器测试,修正位置参数和配置校验逻辑 11. 为飞书分析模块测试添加跳过标记 12. 新增微信能力、限流、链接格式、会话路由等模块的单元测试 13. 修复Twitch适配器导入路径和测试断言 14. 新增Discord Webhook、Nextcloud Talk、Signal多账户等模块的单元测试 15. 修复Manager阶段测试的导入路径 16. 新增iMessage异常和命令处理的单元测试 17. 新增Nostr健康检查和相关模块的单元测试 18. 新增Signal守护进程和SSE重连相关测试
66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
import pytest
|
|
|
|
from yuxi.channels.adapters.wechat.wecom.monitor import WeComMonitor
|
|
|
|
|
|
class TestWeComMonitor:
|
|
def setup_method(self):
|
|
self.http_client = AsyncMock()
|
|
self.config = {"heartbeat_interval": 0.2}
|
|
self.message_handler = AsyncMock()
|
|
self.monitor = WeComMonitor(self.http_client, self.config, self.message_handler)
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_start_creates_heartbeat_task(self):
|
|
token_refresh = AsyncMock()
|
|
await self.monitor.start(token_refresh)
|
|
assert self.monitor._running is True
|
|
assert self.monitor._heartbeat_task is not None
|
|
await self.monitor.stop()
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_stop_cancels_task(self):
|
|
token_refresh = AsyncMock()
|
|
await self.monitor.start(token_refresh)
|
|
await self.monitor.stop()
|
|
assert self.monitor._running is False
|
|
assert self.monitor._heartbeat_task is None
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_heartbeat_calls_token_refresh(self):
|
|
token_refresh = AsyncMock()
|
|
await self.monitor.start(token_refresh)
|
|
await asyncio.sleep(0.4)
|
|
await self.monitor.stop()
|
|
assert token_refresh.call_count >= 1
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_heartbeat_error_does_not_crash(self):
|
|
token_refresh = AsyncMock(side_effect=RuntimeError("refresh error"))
|
|
await self.monitor.start(token_refresh)
|
|
await asyncio.sleep(0.4)
|
|
await self.monitor.stop()
|
|
assert self.monitor._running is False
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_double_stop_no_error(self):
|
|
token_refresh = AsyncMock()
|
|
await self.monitor.start(token_refresh)
|
|
await self.monitor.stop()
|
|
await self.monitor.stop()
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_stop_when_not_running(self):
|
|
await self.monitor.stop()
|
|
|
|
def test_process_webhook_message(self):
|
|
normalize_func = MagicMock(return_value="normalized_message")
|
|
raw = {"Content": "hello"}
|
|
result = self.monitor.process_webhook_message(raw, normalize_func)
|
|
normalize_func.assert_called_once_with(raw)
|
|
assert result == "normalized_message" |