Fix account enrollment and operator callback flows with Redis scenarios
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""All tests use disposable databases and a synthetic Telegram token."""
|
||||
import os
|
||||
import tempfile
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest_asyncio
|
||||
@@ -12,7 +13,7 @@ os.environ["DATABASE_URL"] = os.getenv("TEST_DATABASE_URL") or (
|
||||
os.environ["BOT_TOKEN"] = "123456:TEST_TOKEN_FOR_ISOLATED_TESTS"
|
||||
os.environ["ADMIN_IDS"] = "900001"
|
||||
os.environ["CASHIER_IDS"] = "900002"
|
||||
os.environ["REDIS_URL"] = ""
|
||||
os.environ["REDIS_URL"] = os.getenv("TEST_REDIS_URL", "")
|
||||
|
||||
from src.core.database import Base, engine, async_session_maker
|
||||
from src.core import models
|
||||
@@ -20,8 +21,18 @@ from src.core import models
|
||||
|
||||
@pytest_asyncio.fixture(autouse=True)
|
||||
async def database():
|
||||
if os.getenv("TEST_REDIS_URL"):
|
||||
from redis.asyncio import Redis
|
||||
redis = Redis.from_url(os.environ["TEST_REDIS_URL"])
|
||||
# Only the synthetic bot's FSM namespace in the disposable test service.
|
||||
keys = [key async for key in redis.scan_iter(match="fsm:123456:*")]
|
||||
if keys:
|
||||
await redis.delete(*keys)
|
||||
await redis.aclose()
|
||||
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
|
||||
if os.getenv("TEST_REDIS_URL") and "main" in sys.modules:
|
||||
await sys.modules["main"].dp.storage.close()
|
||||
await engine.dispose()
|
||||
|
||||
Reference in New Issue
Block a user