Add config and client injection with test reorganization.
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 <[email protected]>
This commit is contained in:
co-authored by
Cursor
parent
366831ac52
commit
7991dabdbc
@@ -43,6 +43,38 @@ Requires Redis with the RedisJSON module (e.g. redis-stack).
|
||||
| `MINIO_SECRET_KEY` | Secret key |
|
||||
| `MINIO_BUCKET` | Bucket name (created on connect if missing) |
|
||||
|
||||
Copy [`.env.example`](.env.example) to `.env` for local development. `RedisConfig.from_env()` and `MinioConfig.from_env()` load `.env` automatically when resolving configuration from the environment.
|
||||
|
||||
## Configuration injection
|
||||
|
||||
Adapters accept optional `config` and `client` keyword arguments for explicit setup and testing:
|
||||
|
||||
```python
|
||||
from python_repositories import RedisAdapter, RedisConfig, MinioAdapter, MinioConfig
|
||||
|
||||
redis = RedisAdapter(config=RedisConfig(uri="redis://localhost:6379"))
|
||||
minio = MinioAdapter(
|
||||
config=MinioConfig(
|
||||
endpoint="localhost:9000",
|
||||
access_key="minioadmin",
|
||||
secret_key="minioadmin",
|
||||
bucket="my-bucket",
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
When both `config` and `client` are provided, `connect()` skips client creation (the caller owns the client lifecycle). `config` is required whenever `client` is injected.
|
||||
|
||||
Load a `.env` file explicitly:
|
||||
|
||||
```python
|
||||
from python_repositories import load_dotenv
|
||||
|
||||
load_dotenv() # optional — from_env() also loads .env by default
|
||||
```
|
||||
|
||||
Calling `RedisAdapter()` or `MinioAdapter()` with no arguments still loads configuration from environment variables (and `.env` if present).
|
||||
|
||||
## Quick start
|
||||
|
||||
### JSON documents with Redis
|
||||
@@ -93,9 +125,12 @@ from python_repositories import (
|
||||
ConnectionAwareInterface,
|
||||
ContextAwareInterface,
|
||||
JsonRepositoryInterface,
|
||||
MinioAdapter,
|
||||
MinioConfig,
|
||||
ObjectRepositoryInterface,
|
||||
RedisAdapter,
|
||||
MinioAdapter,
|
||||
RedisConfig,
|
||||
load_dotenv,
|
||||
)
|
||||
```
|
||||
|
||||
@@ -104,9 +139,13 @@ from python_repositories import (
|
||||
```bash
|
||||
uv sync --all-extras
|
||||
uv run pre-commit install # once per clone — runs hooks on git commit
|
||||
uv run pytest tests/integration/ -v
|
||||
uv run pytest tests/unit/ -v # fast, no Docker
|
||||
uv run pytest -m "not integration" -v # all non-Docker tests
|
||||
uv run pytest -v # full suite (requires Docker)
|
||||
```
|
||||
|
||||
Integration tests are marked with `@pytest.mark.integration` and require Docker (testcontainers). Run unit tests alone for quick local feedback.
|
||||
|
||||
`pre-commit` is included in the dev dependency group. `uv sync` installs the CLI, but git does not run hooks until you install them with `pre-commit install` (one time per clone). After that, commits run the checks defined in [`.pre-commit-config.yaml`](.pre-commit-config.yaml) (ruff, mypy, pyupgrade, prettier, and general file hygiene).
|
||||
|
||||
To run all hooks manually without committing:
|
||||
@@ -115,8 +154,6 @@ To run all hooks manually without committing:
|
||||
uv run pre-commit run --all-files
|
||||
```
|
||||
|
||||
Integration tests require Docker (testcontainers).
|
||||
|
||||
## Releases
|
||||
|
||||
Releases are automated when a pull request is merged to `main`. CI reads the **merged PR title** to decide whether and how to bump the version.
|
||||
|
||||
Reference in New Issue
Block a user