28 lines
898 B
Python
28 lines
898 B
Python
"""All tests use disposable databases and a synthetic Telegram token."""
|
|
import os
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import pytest_asyncio
|
|
|
|
_temporary = tempfile.TemporaryDirectory(prefix="lottery-tests-")
|
|
os.environ["DATABASE_URL"] = os.getenv("TEST_DATABASE_URL") or (
|
|
"sqlite+aiosqlite:///" + (Path(_temporary.name) / "test.db").as_posix()
|
|
)
|
|
os.environ["BOT_TOKEN"] = "123456:TEST_TOKEN_FOR_ISOLATED_TESTS"
|
|
os.environ["ADMIN_IDS"] = "900001"
|
|
os.environ["CASHIER_IDS"] = "900002"
|
|
os.environ["REDIS_URL"] = ""
|
|
|
|
from src.core.database import Base, engine, async_session_maker
|
|
from src.core import models
|
|
|
|
|
|
@pytest_asyncio.fixture(autouse=True)
|
|
async def database():
|
|
async with engine.begin() as connection:
|
|
await connection.run_sync(Base.metadata.drop_all)
|
|
await connection.run_sync(Base.metadata.create_all)
|
|
yield async_session_maker
|
|
await engine.dispose()
|