Files
python-repositories/tests/unit/minio_config_test.py
T
Brian Bjarke JensenandCursor 4a5b3b631f
PR Title Check / check-title (pull_request) Successful in 6s
Test Python Package / unit-tests (pull_request) Successful in 18s
Code Quality Pipeline / code-quality (pull_request) Successful in 1m28s
Test Python Package / integration-tests (pull_request) Failing after 1m54s
Test Python Package / coverage-report (pull_request) Has been skipped
Make MinIO bucket creation opt-in with production-safe defaults.
Require buckets to exist by default on connect, extract env_bool parsing, and document local dev overrides for secure and auto-creation settings.

Co-authored-by: Cursor <[email protected]>
2026-07-09 14:52:14 +02:00

69 lines
2.4 KiB
Python

"""Unit tests for MinioConfig."""
from __future__ import annotations
import pytest
from python_repositories.config import MinioConfig
def _set_required_minio_env(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("MINIO_ENDPOINT", "localhost:9000")
monkeypatch.setenv("MINIO_ACCESS_KEY", "access")
monkeypatch.setenv("MINIO_SECRET_KEY", "secret")
monkeypatch.setenv("MINIO_BUCKET", "my-bucket")
def test_from_env_loads_all_fields(monkeypatch: pytest.MonkeyPatch) -> None:
_set_required_minio_env(monkeypatch)
config = MinioConfig.from_env(use_dotenv=False)
assert config.endpoint == "localhost:9000"
assert config.access_key == "access"
assert config.secret_key == "secret"
assert config.bucket == "my-bucket"
assert config.secure is True
assert config.create_bucket_if_missing is False
def test_from_env_defaults_secure_to_true_when_unset(
monkeypatch: pytest.MonkeyPatch,
) -> None:
_set_required_minio_env(monkeypatch)
monkeypatch.delenv("MINIO_SECURE", raising=False)
config = MinioConfig.from_env(use_dotenv=False)
assert config.secure is True
def test_from_env_reads_secure_from_env(monkeypatch: pytest.MonkeyPatch) -> None:
_set_required_minio_env(monkeypatch)
monkeypatch.setenv("MINIO_SECURE", "false")
assert MinioConfig.from_env(use_dotenv=False).secure is False
def test_from_env_reads_create_bucket_if_missing_from_env(
monkeypatch: pytest.MonkeyPatch,
) -> None:
_set_required_minio_env(monkeypatch)
monkeypatch.setenv("MINIO_CREATE_BUCKET_IF_MISSING", "true")
assert MinioConfig.from_env(use_dotenv=False).create_bucket_if_missing is True
def test_from_env_defaults_create_bucket_if_missing_to_false_when_unset(
monkeypatch: pytest.MonkeyPatch,
) -> None:
_set_required_minio_env(monkeypatch)
monkeypatch.delenv("MINIO_CREATE_BUCKET_IF_MISSING", raising=False)
config = MinioConfig.from_env(use_dotenv=False)
assert config.create_bucket_if_missing is False
def test_from_env_raises_when_endpoint_missing(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.delenv("MINIO_ENDPOINT", raising=False)
monkeypatch.setenv("MINIO_ACCESS_KEY", "access")
monkeypatch.setenv("MINIO_SECRET_KEY", "secret")
monkeypatch.setenv("MINIO_BUCKET", "my-bucket")
with pytest.raises(Exception):
MinioConfig.from_env(use_dotenv=False)