[minor] Add config and client injection with test reorganization #25

Merged
brian merged 2 commits from cursor/config-client-injection into main 2026-07-06 20:51:03 +02:00
Owner

Summary

Adds typed configuration objects and optional dependency injection to adapters, making tests simpler while keeping the existing env-var defaults for production.

  • Config package (python_repositories/config/): RedisConfig, MinioConfig, and load_dotenv() with .env support via python-dotenv
  • Adapter injection: RedisAdapter and MinioAdapter accept optional config= and client= keyword arguments; injected clients are not closed on disconnect()
  • Backward compatible: RedisAdapter() / MinioAdapter() still load from environment variables (and .env when present)
  • Test reorganization:
    • Interface and adapter unit tests moved/renamed to follow 1:1 source-file naming
    • Integration tests marked with @pytest.mark.integration
    • Shared test constants in tests/conftest.py; mock fixtures in tests/unit/conftest.py
    • Integration tests use explicit config objects instead of global os.environ mutation
  • Docs: README updated with config injection, .env, and pytest marker usage; added .env.example

Test plan

  • uv run pytest tests/unit/ -v — 54 passed, no Docker
  • uv run pytest -m "not integration" -v — unit tests from repo root
  • uv run pytest -v — full suite, 101 passed (requires Docker)
  • uv run mypy python_repositories/ — clean
  • Pre-commit hooks pass (ruff, mypy, pyupgrade, prettier)
## Summary Adds typed configuration objects and optional dependency injection to adapters, making tests simpler while keeping the existing env-var defaults for production. - **Config package** (`python_repositories/config/`): `RedisConfig`, `MinioConfig`, and `load_dotenv()` with `.env` support via `python-dotenv` - **Adapter injection**: `RedisAdapter` and `MinioAdapter` accept optional `config=` and `client=` keyword arguments; injected clients are not closed on `disconnect()` - **Backward compatible**: `RedisAdapter()` / `MinioAdapter()` still load from environment variables (and `.env` when present) - **Test reorganization**: - Interface and adapter unit tests moved/renamed to follow 1:1 source-file naming - Integration tests marked with `@pytest.mark.integration` - Shared test constants in `tests/conftest.py`; mock fixtures in `tests/unit/conftest.py` - Integration tests use explicit config objects instead of global `os.environ` mutation - **Docs**: README updated with config injection, `.env`, and pytest marker usage; added `.env.example` ## Test plan - [x] `uv run pytest tests/unit/ -v` — 54 passed, no Docker - [x] `uv run pytest -m "not integration" -v` — unit tests from repo root - [x] `uv run pytest -v` — full suite, 101 passed (requires Docker) - [x] `uv run mypy python_repositories/` — clean - [x] Pre-commit hooks pass (ruff, mypy, pyupgrade, prettier)
Member

Test Coverage Report:

============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-9.1.1, pluggy-1.6.0
rootdir: /workspace/brian/python-repositories
configfile: pyproject.toml
testpaths: tests
plugins: cov-7.1.0, anyio-4.14.1
collected 101 items

tests/integration/examples_test.py ...                                   [  2%]
tests/integration/minio_adapter_test.py .........................        [ 27%]
tests/integration/redis_adapter_test.py ...................              [ 46%]
tests/unit/adapters_test.py .......                                      [ 53%]
tests/unit/connection_aware_adapter_test.py .............                [ 66%]
tests/unit/connection_aware_interface_test.py ...                        [ 69%]
tests/unit/context_aware_interface_test.py ..                            [ 71%]
tests/unit/dotenv_loader_test.py ..                                      [ 73%]
tests/unit/json_repository_interface_test.py ....                        [ 77%]
tests/unit/minio_adapter_test.py ......                                  [ 83%]
tests/unit/minio_config_test.py ..                                       [ 85%]
tests/unit/object_repository_interface_test.py ....                      [ 89%]
tests/unit/redis_adapter_test.py ........                                [ 97%]
tests/unit/redis_config_test.py ...                                      [100%]

================================ tests coverage ================================
_______________ coverage: platform linux, python 3.12.3-final-0 ________________

