PR Title Check / check-title (pull_request) Successful in 7s
Code Quality Pipeline / code-quality (pull_request) Failing after 19s
Test Python Package / unit-tests (pull_request) Successful in 47s
Test Python Package / integration-tests (pull_request) Successful in 44s
Test Python Package / coverage-report (pull_request) Successful in 11s
Introduce PostgresAdapter for dict-based row CRUD via psycopg3, including config, lazy exports, unit/integration tests with testcontainers, and an example UserTableRepository. Co-authored-by: Cursor <[email protected]>
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
"""Unit test fixtures for mocked adapters."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
from minio import Minio
|
|
import psycopg
|
|
import pytest
|
|
import redis
|
|
|
|
from python_repositories.adapters.minio_adapter import MinioAdapter
|
|
from python_repositories.adapters.postgres_adapter import PostgresAdapter
|
|
from python_repositories.adapters.redis_adapter import RedisAdapter
|
|
from tests.conftest import TEST_MINIO_CONFIG, TEST_POSTGRES_CONFIG, TEST_REDIS_CONFIG
|
|
|
|
|
|
@pytest.fixture
|
|
def redis_adapter() -> RedisAdapter:
|
|
"""Provide a RedisAdapter with an injected mock client."""
|
|
mock_client = MagicMock(spec=redis.Redis)
|
|
return RedisAdapter(config=TEST_REDIS_CONFIG, client=mock_client)
|
|
|
|
|
|
@pytest.fixture
|
|
def minio_adapter() -> MinioAdapter:
|
|
"""Provide a MinioAdapter with an injected mock client."""
|
|
mock_client = MagicMock(spec=Minio)
|
|
return MinioAdapter(config=TEST_MINIO_CONFIG, client=mock_client)
|
|
|
|
|
|
@pytest.fixture
|
|
def postgres_adapter() -> PostgresAdapter:
|
|
"""Provide a PostgresAdapter with an injected mock client."""
|
|
mock_client = MagicMock(spec=psycopg.Connection)
|
|
mock_cursor = MagicMock()
|
|
mock_cursor.__enter__ = MagicMock(return_value=mock_cursor)
|
|
mock_cursor.__exit__ = MagicMock(return_value=False)
|
|
mock_client.cursor.return_value = mock_cursor
|
|
return PostgresAdapter(config=TEST_POSTGRES_CONFIG, client=mock_client)
|