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

74 lines
2.0 KiB
Python

from __future__ import annotations
import pytest
from yuxi.channels.adapters.mattermost.session import (
resolve_chat_id,
resolve_chat_type,
)
from yuxi.channels.models import ChatType
class TestResolveChatId:
def test_dm_channel(self):
assert resolve_chat_id(
{"user_id": "U001", "channel_id": "abc"},
{"type": "D"},
) == "dm_U001"
def test_dm_without_user_id(self):
assert resolve_chat_id(
{"channel_id": "abc"},
{"type": "D"},
) == "dm_unknown"
def test_public_channel(self):
assert resolve_chat_id(
{"channel_id": "ch123"},
{"type": "O"},
) == "channel_ch123"
def test_private_channel(self):
assert resolve_chat_id(
{"channel_id": "ch456"},
{"type": "P"},
) == "channel_ch456"
def test_thread_message(self):
assert resolve_chat_id(
{"channel_id": "ch123", "root_id": "post1"},
{"type": "O"},
) == "channel_ch123:thread_post1"
def test_thread_priority_over_dm(self):
assert resolve_chat_id(
{"channel_id": "abc", "root_id": "post1", "user_id": "U001"},
{"type": "D"},
) == "channel_abc:thread_post1"
class TestResolveChatType:
def test_direct_message(self):
assert resolve_chat_type({}, {"type": "D"}) == ChatType.DIRECT
def test_thread(self):
assert resolve_chat_type(
{"root_id": "post1"},
{"type": "O"},
) == ChatType.THREAD
def test_thread_priority_over_dm(self):
assert resolve_chat_type(
{"root_id": "post1"},
{"type": "D"},
) == ChatType.THREAD
def test_public_channel(self):
assert resolve_chat_type({}, {"type": "O"}) == ChatType.GROUP
def test_private_channel(self):
assert resolve_chat_type({}, {"type": "P"}) == ChatType.GROUP
def test_missing_type_defaults_to_group(self):
assert resolve_chat_type({}, {}) == ChatType.GROUP