Reach 100% combined coverage with targeted unit tests.
Code Quality Pipeline / code-quality (pull_request) Failing after 29s
Test Python Package / integration-tests (pull_request) Successful in 35s
Test Python Package / unit-tests (pull_request) Successful in 42s
PR Title Check / check-title (pull_request) Successful in 52s
Test Python Package / coverage-report (pull_request) Successful in 12s
Code Quality Pipeline / code-quality (pull_request) Failing after 29s
Test Python Package / integration-tests (pull_request) Successful in 35s
Test Python Package / unit-tests (pull_request) Successful in 42s
PR Title Check / check-title (pull_request) Successful in 52s
Test Python Package / coverage-report (pull_request) Successful in 12s
Add fast unit tests for lazy-import helpers and injected-client connect paths that integration tests miss, and raise the coverage floor to 100%. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
co-authored by
Cursor
parent
ce062be411
commit
beb2b5128e
@@ -53,3 +53,43 @@ 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)
|
||||
|
||||
|
||||
def test_connect_with_injected_client_succeeds() -> None:
|
||||
mock_client = MagicMock(spec=Minio)
|
||||
adapter = MinioAdapter(config=TEST_MINIO_CONFIG, client=mock_client)
|
||||
|
||||
adapter.connect()
|
||||
|
||||
mock_client.list_buckets.assert_called_once()
|
||||
|
||||
|
||||
def test_connect_with_injected_client_raises_on_failure() -> None:
|
||||
mock_client = MagicMock(spec=Minio)
|
||||
mock_client.list_buckets.side_effect = Exception("connection lost")
|
||||
adapter = MinioAdapter(config=TEST_MINIO_CONFIG, client=mock_client)
|
||||
|
||||
with pytest.raises(ConnectionError, match="Could not connect to Minio"):
|
||||
adapter.connect()
|
||||
|
||||
|
||||
def test_connect_disconnects_before_reconnect(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
stale_client = MagicMock(spec=Minio)
|
||||
new_client = MagicMock(spec=Minio)
|
||||
adapter = MinioAdapter(config=TEST_MINIO_CONFIG)
|
||||
adapter._client = stale_client
|
||||
adapter._bucket_name = None
|
||||
|
||||
monkeypatch.setattr(
|
||||
"python_repositories.adapters.minio_adapter.minio.Minio",
|
||||
lambda *args, **kwargs: new_client,
|
||||
)
|
||||
|
||||
adapter.connect()
|
||||
|
||||
assert adapter._client is new_client
|
||||
assert adapter._bucket_name == TEST_MINIO_CONFIG.bucket
|
||||
new_client.list_buckets.assert_called_once()
|
||||
new_client.bucket_exists.assert_called_once_with(TEST_MINIO_CONFIG.bucket)
|
||||
|
||||
Reference in New Issue
Block a user