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>
28 lines
871 B
Python
28 lines
871 B
Python
"""Unit tests for RedisConfig."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from python_repositories.config import RedisConfig
|
|
|
|
|
|
def test_from_env_loads_uri(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setenv("REDIS_URI", "redis://example:6379")
|
|
config = RedisConfig.from_env(use_dotenv=False)
|
|
assert config.uri == "redis://example:6379"
|
|
|
|
|
|
def test_from_env_raises_when_uri_missing(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.delenv("REDIS_URI", raising=False)
|
|
with pytest.raises(Exception):
|
|
RedisConfig.from_env(use_dotenv=False)
|
|
|
|
|
|
def test_from_env_respects_custom_env_var_name(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
monkeypatch.setenv("CUSTOM_REDIS_URI", "redis://custom:6379")
|
|
config = RedisConfig.from_env("CUSTOM_REDIS_URI", use_dotenv=False)
|
|
assert config.uri == "redis://custom:6379"
|