Implemented mongodb storage

This commit is contained in:
asimaranov 2021-12-15 22:09:00 +03:00
parent 76ae5c4415
commit 3e04d3365e
4 changed files with 121 additions and 1 deletions

View file

@ -6,6 +6,7 @@ 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.mongo import MongoStorage
from aiogram.dispatcher.fsm.storage.redis import RedisStorage
from tests.mocked_bot import MockedBot
@ -67,6 +68,19 @@ async def memory_storage():
await storage.close()
@pytest.fixture()
@pytest.mark.mongo
async def mongo_storage(redis_server):
if not redis_server:
pytest.skip("Mongo is not available here")
storage = MongoStorage.from_url(redis_server)
try:
yield storage
finally:
await storage.close()
@pytest.fixture()
def bot():
bot = MockedBot()

View file

@ -13,7 +13,7 @@ def create_storate_key(bot: MockedBot):
@pytest.mark.parametrize(
"storage",
[pytest.lazy_fixture("redis_storage"), pytest.lazy_fixture("memory_storage")],
[pytest.lazy_fixture("redis_storage"), pytest.lazy_fixture("memory_storage"), pytest.lazy_fixture("mongo_storage")],
)
class TestStorages:
async def test_lock(self, bot: MockedBot, storage: BaseStorage, storage_key: StorageKey):