mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Backport and improvements (#601)
* Backport RedisStorage, deep-linking * Allow prereleases for aioredis * Bump dependencies * Correctly skip Redis tests on Windows * Reformat tests code and bump Makefile
This commit is contained in:
parent
32bc05130f
commit
83d6ab48c5
43 changed files with 1004 additions and 327 deletions
|
|
@ -2,27 +2,28 @@ import pytest
|
|||
|
||||
from aiogram.dispatcher.fsm.context import FSMContext
|
||||
from aiogram.dispatcher.fsm.storage.memory import MemoryStorage
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def state():
|
||||
def state(bot: MockedBot):
|
||||
storage = MemoryStorage()
|
||||
ctx = storage.storage[-42][42]
|
||||
ctx = storage.storage[bot][-42][42]
|
||||
ctx.state = "test"
|
||||
ctx.data = {"foo": "bar"}
|
||||
return FSMContext(storage=storage, user_id=-42, chat_id=42)
|
||||
return FSMContext(bot=bot, storage=storage, user_id=-42, chat_id=42)
|
||||
|
||||
|
||||
class TestFSMContext:
|
||||
@pytest.mark.asyncio
|
||||
async def test_address_mapping(self):
|
||||
async def test_address_mapping(self, bot: MockedBot):
|
||||
storage = MemoryStorage()
|
||||
ctx = storage.storage[-42][42]
|
||||
ctx = storage.storage[bot][-42][42]
|
||||
ctx.state = "test"
|
||||
ctx.data = {"foo": "bar"}
|
||||
state = FSMContext(storage=storage, chat_id=-42, user_id=42)
|
||||
state2 = FSMContext(storage=storage, chat_id=42, user_id=42)
|
||||
state3 = FSMContext(storage=storage, chat_id=69, user_id=69)
|
||||
state = FSMContext(bot=bot, storage=storage, chat_id=-42, user_id=42)
|
||||
state2 = FSMContext(bot=bot, storage=storage, chat_id=42, user_id=42)
|
||||
state3 = FSMContext(bot=bot, storage=storage, chat_id=69, user_id=69)
|
||||
|
||||
assert await state.get_state() == "test"
|
||||
assert await state2.get_state() is None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue