mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
Cover base and memory storage
This commit is contained in:
parent
becbcecaf1
commit
03ccebd8be
3 changed files with 43 additions and 5 deletions
0
tests/test_dispatcher/fsm/storage/__init__.py
Normal file
0
tests/test_dispatcher/fsm/storage/__init__.py
Normal file
34
tests/test_dispatcher/fsm/storage/test_base.py
Normal file
34
tests/test_dispatcher/fsm/storage/test_base.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.dispatcher.fsm.storage.memory import MemoryStorage, MemoryStorageRecord
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def storage():
|
||||
return MemoryStorage()
|
||||
|
||||
|
||||
class TestMemoryStorage:
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_state(self, storage: MemoryStorage):
|
||||
assert await storage.get_state(chat_id=-42, user_id=42) is None
|
||||
|
||||
await storage.set_state(chat_id=-42, user_id=42, state="state")
|
||||
assert await storage.get_state(chat_id=-42, user_id=42) == "state"
|
||||
|
||||
assert -42 in storage.storage
|
||||
assert 42 in storage.storage[-42]
|
||||
assert isinstance(storage.storage[-42][42], MemoryStorageRecord)
|
||||
assert storage.storage[-42][42].state == "state"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_data(self, storage: MemoryStorage):
|
||||
assert await storage.get_data(chat_id=-42, user_id=42) == {}
|
||||
|
||||
await storage.set_data(chat_id=-42, user_id=42, data={"foo": "bar"})
|
||||
assert await storage.get_data(chat_id=-42, user_id=42) == {"foo": "bar"}
|
||||
|
||||
assert -42 in storage.storage
|
||||
assert 42 in storage.storage[-42]
|
||||
assert isinstance(storage.storage[-42][42], MemoryStorageRecord)
|
||||
assert storage.storage[-42][42].data == {"foo": "bar"}
|
||||
Loading…
Add table
Add a link
Reference in a new issue