2025-01-01 18:18:38 +00:00
|
|
|
from collections.abc import AsyncGenerator
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from pydantic_settings import SettingsConfigDict
|
|
|
|
from redis import asyncio as aioredis
|
|
|
|
|
2025-01-01 19:01:10 +00:00
|
|
|
from pssecret_server.main import app
|
|
|
|
from pssecret_server.settings import Settings, get_settings
|
2025-01-01 18:18:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
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_
|