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
@@ -2,29 +2,46 @@
|
||||
|
||||
from collections.abc import Generator
|
||||
from io import BytesIO
|
||||
import os
|
||||
import random
|
||||
|
||||
import pytest
|
||||
|
||||
from python_repositories.examples.artifact_object_repository import (
|
||||
ArtifactObjectRepository,
|
||||
)
|
||||
from python_repositories.examples.user_json_repository import UserJsonRepository
|
||||
|
||||
pytestmark = pytest.mark.integration
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def set_example_env(
|
||||
redis_container: str,
|
||||
minio_container: dict[str, str],
|
||||
) -> Generator[None, None, None]:
|
||||
"""Set env vars so example repositories can use from_env() defaults."""
|
||||
env_vars = {"REDIS_URI": redis_container, **minio_container}
|
||||
for key, value in env_vars.items():
|
||||
os.environ[key] = value
|
||||
yield
|
||||
for key in env_vars:
|
||||
_ = os.environ.pop(key, default=None)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def user_data() -> Generator[dict[str, str]]:
|
||||
def user_data() -> Generator[dict[str, str], None, None]:
|
||||
"""Provide sample user data for tests."""
|
||||
yield {"name": "Alice", "email": "[email protected]"}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def artifact_data() -> Generator[BytesIO]:
|
||||
def artifact_data() -> Generator[BytesIO, None, None]:
|
||||
"""Provide sample artifact data for tests."""
|
||||
yield BytesIO(random.randbytes(2**20))
|
||||
|
||||
|
||||
def test_user_json_repository_save_and_get(
|
||||
redis_container: str,
|
||||
user_data: dict[str, str],
|
||||
) -> None:
|
||||
"""Test that UserJsonRepository can save and retrieve a user."""
|
||||
@@ -34,7 +51,6 @@ def test_user_json_repository_save_and_get(
|
||||
|
||||
|
||||
def test_user_json_repository_delete(
|
||||
redis_container: str,
|
||||
user_data: dict[str, str],
|
||||
) -> None:
|
||||
"""Test that UserJsonRepository can delete a user."""
|
||||
@@ -45,7 +61,6 @@ def test_user_json_repository_delete(
|
||||
|
||||
|
||||
def test_artifact_object_repository_store_and_get(
|
||||
minio_container: dict[str, str],
|
||||
artifact_data: BytesIO,
|
||||
) -> None:
|
||||
"""Test that ArtifactObjectRepository can store and retrieve an artifact."""
|
||||
|
||||
Reference in New Issue
Block a user