新增了Twitch、Telegram、Discord、Slack、Mattermost、WeChat、Zalo等多渠道的单元测试用例,覆盖了令牌处理、速率限制、消息去重、会话解析、格式转换、安全策略等模块 同时在测试配置中添加了测试用的OpenAI API密钥环境变量
148 lines
4.4 KiB
Python
148 lines
4.4 KiB
Python
from __future__ import annotations
|
|
|
|
from yuxi.channels.adapters.zalo_user.reaction import (
|
|
normalize_reaction_icon,
|
|
is_valid_reaction,
|
|
is_delete_reaction,
|
|
resolve_message_ids_for_reaction,
|
|
list_supported_reactions,
|
|
list_reaction_aliases,
|
|
)
|
|
|
|
|
|
class TestNormalizeReactionIcon:
|
|
def test_direct_emoji(self):
|
|
assert normalize_reaction_icon("\U0001f44d") == "\U0001f44d"
|
|
|
|
def test_direct_heart(self):
|
|
assert normalize_reaction_icon("\u2764\ufe0f") == "\u2764\ufe0f"
|
|
|
|
def test_direct_laugh(self):
|
|
assert normalize_reaction_icon("\U0001f602") == "\U0001f602"
|
|
|
|
def test_direct_wow(self):
|
|
assert normalize_reaction_icon("\U0001f62e") == "\U0001f62e"
|
|
|
|
def test_direct_sad(self):
|
|
assert normalize_reaction_icon("\U0001f622") == "\U0001f622"
|
|
|
|
def test_direct_angry(self):
|
|
assert normalize_reaction_icon("\U0001f621") == "\U0001f621"
|
|
|
|
def test_alias_like(self):
|
|
assert normalize_reaction_icon("like") == "\U0001f44d"
|
|
|
|
def test_alias_plus1(self):
|
|
assert normalize_reaction_icon("+1") == "\U0001f44d"
|
|
|
|
def test_alias_colon_plus1(self):
|
|
assert normalize_reaction_icon(":+1:") == "\U0001f44d"
|
|
|
|
def test_alias_love(self):
|
|
assert normalize_reaction_icon("love") == "\u2764\ufe0f"
|
|
|
|
def test_alias_heart(self):
|
|
assert normalize_reaction_icon("heart") == "\u2764\ufe0f"
|
|
|
|
def test_alias_colon_heart(self):
|
|
assert normalize_reaction_icon(":heart:") == "\u2764\ufe0f"
|
|
|
|
def test_alias_laugh(self):
|
|
assert normalize_reaction_icon("laugh") == "\U0001f602"
|
|
|
|
def test_alias_haha(self):
|
|
assert normalize_reaction_icon("haha") == "\U0001f602"
|
|
|
|
def test_alias_colon_laughing(self):
|
|
assert normalize_reaction_icon(":laughing:") == "\U0001f602"
|
|
|
|
def test_alias_wow(self):
|
|
assert normalize_reaction_icon("wow") == "\U0001f62e"
|
|
|
|
def test_alias_surprised(self):
|
|
assert normalize_reaction_icon("surprised") == "\U0001f62e"
|
|
|
|
def test_alias_colon_open_mouth(self):
|
|
assert normalize_reaction_icon(":open_mouth:") == "\U0001f62e"
|
|
|
|
def test_alias_sad(self):
|
|
assert normalize_reaction_icon("sad") == "\U0001f622"
|
|
|
|
def test_alias_cry(self):
|
|
assert normalize_reaction_icon("cry") == "\U0001f622"
|
|
|
|
def test_alias_colon_cry(self):
|
|
assert normalize_reaction_icon(":cry:") == "\U0001f622"
|
|
|
|
def test_alias_angry(self):
|
|
assert normalize_reaction_icon("angry") == "\U0001f621"
|
|
|
|
def test_alias_mad(self):
|
|
assert normalize_reaction_icon("mad") == "\U0001f621"
|
|
|
|
def test_alias_colon_rage(self):
|
|
assert normalize_reaction_icon(":rage:") == "\U0001f621"
|
|
|
|
def test_empty_string_is_delete(self):
|
|
assert normalize_reaction_icon("") == ""
|
|
|
|
def test_whitespace_only(self):
|
|
assert normalize_reaction_icon(" ") == ""
|
|
|
|
def test_case_insensitive_alias(self):
|
|
assert normalize_reaction_icon("LIKE") == "\U0001f44d"
|
|
|
|
def test_unknown_passed_through(self):
|
|
assert normalize_reaction_icon("custom_emoji") == "custom_emoji"
|
|
|
|
|
|
class TestIsValidReaction:
|
|
def test_valid_emoji(self):
|
|
assert is_valid_reaction("\U0001f44d") is True
|
|
|
|
def test_valid_alias(self):
|
|
assert is_valid_reaction("like") is True
|
|
|
|
def test_invalid(self):
|
|
assert is_valid_reaction("unknown") is False
|
|
|
|
def test_empty_is_invalid(self):
|
|
assert is_valid_reaction("") is False
|
|
|
|
|
|
class TestIsDeleteReaction:
|
|
def test_empty_string(self):
|
|
assert is_delete_reaction("") is True
|
|
|
|
def test_none_alike_empty(self):
|
|
assert is_delete_reaction("") is True
|
|
|
|
def test_non_empty(self):
|
|
assert is_delete_reaction("\U0001f44d") is False
|
|
|
|
|
|
class TestResolveMessageIds:
|
|
def test_single_id(self):
|
|
msg_id, cli_id = resolve_message_ids_for_reaction("msg_123")
|
|
assert msg_id == "msg_123"
|
|
assert cli_id is None
|
|
|
|
def test_dual_id(self):
|
|
msg_id, cli_id = resolve_message_ids_for_reaction("msg_123:cli_456")
|
|
assert msg_id == "msg_123"
|
|
assert cli_id == "cli_456"
|
|
|
|
def test_colon_in_id(self):
|
|
msg_id, cli_id = resolve_message_ids_for_reaction("a:b:c")
|
|
assert msg_id == "a"
|
|
assert cli_id == "b:c"
|
|
|
|
|
|
class TestListReactions:
|
|
def test_supported_count(self):
|
|
reactions = list_supported_reactions()
|
|
assert len(reactions) == 6
|
|
|
|
def test_aliases_count(self):
|
|
aliases = list_reaction_aliases()
|
|
assert len(aliases) == 18 |