test(telegram): cover rich message fallback latch

This commit is contained in:
Xubin Ren
2026-06-21 15:22:05 +08:00
parent a8c65b50ca
commit 85036bacb6
+39
View File
@@ -466,6 +466,45 @@ async def test_send_text_gives_up_after_max_retries() -> None:
assert channel._app.bot.sent_messages == []
@pytest.mark.asyncio
async def test_send_rich_capability_error_latches_and_falls_back() -> None:
from telegram.error import BadRequest
channel = TelegramChannel(
TelegramConfig(enabled=True, token="123:abc", allow_from=["*"]),
MessageBus(),
)
channel._app = _FakeApp(lambda: None)
channel._app.bot.do_api_request = AsyncMock(side_effect=BadRequest("Method not found"))
await channel.send(OutboundMessage(channel="telegram", chat_id="123", content="**hello**"))
assert channel._rich_send_disabled is True
channel._app.bot.do_api_request.assert_awaited_once()
assert len(channel._app.bot.sent_messages) == 1
assert channel._app.bot.sent_messages[0]["text"]
@pytest.mark.asyncio
async def test_send_rich_bad_request_does_not_latch_capability() -> None:
from telegram.error import BadRequest
channel = TelegramChannel(
TelegramConfig(enabled=True, token="123:abc", allow_from=["*"]),
MessageBus(),
)
channel._app = _FakeApp(lambda: None)
channel._app.bot.do_api_request = AsyncMock(
side_effect=BadRequest("Bad Request: message to reply not found")
)
await channel.send(OutboundMessage(channel="telegram", chat_id="123", content="**hello**"))
assert channel._rich_send_disabled is False
channel._app.bot.do_api_request.assert_awaited_once()
assert len(channel._app.bot.sent_messages) == 1
@pytest.mark.asyncio
async def test_on_error_logs_network_issues_as_warning(monkeypatch) -> None:
from telegram.error import NetworkError