Name                                                            Stmts   Miss  Cover   Missing
---------------------------------------------------------------------------------------------
python_repositories/__init__.py                                    12      1    92%   43
python_repositories/adapters/__init__.py                           13      2    85%   37, 42
python_repositories/adapters/connection_aware_adapter.py           45      0   100%
python_repositories/adapters/minio_adapter.py                     119      8    93%   61-69, 74
python_repositories/adapters/redis_adapter.py                      97     11    89%   55-66, 68-70
python_repositories/config/__init__.py                              4      0   100%
python_repositories/config/dotenv_loader.py                         7      0   100%
python_repositories/config/minio_config.py                         19      0   100%
python_repositories/config/redis_config.py                         14      0   100%
python_repositories/examples/__init__.py                            0      0   100%
python_repositories/examples/artifact_object_repository.py          9      0   100%
python_repositories/examples/user_json_repository.py               10      0   100%
python_repositories/interfaces/__init__.py                          5      0   100%
python_repositories/interfaces/connection_aware_interface.py        8      0   100%
python_repositories/interfaces/context_aware_interface.py           8      0   100%
python_repositories/interfaces/json_repository_interface.py        10      0   100%
python_repositories/interfaces/object_repository_interface.py      11      0   100%
---------------------------------------------------------------------------------------------
TOTAL                                                             391     22    94%
============================= 101 passed in 29.47s =============================

**Test Coverage Report:** ``` ============================= test session starts ============================== platform linux -- Python 3.12.3, pytest-9.1.1, pluggy-1.6.0 rootdir: /workspace/brian/python-repositories configfile: pyproject.toml testpaths: tests plugins: cov-7.1.0, anyio-4.14.1 collected 101 items tests/integration/examples_test.py ... [ 2%] tests/integration/minio_adapter_test.py ......................... [ 27%] tests/integration/redis_adapter_test.py ................... [ 46%] tests/unit/adapters_test.py ....... [ 53%] tests/unit/connection_aware_adapter_test.py ............. [ 66%] tests/unit/connection_aware_interface_test.py ... [ 69%] tests/unit/context_aware_interface_test.py .. [ 71%] tests/unit/dotenv_loader_test.py .. [ 73%] tests/unit/json_repository_interface_test.py .... [ 77%] tests/unit/minio_adapter_test.py ...... [ 83%] tests/unit/minio_config_test.py .. [ 85%] tests/unit/object_repository_interface_test.py .... [ 89%] tests/unit/redis_adapter_test.py ........ [ 97%] tests/unit/redis_config_test.py ... [100%] ================================ tests coverage ================================ _______________ coverage: platform linux, python 3.12.3-final-0 ________________ Name Stmts Miss Cover Missing --------------------------------------------------------------------------------------------- python_repositories/__init__.py 12 1 92% 43 python_repositories/adapters/__init__.py 13 2 85% 37, 42 python_repositories/adapters/connection_aware_adapter.py 45 0 100% python_repositories/adapters/minio_adapter.py 119 8 93% 61-69, 74 python_repositories/adapters/redis_adapter.py 97 11 89% 55-66, 68-70 python_repositories/config/__init__.py 4 0 100% python_repositories/config/dotenv_loader.py 7 0 100% python_repositories/config/minio_config.py 19 0 100% python_repositories/config/redis_config.py 14 0 100% python_repositories/examples/__init__.py 0 0 100% python_repositories/examples/artifact_object_repository.py 9 0 100% python_repositories/examples/user_json_repository.py 10 0 100% python_repositories/interfaces/__init__.py 5 0 100% python_repositories/interfaces/connection_aware_interface.py 8 0 100% python_repositories/interfaces/context_aware_interface.py 8 0 100% python_repositories/interfaces/json_repository_interface.py 10 0 100% python_repositories/interfaces/object_repository_interface.py 11 0 100% --------------------------------------------------------------------------------------------- TOTAL 391 22 94% ============================= 101 passed in 29.47s ============================= ```
brian added 2 commits 2026-07-06 20:45:41 +02:00
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>
Load MINIO_SECURE from env and replace adapter asserts with explicit errors.
Code Quality Pipeline / code-quality (pull_request) Successful in 32s
PR Title Check / check-title (pull_request) Successful in 6s
Test Python Package / test (pull_request) Successful in 57s
3aa91280ec
Default TLS to enabled for production MinIO setups while keeping local and integration tests on plain HTTP via explicit secure=false configuration.

Co-authored-by: Cursor <cursoragent@cursor.com>
brian force-pushed cursor/config-client-injection from 5e32787b90 to 3aa91280ec 2026-07-06 20:45:41 +02:00 Compare
Member

Test Coverage Report:

============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-9.1.1, pluggy-1.6.0
rootdir: /workspace/brian/python-repositories
configfile: pyproject.toml
testpaths: tests
plugins: cov-7.1.0, anyio-4.14.1
collected 109 items

tests/integration/examples_test.py ...                                   [  2%]
tests/integration/minio_adapter_test.py .........................        [ 25%]
tests/integration/redis_adapter_test.py ...................              [ 43%]
tests/unit/adapters_test.py .......                                      [ 49%]
tests/unit/connection_aware_adapter_test.py .............                [ 61%]
tests/unit/connection_aware_interface_test.py ...                        [ 64%]
tests/unit/context_aware_interface_test.py ..                            [ 66%]
tests/unit/dotenv_loader_test.py ..                                      [ 67%]
tests/unit/json_repository_interface_test.py ....                        [ 71%]
tests/unit/minio_adapter_test.py ......                                  [ 77%]
tests/unit/minio_config_test.py ..........                               [ 86%]
tests/unit/object_repository_interface_test.py ....                      [ 89%]
tests/unit/redis_adapter_test.py ........                                [ 97%]
tests/unit/redis_config_test.py ...                                      [100%]

