# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence. """How an attachment is spelled on the wire. Split out of test_transport_rest.py, which reached the 250-line cap. The data-URI form is the container's own, read off its /swagger/doc.json rather than remembered: api.SendMessageV2 documents base64_attachments as taking bare base64, "data:;base64," or "data:;filename=;base64,". """ from __future__ import annotations import json from typing import TYPE_CHECKING import httpx from tests.test_transport_rest import MockHandler, _transport if TYPE_CHECKING: from signal_bot.config import Config def _recorder(seen: list[dict[str, object]]) -> MockHandler: """A handler that keeps every payload it is sent.""" def record(request: httpx.Request) -> httpx.Response: seen.append(json.loads(request.content)) return httpx.Response(201) return record async def test_an_image_send_is_unchanged_by_the_media_path(config: Config) -> None: """send_image delegates now; the payload must still be bare base64.""" seen: list[dict[str, object]] = [] def record(request: httpx.Request) -> httpx.Response: seen.append(__import__("json").loads(request.content)) return httpx.Response(201) transport = _transport(config, record) await transport.send_image("QUJD", "group-a==", caption="hi") assert seen[0]["base64_attachments"] == ["QUJD"] assert seen[0]["message"] == "hi" async def test_a_typed_attachment_travels_as_a_data_uri(config: Config) -> None: """The spelling is the container's own, from its /swagger/doc.json.""" seen: list[dict[str, object]] = [] def record(request: httpx.Request) -> httpx.Response: seen.append(__import__("json").loads(request.content)) return httpx.Response(201) transport = _transport(config, record) await transport.send_media("QUJD", "group-a==", media_type="video/mp4", filename="clip.mp4") assert seen[0]["base64_attachments"] == ["data:video/mp4;filename=clip.mp4;base64,QUJD"] async def test_a_type_without_a_filename_still_names_the_type(config: Config) -> None: seen: list[dict[str, object]] = [] def record(request: httpx.Request) -> httpx.Response: seen.append(__import__("json").loads(request.content)) return httpx.Response(201) transport = _transport(config, record) await transport.send_media("QUJD", "group-a==", media_type="image/png") assert seen[0]["base64_attachments"] == ["data:image/png;base64,QUJD"]