40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from collections.abc import Iterator
|
|
|
|
import pytest
|
|
from testcontainers.community.minio import MinioContainer
|
|
|
|
from src.config import MinioSettings
|
|
from src.infrastructure.minio.client import create_client
|
|
|
|
_BUCKET = "test-source-files"
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def minio_container() -> Iterator[MinioContainer]:
|
|
with MinioContainer() as container:
|
|
yield container
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def minio_settings(minio_container: MinioContainer) -> MinioSettings:
|
|
config = minio_container.get_config()
|
|
# Pinned to IPv4 for the same reason as postgres_url (see
|
|
# tests/integration/postgres/conftest.py): `localhost` resolves to `::1`
|
|
# first, but Docker only publishes the mapped port on IPv4, so the
|
|
# connection hangs instead of failing.
|
|
endpoint = config["endpoint"].replace("localhost:", "127.0.0.1:")
|
|
return MinioSettings(
|
|
endpoint=endpoint,
|
|
access_key=config["access_key"],
|
|
secret_key=config["secret_key"],
|
|
secure=False,
|
|
bucket=_BUCKET,
|
|
)
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def _ensure_bucket(minio_settings: MinioSettings) -> None:
|
|
client = create_client(minio_settings)
|
|
if not client.bucket_exists(minio_settings.bucket):
|
|
client.make_bucket(minio_settings.bucket)
|