mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Fixed tests, covered flags and events isolation modules
This commit is contained in:
parent
84be7d8323
commit
4257f7db57
17 changed files with 298 additions and 33 deletions
|
|
@ -4,9 +4,13 @@ import pytest
|
|||
from _pytest.config import UsageError
|
||||
from aioredis.connection import parse_url as parse_redis_url
|
||||
|
||||
from aiogram import Bot
|
||||
from aiogram.dispatcher.fsm.storage.memory import MemoryStorage
|
||||
from aiogram.dispatcher.fsm.storage.redis import RedisStorage
|
||||
from aiogram import Bot, Dispatcher
|
||||
from aiogram.dispatcher.fsm.storage.memory import (
|
||||
DisabledEventIsolation,
|
||||
MemoryStorage,
|
||||
SimpleEventIsolation,
|
||||
)
|
||||
from aiogram.dispatcher.fsm.storage.redis import RedisEventIsolation, RedisStorage
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
DATA_DIR = Path(__file__).parent / "data"
|
||||
|
|
@ -67,6 +71,42 @@ async def memory_storage():
|
|||
await storage.close()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.mark.redis
|
||||
async def redis_isolation(redis_server):
|
||||
if not redis_server:
|
||||
pytest.skip("Redis is not available here")
|
||||
isolation = RedisEventIsolation.from_url(redis_server)
|
||||
try:
|
||||
await isolation.redis.info()
|
||||
except ConnectionError as e:
|
||||
pytest.skip(str(e))
|
||||
try:
|
||||
yield isolation
|
||||
finally:
|
||||
conn = await isolation.redis
|
||||
await conn.flushdb()
|
||||
await isolation.close()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
async def lock_isolation():
|
||||
isolation = SimpleEventIsolation()
|
||||
try:
|
||||
yield isolation
|
||||
finally:
|
||||
await isolation.close()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
async def disabled_isolation():
|
||||
isolation = DisabledEventIsolation()
|
||||
try:
|
||||
yield isolation
|
||||
finally:
|
||||
await isolation.close()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def bot():
|
||||
bot = MockedBot()
|
||||
|
|
@ -75,3 +115,13 @@ def bot():
|
|||
yield bot
|
||||
finally:
|
||||
Bot.reset_current(token)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
async def dispatcher():
|
||||
dp = Dispatcher()
|
||||
await dp.emit_startup()
|
||||
try:
|
||||
yield dp
|
||||
finally:
|
||||
await dp.emit_shutdown()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue