mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
Dev 3.x flat package (#961)
* Move packages * Added changelog * Update examples/echo_bot.py Co-authored-by: Oleg A. <t0rr@mail.ru> * Rename `handler` -> `handlers` * Update __init__.py Co-authored-by: Oleg A. <t0rr@mail.ru>
This commit is contained in:
parent
5e7932ca20
commit
4315ecf1a2
111 changed files with 376 additions and 390 deletions
59
tests/test_fsm/test_context.py
Normal file
59
tests/test_fsm/test_context.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.fsm.storage.base import StorageKey
|
||||
from aiogram.fsm.storage.memory import MemoryStorage
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def state(bot: MockedBot):
|
||||
storage = MemoryStorage()
|
||||
key = StorageKey(user_id=42, chat_id=-42, bot_id=bot.id)
|
||||
ctx = storage.storage[key]
|
||||
ctx.state = "test"
|
||||
ctx.data = {"foo": "bar"}
|
||||
return FSMContext(bot=bot, storage=storage, key=key)
|
||||
|
||||
|
||||
class TestFSMContext:
|
||||
async def test_address_mapping(self, bot: MockedBot):
|
||||
storage = MemoryStorage()
|
||||
ctx = storage.storage[StorageKey(chat_id=-42, user_id=42, bot_id=bot.id)]
|
||||
ctx.state = "test"
|
||||
ctx.data = {"foo": "bar"}
|
||||
state = FSMContext(
|
||||
bot=bot, storage=storage, key=StorageKey(chat_id=-42, user_id=42, bot_id=bot.id)
|
||||
)
|
||||
state2 = FSMContext(
|
||||
bot=bot, storage=storage, key=StorageKey(chat_id=42, user_id=42, bot_id=bot.id)
|
||||
)
|
||||
state3 = FSMContext(
|
||||
bot=bot, storage=storage, key=StorageKey(chat_id=69, user_id=69, bot_id=bot.id)
|
||||
)
|
||||
|
||||
assert await state.get_state() == "test"
|
||||
assert await state2.get_state() is None
|
||||
assert await state3.get_state() is None
|
||||
|
||||
assert await state.get_data() == {"foo": "bar"}
|
||||
assert await state2.get_data() == {}
|
||||
assert await state3.get_data() == {}
|
||||
|
||||
await state2.set_state("experiments")
|
||||
assert await state.get_state() == "test"
|
||||
assert await state3.get_state() is None
|
||||
|
||||
await state3.set_data({"key": "value"})
|
||||
assert await state2.get_data() == {}
|
||||
|
||||
await state.update_data({"key": "value"})
|
||||
assert await state.get_data() == {"foo": "bar", "key": "value"}
|
||||
|
||||
await state.clear()
|
||||
assert await state.get_state() is None
|
||||
assert await state.get_data() == {}
|
||||
|
||||
assert await state2.get_state() == "experiments"
|
||||
Loading…
Add table
Add a link
Reference in a new issue