Add config and client injection with test reorganization.
Introduce typed config objects, optional adapter injection, and .env loading to simplify testing while preserving env-based defaults for production usage. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
7ed1b34233
commit
5e32787b90
@@ -0,0 +1,31 @@
|
||||
"""Unit tests for MinioConfig."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from python_repositories.config import MinioConfig
|
||||
|
||||
|
||||
def test_from_env_loads_all_fields(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")
|
||||
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 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)
|
||||
Reference in New Issue
Block a user