================================ tests coverage ================================
_______________ coverage: platform linux, python 3.12.3-final-0 ________________

Name                                                            Stmts   Miss  Cover   Missing
---------------------------------------------------------------------------------------------
python_repositories/__init__.py                                    12      1    92%   43
python_repositories/adapters/__init__.py                           13      2    85%   37, 42
python_repositories/adapters/connection_aware_adapter.py           45      0   100%
python_repositories/adapters/minio_adapter.py                     119      8    93%   62-70, 75
python_repositories/adapters/redis_adapter.py                      96     11    89%   54-65, 67-69
python_repositories/config/__init__.py                              4      0   100%
python_repositories/config/dotenv_loader.py                         7      0   100%
python_repositories/config/minio_config.py                         31      0   100%
python_repositories/config/redis_config.py                         14      0   100%
python_repositories/examples/__init__.py                            0      0   100%
python_repositories/examples/artifact_object_repository.py          9      0   100%
python_repositories/examples/user_json_repository.py               10      0   100%
python_repositories/interfaces/__init__.py                          5      0   100%
python_repositories/interfaces/connection_aware_interface.py        8      0   100%
python_repositories/interfaces/context_aware_interface.py           8      0   100%
python_repositories/interfaces/json_repository_interface.py        10      0   100%
python_repositories/interfaces/object_repository_interface.py      11      0   100%
---------------------------------------------------------------------------------------------
TOTAL                                                             402     22    95%
============================= 109 passed in 39.55s =============================

**Test Coverage Report:** ``` ============================= test session starts ============================== platform linux -- Python 3.12.3, pytest-9.1.1, pluggy-1.6.0 rootdir: /workspace/brian/python-repositories configfile: pyproject.toml testpaths: tests plugins: cov-7.1.0, anyio-4.14.1 collected 109 items tests/integration/examples_test.py ... [ 2%] tests/integration/minio_adapter_test.py ......................... [ 25%] tests/integration/redis_adapter_test.py ................... [ 43%] tests/unit/adapters_test.py ....... [ 49%] tests/unit/connection_aware_adapter_test.py ............. [ 61%] tests/unit/connection_aware_interface_test.py ... [ 64%] tests/unit/context_aware_interface_test.py .. [ 66%] tests/unit/dotenv_loader_test.py .. [ 67%] tests/unit/json_repository_interface_test.py .... [ 71%] tests/unit/minio_adapter_test.py ...... [ 77%] tests/unit/minio_config_test.py .......... [ 86%] tests/unit/object_repository_interface_test.py .... [ 89%] tests/unit/redis_adapter_test.py ........ [ 97%] tests/unit/redis_config_test.py ... [100%] ================================ tests coverage ================================ _______________ coverage: platform linux, python 3.12.3-final-0 ________________ Name Stmts Miss Cover Missing --------------------------------------------------------------------------------------------- python_repositories/__init__.py 12 1 92% 43 python_repositories/adapters/__init__.py 13 2 85% 37, 42 python_repositories/adapters/connection_aware_adapter.py 45 0 100% python_repositories/adapters/minio_adapter.py 119 8 93% 62-70, 75 python_repositories/adapters/redis_adapter.py 96 11 89% 54-65, 67-69 python_repositories/config/__init__.py 4 0 100% python_repositories/config/dotenv_loader.py 7 0 100% python_repositories/config/minio_config.py 31 0 100% python_repositories/config/redis_config.py 14 0 100% python_repositories/examples/__init__.py 0 0 100% python_repositories/examples/artifact_object_repository.py 9 0 100% python_repositories/examples/user_json_repository.py 10 0 100% python_repositories/interfaces/__init__.py 5 0 100% python_repositories/interfaces/connection_aware_interface.py 8 0 100% python_repositories/interfaces/context_aware_interface.py 8 0 100% python_repositories/interfaces/json_repository_interface.py 10 0 100% python_repositories/interfaces/object_repository_interface.py 11 0 100% --------------------------------------------------------------------------------------------- TOTAL 402 22 95% ============================= 109 passed in 39.55s ============================= ```
brian merged commit 918e5e6ba4 into main 2026-07-06 20:51:03 +02:00
brian deleted branch cursor/config-client-injection 2026-07-06 20:51:03 +02:00
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: lille-vemmelund/python-repositories#25