Model/tests/infrastructure/test_s3_document_bytes_reader.py
Khalim Conn-Kowlessar 0a09b56425 Read document bytes from an arbitrary source bucket 🟥
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 09:42:05 +00:00

29 lines
1 KiB
Python

"""The multi-bucket document reader (ADR-0060) — reads object bytes from
whichever source bucket an uploaded file lives in."""
from collections.abc import Iterator
import pytest
from moto import mock_aws
from infrastructure.s3.s3_document_bytes_reader import S3DocumentBytesReader
from tests.infrastructure import make_boto_client
@pytest.fixture
def reader() -> Iterator[S3DocumentBytesReader]:
with mock_aws():
boto_client = make_boto_client("s3")
boto_client.create_bucket(Bucket="src-a")
boto_client.create_bucket(Bucket="src-b")
boto_client.put_object(Bucket="src-a", Key="surveys/one.pdf", Body=b"AAA")
boto_client.put_object(Bucket="src-b", Key="photos/two.zip", Body=b"BBB")
yield S3DocumentBytesReader(boto_client)
def test_reads_bytes_from_the_named_source_bucket(
reader: S3DocumentBytesReader,
) -> None:
# act / assert — each object is read from its own bucket.
assert reader.read("src-a", "surveys/one.pdf") == b"AAA"
assert reader.read("src-b", "photos/two.zip") == b"BBB"