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重连相关测试
139 lines
3.9 KiB
Python
139 lines
3.9 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from yuxi.channels.models import (
|
|
FetchOptions,
|
|
HistoricalMessage,
|
|
SessionScope,
|
|
ThreadContext,
|
|
ThreadType,
|
|
)
|
|
|
|
|
|
class TestThreadType:
|
|
def test_native(self):
|
|
assert ThreadType.NATIVE == "native"
|
|
|
|
def test_topic(self):
|
|
assert ThreadType.TOPIC == "topic"
|
|
|
|
def test_simulated(self):
|
|
assert ThreadType.SIMULATED == "simulated"
|
|
|
|
def test_all_values_strings(self):
|
|
for member in ThreadType:
|
|
assert isinstance(member.value, str)
|
|
|
|
|
|
class TestSessionScope:
|
|
def test_direct(self):
|
|
assert SessionScope.DIRECT == "dm"
|
|
|
|
def test_group(self):
|
|
assert SessionScope.GROUP == "group"
|
|
|
|
def test_thread(self):
|
|
assert SessionScope.THREAD == "thread"
|
|
|
|
def test_all_values_strings(self):
|
|
for member in SessionScope:
|
|
assert isinstance(member.value, str)
|
|
|
|
|
|
class TestThreadContext:
|
|
def test_minimal(self):
|
|
ctx = ThreadContext(thread_id="t1")
|
|
assert ctx.thread_id == "t1"
|
|
assert ctx.thread_type == ThreadType.DIRECT
|
|
assert ctx.parent_id is None
|
|
assert ctx.participants == []
|
|
assert ctx.metadata == {}
|
|
|
|
def test_full(self):
|
|
ctx = ThreadContext(
|
|
thread_id="t2",
|
|
thread_type=ThreadType.NATIVE,
|
|
parent_id="p1",
|
|
root_message_id="root_1",
|
|
participants=["u1", "u2"],
|
|
created_at=datetime.now(),
|
|
metadata={"key": "val"},
|
|
)
|
|
assert ctx.thread_type == ThreadType.NATIVE
|
|
assert len(ctx.participants) == 2
|
|
assert ctx.metadata["key"] == "val"
|
|
|
|
def test_thread_id_required(self):
|
|
with pytest.raises(ValidationError):
|
|
ThreadContext()
|
|
|
|
|
|
class TestHistoricalMessage:
|
|
def test_minimal(self):
|
|
msg = HistoricalMessage(
|
|
message_id="m1",
|
|
sender_id="s1",
|
|
sender_name="Alice",
|
|
content="hello",
|
|
timestamp=datetime.now(),
|
|
)
|
|
assert msg.message_id == "m1"
|
|
assert msg.sender_name == "Alice"
|
|
assert msg.is_from_bot is False
|
|
assert msg.reply_to_id is None
|
|
|
|
def test_bot_message(self):
|
|
msg = HistoricalMessage(
|
|
message_id="m2",
|
|
sender_id="bot1",
|
|
sender_name="Bot",
|
|
content="hello",
|
|
timestamp=datetime.now(),
|
|
is_from_bot=True,
|
|
)
|
|
assert msg.is_from_bot is True
|
|
|
|
def test_with_reply(self):
|
|
msg = HistoricalMessage(
|
|
message_id="m3",
|
|
sender_id="s3",
|
|
sender_name="Bob",
|
|
content="reply",
|
|
timestamp=datetime.now(),
|
|
reply_to_id="m2",
|
|
)
|
|
assert msg.reply_to_id == "m2"
|
|
|
|
def test_required_fields(self):
|
|
with pytest.raises(ValidationError):
|
|
HistoricalMessage(sender_id="s1", sender_name="Alice", content="hi", timestamp=datetime.now())
|
|
|
|
def test_sender_id_required(self):
|
|
with pytest.raises(ValidationError):
|
|
HistoricalMessage(message_id="m1", sender_name="Alice", content="hi", timestamp=datetime.now())
|
|
|
|
|
|
class TestFetchOptions:
|
|
def test_defaults(self):
|
|
opts = FetchOptions()
|
|
assert opts.max_messages == 50
|
|
assert opts.max_chars == 4000
|
|
assert opts.include_bot_messages is True
|
|
assert opts.before_message_id is None
|
|
assert opts.after_message_id is None
|
|
|
|
def test_custom(self):
|
|
opts = FetchOptions(
|
|
max_messages=10,
|
|
max_chars=1000,
|
|
include_bot_messages=False,
|
|
before_message_id="mid_123",
|
|
)
|
|
assert opts.max_messages == 10
|
|
assert opts.max_chars == 1000
|
|
assert opts.include_bot_messages is False
|
|
assert opts.before_message_id == "mid_123" |