pssecret-server/tests/conftest.py
2025-01-03 15:28:15 +01:00

45 lines
1 KiB
Python

from collections.abc import AsyncGenerator
from cryptography.fernet import Fernet
import pytest
from fastapi.testclient import TestClient
from pydantic_settings import SettingsConfigDict
from redis import asyncio as aioredis
from pssecret_server.fernet import get_fernet
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
def fernet(settings: Settings) -> Fernet:
return get_fernet(settings)
@pytest.fixture(scope="session")
def client() -> TestClient:
client_ = TestClient(app)
app.dependency_overrides[get_settings] = get_test_settings
return client_