pssecret-server/tests/conftest.py

38 lines
892 B
Python

from collections.abc import AsyncGenerator
import pytest
from fastapi.testclient import TestClient
from pydantic_settings import SettingsConfigDict
from redis import asyncio as aioredis
from pssecret_server.main import app
from pssecret_server.settings import Settings, get_settings
class TestSettings(Settings):
model_config = SettingsConfigDict(env_file=".test.env")
@pytest.fixture
def settings() -> Settings:
return TestSettings()
@pytest.fixture()
async def redis_server(settings: Settings) -> AsyncGenerator[aioredis.Redis]:
redis = await aioredis.from_url(str(settings.redis_url))
yield redis
await redis.flushdb()
def get_test_settings() -> Settings:
return TestSettings()
@pytest.fixture(scope="session")
def client() -> TestClient:
client_ = TestClient(app)
app.dependency_overrides[get_settings] = get_test_settings
return client_