trace/services/notify-gateway/tests/test_plain_format.py
Lee 19afaffbb7
All checks were successful
Java Maven 3.9.9 & JDK 26 CI/CD Pipeline / build-and-deploy (push) Successful in 3m22s
feat: add shared notification gateway
2026-09-07 17:50:25 +08:00

33 lines
1.2 KiB
Python

import inspect
from notifiers.telegram import TelegramNotifier
from notifiers.wecom_webhook import WecomWebhookNotifier, _format_plain_text
def test_titleless_message_is_plain_and_undecorated():
text = "【小学群】 发送人:家长\n摘要:发送了一张图片\n准备物品:课外书"
result = _format_plain_text("", text)
assert result == text
assert "🔔" not in result
assert "📌" not in result
assert "━━━━━━━━━━━━" not in result
def test_titled_messages_keep_existing_decoration():
result = _format_plain_text("系统通知", "发送人:测试")
assert result.startswith("🔔 系统通知\n━━━━━━━━━━━━")
assert "👤 发送人:测试" in result
def test_original_image_file_attachments_are_disabled():
telegram_source = inspect.getsource(TelegramNotifier.send)
wecom_source = inspect.getsource(WecomWebhookNotifier.send)
assert "sendDocument" not in telegram_source
assert "upload_media" not in wecom_source
assert '"msgtype": "file"' not in wecom_source
for name in sorted(value for value in globals() if value.startswith("test_")):
globals()[name]()
print(f"{name}=PASS")