mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 18:01:04 +00:00
Return DataMixin
This commit is contained in:
parent
a823e275a7
commit
7db1572fd3
2 changed files with 62 additions and 2 deletions
|
|
@ -1,11 +1,45 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.utils.mixins import ContextInstanceMixin
|
||||
from aiogram.utils.mixins import (
|
||||
ContextInstanceMixin,
|
||||
DataMixin,
|
||||
)
|
||||
|
||||
|
||||
class ContextObject(ContextInstanceMixin['ContextObject']):
|
||||
pass
|
||||
|
||||
|
||||
class DataObject(DataMixin):
|
||||
pass
|
||||
|
||||
|
||||
class TestDataMixin:
|
||||
def test_store_value(self):
|
||||
obj = DataObject()
|
||||
obj["foo"] = 42
|
||||
|
||||
assert "foo" in obj
|
||||
assert obj["foo"] == 42
|
||||
assert len(obj.data) == 1
|
||||
|
||||
def test_remove_value(self):
|
||||
obj = DataObject()
|
||||
obj["foo"] = 42
|
||||
del obj["foo"]
|
||||
|
||||
assert "key" not in obj
|
||||
assert len(obj.data) == 0
|
||||
|
||||
def test_getter(self):
|
||||
obj = DataObject()
|
||||
obj["foo"] = 42
|
||||
|
||||
assert obj.get("foo") == 42
|
||||
assert obj.get("bar") is None
|
||||
assert obj.get("baz", "test") == "test"
|
||||
|
||||
|
||||
class TestContextInstanceMixin:
|
||||
def test_empty(self):
|
||||
obj = ContextObject()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue