"""The multi-bucket document downloader (ADR-0060) — streams object bytes from whichever source bucket an uploaded file lives in, to local disk.""" from collections.abc import Iterator from pathlib import Path import pytest from moto import mock_aws from infrastructure.s3.s3_document_downloader import S3DocumentDownloader from tests.infrastructure import make_boto_client @pytest.fixture def downloader() -> Iterator[S3DocumentDownloader]: 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 S3DocumentDownloader(boto_client) def test_downloads_bytes_from_the_named_source_bucket( downloader: S3DocumentDownloader, tmp_path: Path ) -> None: # act — each object streams from its own bucket to a local file. a = tmp_path / "a" b = tmp_path / "b" downloader.download("src-a", "surveys/one.pdf", str(a)) downloader.download("src-b", "photos/two.zip", str(b)) # assert assert a.read_bytes() == b"AAA" assert b.read_bytes() == b"BBB"