pssecret-server/tests/conftest.py

46 lines
1 KiB
Python
Raw Normal View History

from collections.abc import AsyncGenerator
2025-01-03 14:28:15 +00:00
from cryptography.fernet import Fernet
import pytest
from fastapi.testclient import TestClient
from pydantic_settings import SettingsConfigDict
from redis import asyncio as aioredis
2025-01-03 14:28:15 +00:00
from pssecret_server.fernet import get_fernet
2025-01-01 19:01:10 +00:00
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()
2025-01-03 14:28:15 +00:00
@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_