Model/tests/infrastructure/test_s3_client.py
Jun-te Kim 7b00a33cd2 infrastructure: typed S3/SQS clients (S3Client, CsvS3Client, SqsClient, Address2UprnQueueClient)
Slice 3/6 of the postcode_splitter refactor (Hestia-Homes/Model#1101).
Introduces a thin typed infrastructure layer wrapping boto3 for the AWS
side of the splitter. S3Client/SqsClient are bucket-/queue-bound byte
adapters; CsvS3Client subclasses S3Client to round-trip CSV row dicts
via the existing parse_s3_uri helper in utils/s3.py; Address2UprnQueueClient
subclasses SqsClient to publish the typed {task_id, sub_task_id, s3_uri}
fan-out body the downstream consumer expects. moto[s3,sqs] is pulled into
test.requirements.txt and the new tests/infrastructure/ suite exercises
each client against the moto backend (S3 round-trip, CSV round-trip,
SQS send + body inspection, typed publish + body inspection). pyright
--strict is clean on the new modules.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-19 17:12:21 +00:00

31 lines
931 B
Python

from collections.abc import Iterator
import pytest
from moto import mock_aws
from infrastructure.s3_client import S3Client
from tests.infrastructure import make_boto_client
BUCKET = "test-bucket"
@pytest.fixture
def s3_client() -> Iterator[S3Client]:
with mock_aws():
boto_client = make_boto_client("s3")
boto_client.create_bucket(Bucket=BUCKET)
yield S3Client(boto_client, BUCKET)
def test_put_object_returns_s3_uri(s3_client: S3Client) -> None:
uri = s3_client.put_object("folder/data.bin", b"payload")
assert uri == f"s3://{BUCKET}/folder/data.bin"
def test_get_object_returns_bytes_written_by_put_object(s3_client: S3Client) -> None:
s3_client.put_object("round/trip.bin", b"hello world")
assert s3_client.get_object("round/trip.bin") == b"hello world"
def test_bucket_property_exposes_configured_bucket(s3_client: S3Client) -> None:
assert s3_client.bucket == BUCKET