87 lines
2.5 KiB
Python
87 lines
2.5 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
|
||
|
|
from yuxi.channels.adapters.wechat.format import (
|
||
|
|
map_wecom_msg_type,
|
||
|
|
map_mp_msg_type,
|
||
|
|
map_bridge_msg_type,
|
||
|
|
truncate_text,
|
||
|
|
TRUNCATION_MARKER,
|
||
|
|
)
|
||
|
|
from yuxi.channels.models import MessageType
|
||
|
|
|
||
|
|
|
||
|
|
class TestMessageTypeMapping:
|
||
|
|
def test_map_wecom_text(self):
|
||
|
|
assert map_wecom_msg_type("text") == MessageType.TEXT
|
||
|
|
|
||
|
|
def test_map_wecom_image(self):
|
||
|
|
assert map_wecom_msg_type("image") == MessageType.IMAGE
|
||
|
|
|
||
|
|
def test_map_wecom_voice(self):
|
||
|
|
assert map_wecom_msg_type("voice") == MessageType.AUDIO
|
||
|
|
|
||
|
|
def test_map_wecom_video(self):
|
||
|
|
assert map_wecom_msg_type("video") == MessageType.VIDEO
|
||
|
|
|
||
|
|
def test_map_wecom_file(self):
|
||
|
|
assert map_wecom_msg_type("file") == MessageType.FILE
|
||
|
|
|
||
|
|
def test_map_wecom_location(self):
|
||
|
|
assert map_wecom_msg_type("location") == MessageType.LOCATION
|
||
|
|
|
||
|
|
def test_map_wecom_unknown(self):
|
||
|
|
assert map_wecom_msg_type("unknown") == MessageType.TEXT
|
||
|
|
|
||
|
|
def test_map_mp_text(self):
|
||
|
|
assert map_mp_msg_type("text") == MessageType.TEXT
|
||
|
|
|
||
|
|
def test_map_mp_image(self):
|
||
|
|
assert map_mp_msg_type("image") == MessageType.IMAGE
|
||
|
|
|
||
|
|
def test_map_mp_voice(self):
|
||
|
|
assert map_mp_msg_type("voice") == MessageType.AUDIO
|
||
|
|
|
||
|
|
def test_map_bridge_text(self):
|
||
|
|
assert map_bridge_msg_type(1) == MessageType.TEXT
|
||
|
|
|
||
|
|
def test_map_bridge_image(self):
|
||
|
|
assert map_bridge_msg_type(3) == MessageType.IMAGE
|
||
|
|
|
||
|
|
def test_map_bridge_voice(self):
|
||
|
|
assert map_bridge_msg_type(34) == MessageType.AUDIO
|
||
|
|
|
||
|
|
def test_map_bridge_video(self):
|
||
|
|
assert map_bridge_msg_type(43) == MessageType.VIDEO
|
||
|
|
|
||
|
|
def test_map_bridge_file(self):
|
||
|
|
assert map_bridge_msg_type(49) == MessageType.FILE
|
||
|
|
|
||
|
|
def test_map_bridge_unknown(self):
|
||
|
|
assert map_bridge_msg_type(99) == MessageType.TEXT
|
||
|
|
|
||
|
|
|
||
|
|
class TestTextTruncation:
|
||
|
|
def test_no_truncation_needed(self):
|
||
|
|
text = "短文本"
|
||
|
|
result = truncate_text(text, 100)
|
||
|
|
assert result == text
|
||
|
|
assert len(result) <= 100
|
||
|
|
|
||
|
|
def test_truncation_applied(self):
|
||
|
|
text = "A" * 3000
|
||
|
|
result = truncate_text(text, 100)
|
||
|
|
assert len(result) <= 100
|
||
|
|
assert TRUNCATION_MARKER in result
|
||
|
|
|
||
|
|
def test_truncation_exact_limit(self):
|
||
|
|
text = "A" * 100
|
||
|
|
result = truncate_text(text, 100)
|
||
|
|
assert result == text
|
||
|
|
|
||
|
|
def test_truncation_at_boundary(self):
|
||
|
|
text = "A" * 101
|
||
|
|
result = truncate_text(text, 100)
|
||
|
|
assert len(result) <= 100
|
||
|
|
assert TRUNCATION_MARKER in result
|