ForcePilot/backend/test/unit/channels/plugins/qqbot/conftest.py

53 lines
2.1 KiB
Python
Raw Normal View History

"""channels plugins/qqbot 层单元测试共享 fixture。
提供 ``fake_qqbot_client`` 模拟 ``QQBotClient``
``yuxi.channels.plugins.qqbot.qqbot_client.QQBotClient``
QQ Bot 适配器测试通过此桩注入客户端依赖不发起真实 HTTP 请求
桩使用 ``AsyncMock()``预设主要方法返回值 dict / token 元组 /
gateway URL调用方可按需覆盖方法签名以 ``QQBotClient`` 实现为准
单文件独有的 helper 应保留在对应测试文件内 testing-guidelines.md
"""
from __future__ import annotations
from unittest.mock import AsyncMock
import pytest
@pytest.fixture
def fake_qqbot_client() -> AsyncMock:
"""QQBotClient 桩。
``AsyncMock()`` 模拟 ``QQBotClient``预设主要方法返回值
- ``get_app_access_token`` 返回 ``("fake-token", 7200)``
- ``get_gateway`` 返回 ``"wss://gateway.qq.com"``
- ``send_c2c_message`` / ``send_group_message`` 返回 ``{"msg_id": "..."}``
- ``recall_c2c_message`` / ``recall_group_message`` 返回 ``{}``
- ``upload_c2c_file`` / ``upload_group_file`` 返回 ``{"file_info": "..."}``
- ``ack_interaction`` / ``get_user`` 返回 ``{}``
"""
client = AsyncMock()
# Token 管理
client.get_app_access_token.return_value = ("fake-token", 7200)
# Gateway
client.get_gateway.return_value = "wss://gateway.qq.com"
# 连接池注入
client.attach_http_client.return_value = None
client.detach_http_client.return_value = None
# 消息发送
client.send_c2c_message.return_value = {"msg_id": "msg-c2c-1"}
client.send_group_message.return_value = {"msg_id": "msg-group-1"}
# 消息撤回
client.recall_c2c_message.return_value = {}
client.recall_group_message.return_value = {}
# 富媒体上传
client.upload_c2c_file.return_value = {"file_info": "file-c2c-1"}
client.upload_group_file.return_value = {"file_info": "file-group-1"}
# 互动回调
client.ack_interaction.return_value = {}
# 用户查询
client.get_user.return_value = {"nickname": "user-1", "avatar": "https://x.com/a.png"}
return client