Model/tests/infrastructure/test_s3_client.py

36 lines
1,009 B
Python

from collections.abc import Iterator
import pytest
from moto import mock_aws
from infrastructure.s3.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:
# act
uri = s3_client.put_object("folder/data.bin", b"payload")
# assert
assert uri == f"s3://{BUCKET}/folder/data.bin"
def test_get_object_returns_bytes_written_by_put_object(s3_client: S3Client) -> None:
# arrange
s3_client.put_object("round/trip.bin", b"hello world")
# act / assert
assert s3_client.get_object("round/trip.bin") == b"hello world"
def test_bucket_property_exposes_configured_bucket(s3_client: S3Client) -> None:
# act / assert
assert s3_client.bucket == BUCKET