31 lines
870 B
Python
31 lines
870 B
Python
import asyncio
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from sqlalchemy import event
|
|
|
|
|
|
@pytest.fixture
|
|
def client(tmp_path: Path):
|
|
os.environ["DODO_DATABASE_URL"] = f"sqlite+aiosqlite:///{tmp_path / 'test.db'}"
|
|
os.environ["DODO_AUTO_CREATE_SCHEMA"] = "true"
|
|
from backend.config import get_settings
|
|
get_settings.cache_clear()
|
|
from backend.db import get_engine, reset_engine
|
|
reset_engine()
|
|
engine = get_engine()
|
|
|
|
@event.listens_for(engine.sync_engine, "connect")
|
|
def enable_sqlite_foreign_keys(dbapi_connection, _):
|
|
cursor = dbapi_connection.cursor()
|
|
cursor.execute("PRAGMA foreign_keys=ON")
|
|
cursor.close()
|
|
|
|
from backend.main import app
|
|
with TestClient(app) as test_client:
|
|
yield test_client
|
|
asyncio.run(engine.dispose())
|
|
reset_engine()
|