Model/tests/infrastructure/test_sqs_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

38 lines
1.2 KiB
Python

import json
from collections.abc import Iterator
from typing import Any, cast
import pytest
from moto import mock_aws
from infrastructure.sqs_client import SqsClient
from tests.infrastructure import make_boto_client
@pytest.fixture
def sqs_setup() -> Iterator[tuple[SqsClient, Any, str]]:
with mock_aws():
boto_client = make_boto_client("sqs")
queue: dict[str, Any] = boto_client.create_queue(QueueName="test-queue")
queue_url = cast(str, queue["QueueUrl"])
yield SqsClient(boto_client, queue_url), boto_client, queue_url
def test_send_returns_message_id(sqs_setup: tuple[SqsClient, Any, str]) -> None:
client, _boto, _url = sqs_setup
message_id = client.send({"hello": "world"})
assert isinstance(message_id, str)
assert message_id
def test_send_json_serialises_body(sqs_setup: tuple[SqsClient, Any, str]) -> None:
client, boto_client, queue_url = sqs_setup
body = {"hello": "world", "count": 3}
client.send(body)
received: dict[str, Any] = boto_client.receive_message(
QueueUrl=queue_url, MaxNumberOfMessages=1
)
messages: list[dict[str, Any]] = received["Messages"]
assert len(messages) == 1
assert json.loads(messages[0]["Body"]) == body