-
-
Notifications
You must be signed in to change notification settings - Fork 806
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
becbcec
commit 03ccebd
Showing
3 changed files
with
43 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"} |