ForcePilot/backend/test/unit/channels/plugins/wechat_ilink/conftest.py
Kris 1022121bee test: add batch of unit tests for channels module
添加了channels限界上下文的大量单元测试文件,包括:
1. 各层级通用与专用的conftest夹具
2. 核心领域模型、事件、服务测试
3. 应用层流水线、扩展处理器测试
4. 适配器与插件层测试
5. 修复并补充了pool manager测试用例
2026-07-02 03:28:19 +08:00

95 lines
3.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""channels plugins/wechat_ilink 层单元测试共享 fixture。
提供 ``fake_ilink_client`` 桩,模拟 ``ILinkClient``
``yuxi.channels.plugins.wechat_ilink.ilink_client.ILinkClient``)。
微信 iLink 适配器测试通过此桩注入客户端依赖,不发起真实 HTTP 请求。
桩使用 ``AsyncMock()``,预设主要方法返回值(消息列表 / client_id /
二维码 / 凭证字典 / 空字节等),调用方可按需覆盖。方法签名以
``ILinkClient`` 实现为准。单文件独有的 helper 应保留在对应测试文件内
(见 testing-guidelines.md
"""
from __future__ import annotations
from unittest.mock import AsyncMock
import pytest
@pytest.fixture
def fake_ilink_client() -> AsyncMock:
"""ILinkClient 桩。
``AsyncMock()`` 模拟 ``ILinkClient``,预设主要方法返回值:
- ``get_updates`` 返回 ``{"msgs": [], "get_updates_buf": "fake-cursor"}``
- ``send_message`` 返回 ``{"client_id": "fake-client-id"}``
- ``get_bot_qrcode`` 返回 ``{"qrcode_img_content": "", "qrcode": "fake-qrcode"}``
- ``get_qrcode_status`` 返回 ``{"status": "CONFIRM"}``
- ``getconfig`` 返回 ``{}``
- ``getuploadurl`` 返回含 upload_url / encrypt_query_param / aes_key /
file_id 的字典;
- ``cdn_upload`` 返回 ``None``
- ``cdn_download`` 返回 ``b""``
- ``get_credentials`` 返回含 bot_token / ilink_bot_id / ilink_user_id /
baseurl 的字典;
- ``get_context_token`` / ``get_qr_token`` 返回 ``None``
- ``get_cursor`` 返回 ``""``
- ``set_xxx`` / ``clear_xxx`` 返回 ``None``。
"""
client = AsyncMock()
# 配置读取
client.get_channel_config.return_value = None
# 长轮询
client.get_updates.return_value = {
"msgs": [],
"get_updates_buf": "fake-cursor",
}
# 消息发送
client.send_message.return_value = {"client_id": "fake-client-id"}
# 二维码登录
client.get_bot_qrcode.return_value = {
"qrcode_img_content": "",
"qrcode": "fake-qrcode",
}
client.get_qrcode_status.return_value = {
"status": "CONFIRM",
"redirect_host": None,
"bot_token": "fake-bot-token",
"ilink_bot_id": "fake-bot-id",
"ilink_user_id": "fake-user-id",
"baseurl": "https://ilinkai.weixin.qq.com",
}
# 健康探活
client.getconfig.return_value = {}
# CDN 上传/下载
client.getuploadurl.return_value = {
"upload_url": "https://fake-cdn.example.com/upload",
"encrypt_query_param": "fake-encrypt-param",
"aes_key": "fake-aes-key",
"file_id": "fake-file-id",
}
client.cdn_upload.return_value = None
client.cdn_download.return_value = b""
# 凭证缓存
client.get_credentials.return_value = {
"bot_token": "fake-bot-token",
"ilink_bot_id": "fake-bot-id",
"ilink_user_id": "fake-user-id",
"baseurl": "https://ilinkai.weixin.qq.com",
}
client.set_credentials.return_value = None
client.clear_credentials.return_value = None
# context_token 缓存
client.get_context_token.return_value = None
client.set_context_token.return_value = None
client.clear_context_token.return_value = None
# qr_token 缓存
client.get_qr_token.return_value = None
client.set_qr_token.return_value = None
client.clear_qr_token.return_value = None
# cursor 缓存
client.get_cursor.return_value = ""
client.set_cursor.return_value = None
return client