"""Unit tests for MinioAdapter instantiation and injection.""" from __future__ import annotations from unittest.mock import MagicMock import pytest from minio import Minio from python_repositories.adapters.minio_adapter import MinioAdapter from python_repositories.interfaces import ObjectRepositoryInterface from tests.conftest import TEST_MINIO_CONFIG def test_should_adhere_to_interface() -> None: assert issubclass(MinioAdapter, ObjectRepositoryInterface) _ = MinioAdapter(config=TEST_MINIO_CONFIG) def test_should_have_logger_when_instantiated() -> None: adapter = MinioAdapter(config=TEST_MINIO_CONFIG) assert hasattr(adapter, "logger") assert adapter.logger is not None def test_should_not_be_connected_when_instantiated() -> None: adapter = MinioAdapter(config=TEST_MINIO_CONFIG) assert not adapter.is_connected() def test_constructs_with_injected_config_without_env( monkeypatch: pytest.MonkeyPatch, ) -> None: for var in ( "MINIO_ENDPOINT", "MINIO_ACCESS_KEY", "MINIO_SECRET_KEY", "MINIO_BUCKET", ): monkeypatch.delenv(var, raising=False) adapter = MinioAdapter(config=TEST_MINIO_CONFIG) assert adapter._config == TEST_MINIO_CONFIG def test_injected_client_sets_bucket_name() -> None: mock_client = MagicMock(spec=Minio) adapter = MinioAdapter(config=TEST_MINIO_CONFIG, client=mock_client) assert adapter._bucket_name == "test-bucket" assert adapter._client is mock_client def test_raises_when_client_provided_without_config() -> None: mock_client = MagicMock(spec=Minio) with pytest.raises(ValueError, match="config is required"): MinioAdapter(client=mock_client)