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重连相关测试
151 lines
4.8 KiB
Python
151 lines
4.8 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from yuxi.channels.adapters.nextcloudtalk.normalize import (
|
|
is_pure_token,
|
|
looks_like_nc_target,
|
|
normalize_nc_target,
|
|
normalize_room_target,
|
|
normalize_user_target,
|
|
resolve_target_with_hint,
|
|
strip_nc_prefix,
|
|
)
|
|
|
|
|
|
class TestIsPureToken:
|
|
def test_valid_token(self):
|
|
assert is_pure_token("abc123def456abcdef1234") is True
|
|
|
|
def test_min_length_token(self):
|
|
assert is_pure_token("a" * 20) is True
|
|
|
|
def test_max_length_token(self):
|
|
assert is_pure_token("a" * 64) is True
|
|
|
|
def test_too_short_token(self):
|
|
assert is_pure_token("abc123def456") is False
|
|
|
|
def test_too_long_token(self):
|
|
assert is_pure_token("a" * 65) is False
|
|
|
|
def test_token_with_special_chars(self):
|
|
assert is_pure_token("abc-def") is False
|
|
|
|
def test_token_with_uppercase(self):
|
|
assert is_pure_token("ABC123") is False
|
|
|
|
def test_token_with_whitespace(self):
|
|
assert is_pure_token(" " + "a" * 20 + " ") is True
|
|
|
|
def test_empty_string(self):
|
|
assert is_pure_token("") is False
|
|
|
|
|
|
class TestResolveTargetWithHint:
|
|
def test_pure_token_gets_direct_token_hint(self):
|
|
target, hints = resolve_target_with_hint("a" * 30)
|
|
assert hints["resolver_hint"] == "direct_token"
|
|
assert target == f"nextcloud-talk:{'a' * 30}"
|
|
|
|
def test_room_prefix(self):
|
|
target, hints = resolve_target_with_hint("room:myroom")
|
|
assert hints["resolver_hint"] == "room_token"
|
|
assert target.startswith("nextcloud-talk:")
|
|
|
|
def test_user_prefix(self):
|
|
target, hints = resolve_target_with_hint("user:johndoe")
|
|
assert hints["resolver_hint"] == "user_id"
|
|
assert target.startswith("nextcloud-talk:")
|
|
|
|
def test_already_prefixed(self):
|
|
target, hints = resolve_target_with_hint("nextcloud-talk:room:abc")
|
|
assert target == "nextcloud-talk:room:abc"
|
|
|
|
def test_whitespace_stripped(self):
|
|
target, _ = resolve_target_with_hint(" user:johndoe ")
|
|
assert target == "nextcloud-talk:user:johndoe"
|
|
|
|
|
|
class TestNormalizeNcTarget:
|
|
def test_bare_target(self):
|
|
assert normalize_nc_target("room:abc") == "nextcloud-talk:room:abc"
|
|
|
|
def test_nextcloud_talk_colon_prefix(self):
|
|
assert normalize_nc_target("nextcloud-talk:room:abc") == "nextcloud-talk:room:abc"
|
|
|
|
def test_nextcloudtalk_colon_prefix(self):
|
|
assert normalize_nc_target("nextcloudtalk:room:abc") == "nextcloud-talk:room:abc"
|
|
|
|
def test_nc_talk_colon_prefix(self):
|
|
assert normalize_nc_target("nc-talk:room:abc") == "nextcloud-talk:room:abc"
|
|
|
|
def test_nc_colon_prefix(self):
|
|
assert normalize_nc_target("nc:johndoe") == "nextcloud-talk:johndoe"
|
|
|
|
def test_already_normalized(self):
|
|
result = normalize_nc_target("nextcloud-talk:johndoe")
|
|
assert result == "nextcloud-talk:johndoe"
|
|
|
|
def test_lowercase_conversion(self):
|
|
result = normalize_nc_target("ROOM:ABC")
|
|
assert result == "nextcloud-talk:room:abc"
|
|
|
|
|
|
class TestStripNcPrefix:
|
|
def test_strips_nextcloud_talk_prefix(self):
|
|
assert strip_nc_prefix("nextcloud-talk:room:abc") == "room:abc"
|
|
|
|
def test_strips_nextcloudtalk(self):
|
|
assert strip_nc_prefix("nextcloudtalk:room:abc") == "room:abc"
|
|
|
|
def test_strips_nc_talk(self):
|
|
assert strip_nc_prefix("nc-talk:room:abc") == "room:abc"
|
|
|
|
def test_strips_nc(self):
|
|
assert strip_nc_prefix("nc:johndoe") == "johndoe"
|
|
|
|
def test_no_prefix_returns_original(self):
|
|
assert strip_nc_prefix("johndoe") == "johndoe"
|
|
|
|
def test_strips_whitespace_and_lowers(self):
|
|
assert strip_nc_prefix(" NC:JohnDoe ") == "johndoe"
|
|
|
|
|
|
class TestLooksLikeNcTarget:
|
|
def test_matches_nextcloud_talk(self):
|
|
assert looks_like_nc_target("nextcloud-talk:abc") is True
|
|
|
|
def test_matches_nextcloudtalk(self):
|
|
assert looks_like_nc_target("nextcloudtalk:abc") is True
|
|
|
|
def test_matches_nc_talk(self):
|
|
assert looks_like_nc_target("nc-talk:abc") is True
|
|
|
|
def test_matches_nc(self):
|
|
assert looks_like_nc_target("nc:abc") is True
|
|
|
|
def test_no_match(self):
|
|
assert looks_like_nc_target("random:abc") is False
|
|
|
|
def test_case_insensitive(self):
|
|
assert looks_like_nc_target("NC-TALK:ABC") is True
|
|
|
|
def test_empty_string(self):
|
|
assert looks_like_nc_target("") is False
|
|
|
|
|
|
class TestNormalizeRoomTarget:
|
|
def test_basic(self):
|
|
assert normalize_room_target("abc123") == "nextcloud-talk:room:abc123"
|
|
|
|
def test_with_special_chars(self):
|
|
assert normalize_room_target("room_1") == "nextcloud-talk:room:room_1"
|
|
|
|
|
|
class TestNormalizeUserTarget:
|
|
def test_basic(self):
|
|
assert normalize_user_target("johndoe") == "nextcloud-talk:johndoe"
|
|
|
|
def test_with_email(self):
|
|
assert normalize_user_target("john@example.com") == "nextcloud-talk:john@example.com" |