mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
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
|
|
|
|
|
|
def test_generate_presigned_url_signs_a_get_for_the_object(s3_client: S3Client) -> None:
|
|
# arrange
|
|
s3_client.put_object("bulk-downloads/pkg.zip", b"zip-bytes")
|
|
|
|
# act
|
|
url = s3_client.generate_presigned_url("bulk-downloads/pkg.zip", expires_in=3600)
|
|
|
|
# assert — a signed GET URL for this bucket + key
|
|
assert BUCKET in url
|
|
assert "bulk-downloads/pkg.zip" in url
|
|
assert "Signature" in url
|