Add Postgres table adapter with TableRepositoryInterface.
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
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 <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
f28d3c4844
commit
dc6f8a3e89
@@ -45,6 +45,7 @@ from python_repositories import JsonRepositoryInterface
|
||||
assert JsonRepositoryInterface is not None
|
||||
assert "python_repositories.adapters.redis_adapter" not in sys.modules
|
||||
assert "python_repositories.adapters.minio_adapter" not in sys.modules
|
||||
assert "python_repositories.adapters.postgres_adapter" not in sys.modules
|
||||
"""
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", script],
|
||||
@@ -58,10 +59,11 @@ assert "python_repositories.adapters.minio_adapter" not in sys.modules
|
||||
|
||||
def test_lazy_adapter_load_succeeds_when_extra_present() -> None:
|
||||
"""Adapters load when their optional dependencies are installed."""
|
||||
from python_repositories import MinioAdapter, RedisAdapter
|
||||
from python_repositories import MinioAdapter, PostgresAdapter, RedisAdapter
|
||||
|
||||
assert RedisAdapter.__name__ == "RedisAdapter"
|
||||
assert MinioAdapter.__name__ == "MinioAdapter"
|
||||
assert PostgresAdapter.__name__ == "PostgresAdapter"
|
||||
|
||||
|
||||
def test_redis_adapter_import_error_without_extra() -> None:
|
||||
@@ -86,6 +88,17 @@ def test_minio_adapter_import_error_without_extra() -> None:
|
||||
importlib.reload(minio_adapter_module)
|
||||
|
||||
|
||||
def test_postgres_adapter_import_error_without_extra() -> None:
|
||||
"""Missing postgres extra raises ImportError with install hint."""
|
||||
import python_repositories.adapters.postgres_adapter as postgres_adapter_module
|
||||
|
||||
with patch.object(builtins, "__import__", new=_block_backend_import("psycopg")):
|
||||
with pytest.raises(ImportError, match=r"python-repositories\[postgres\]"):
|
||||
importlib.reload(postgres_adapter_module)
|
||||
|
||||
importlib.reload(postgres_adapter_module)
|
||||
|
||||
|
||||
def test_top_level_lazy_import_propagates_redis_import_error() -> None:
|
||||
"""Top-level RedisAdapter access surfaces adapter import errors."""
|
||||
with patch(
|
||||
@@ -112,6 +125,19 @@ def test_top_level_lazy_import_propagates_minio_import_error() -> None:
|
||||
_ = python_repositories.MinioAdapter
|
||||
|
||||
|
||||
def test_top_level_lazy_import_propagates_postgres_import_error() -> None:
|
||||
"""Top-level PostgresAdapter access surfaces adapter import errors."""
|
||||
with patch(
|
||||
"importlib.import_module",
|
||||
side_effect=ImportError(
|
||||
"Postgres support requires the postgres extra. "
|
||||
"Install with: pip install python-repositories[postgres]"
|
||||
),
|
||||
):
|
||||
with pytest.raises(ImportError, match=r"python-repositories\[postgres\]"):
|
||||
_ = python_repositories.PostgresAdapter
|
||||
|
||||
|
||||
def test_adapters_subpackage_lazy_import_succeeds() -> None:
|
||||
"""Adapter subpackage imports delegate to the same lazy loader."""
|
||||
from python_repositories.adapters import RedisAdapter
|
||||
@@ -123,7 +149,7 @@ def test_adapters_dir_exposes_lazy_exports() -> None:
|
||||
"""dir(adapters) includes lazy adapter names for tab completion."""
|
||||
import python_repositories.adapters as adapters
|
||||
|
||||
assert {"RedisAdapter", "MinioAdapter"}.issubset(set(dir(adapters)))
|
||||
assert {"RedisAdapter", "MinioAdapter", "PostgresAdapter"}.issubset(set(dir(adapters)))
|
||||
|
||||
|
||||
def test_adapters_getattr_raises_for_unknown() -> None:
|
||||
@@ -138,3 +164,4 @@ def test_top_level_dir_exposes_lazy_exports() -> None:
|
||||
"""dir(python_repositories) includes lazy adapter names for tab completion."""
|
||||
assert "RedisAdapter" in dir(python_repositories)
|
||||
assert "MinioAdapter" in dir(python_repositories)
|
||||
assert "PostgresAdapter" in dir(python_repositories)
|
||||
|
||||
Reference in New Issue
Block a user