mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-20 08:32:25 +00:00
test(telegram): cover local attachment filenames
Add a regression test for preserving the original basename when Telegram sends local media bytes. Made-with: Cursor
This commit is contained in:
parent
e36e70fe16
commit
50698c3d1c
@ -1,4 +1,3 @@
|
|||||||
import asyncio
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
from unittest.mock import AsyncMock
|
from unittest.mock import AsyncMock
|
||||||
@ -13,8 +12,12 @@ except ImportError:
|
|||||||
|
|
||||||
from nanobot.bus.events import OutboundMessage
|
from nanobot.bus.events import OutboundMessage
|
||||||
from nanobot.bus.queue import MessageBus
|
from nanobot.bus.queue import MessageBus
|
||||||
from nanobot.channels.telegram import TELEGRAM_REPLY_CONTEXT_MAX_LEN, TelegramChannel, _StreamBuf
|
from nanobot.channels.telegram import (
|
||||||
from nanobot.channels.telegram import TelegramConfig
|
TELEGRAM_REPLY_CONTEXT_MAX_LEN,
|
||||||
|
TelegramChannel,
|
||||||
|
TelegramConfig,
|
||||||
|
_StreamBuf,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class _FakeHTTPXRequest:
|
class _FakeHTTPXRequest:
|
||||||
@ -752,6 +755,36 @@ async def test_send_remote_media_url_after_security_validation(monkeypatch) -> N
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_send_local_media_preserves_filename(tmp_path: Path) -> None:
|
||||||
|
channel = TelegramChannel(
|
||||||
|
TelegramConfig(enabled=True, token="123:abc", allow_from=["*"]),
|
||||||
|
MessageBus(),
|
||||||
|
)
|
||||||
|
channel._app = _FakeApp(lambda: None)
|
||||||
|
attachment = tmp_path / "report.final.md"
|
||||||
|
attachment.write_bytes(b"# Report\n")
|
||||||
|
|
||||||
|
await channel.send(
|
||||||
|
OutboundMessage(
|
||||||
|
channel="telegram",
|
||||||
|
chat_id="123",
|
||||||
|
content="",
|
||||||
|
media=[str(attachment)],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert channel._app.bot.sent_media == [
|
||||||
|
{
|
||||||
|
"kind": "document",
|
||||||
|
"chat_id": 123,
|
||||||
|
"document": b"# Report\n",
|
||||||
|
"reply_parameters": None,
|
||||||
|
"filename": "report.final.md",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_send_blocks_unsafe_remote_media_url(monkeypatch) -> None:
|
async def test_send_blocks_unsafe_remote_media_url(monkeypatch) -> None:
|
||||||
channel = TelegramChannel(
|
channel = TelegramChannel(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user