mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
add stategroup filter (#659)
This commit is contained in:
parent
71eb5fc44e
commit
04bbc8211c
2 changed files with 41 additions and 6 deletions
|
|
@ -139,8 +139,7 @@ class TestStatesGroup:
|
|||
assert MyGroup.state1 not in MyGroup.MyNestedGroup
|
||||
assert MyGroup.state1 in MyGroup
|
||||
|
||||
# Not working as well
|
||||
# assert MyGroup.MyNestedGroup in MyGroup
|
||||
assert MyGroup.MyNestedGroup in MyGroup
|
||||
|
||||
assert "MyGroup.MyNestedGroup:state1" in MyGroup
|
||||
assert "MyGroup.MyNestedGroup:state1" in MyGroup.MyNestedGroup
|
||||
|
|
@ -150,3 +149,36 @@ class TestStatesGroup:
|
|||
assert 42 not in MyGroup
|
||||
|
||||
assert MyGroup.MyNestedGroup.get_root() is MyGroup
|
||||
|
||||
def test_empty_filter(self):
|
||||
class MyGroup(StatesGroup):
|
||||
pass
|
||||
|
||||
assert str(MyGroup()) == "StatesGroup MyGroup"
|
||||
|
||||
def test_with_state_filter(self):
|
||||
class MyGroup(StatesGroup):
|
||||
state1 = State()
|
||||
state2 = State()
|
||||
|
||||
assert MyGroup()(None, "MyGroup:state1")
|
||||
assert MyGroup()(None, "MyGroup:state2")
|
||||
assert not MyGroup()(None, "MyGroup:state3")
|
||||
|
||||
assert str(MyGroup()) == "StatesGroup MyGroup"
|
||||
|
||||
def test_nested_group_filter(self):
|
||||
class MyGroup(StatesGroup):
|
||||
state1 = State()
|
||||
|
||||
class MyNestedGroup(StatesGroup):
|
||||
state1 = State()
|
||||
|
||||
assert MyGroup()(None, "MyGroup:state1")
|
||||
assert MyGroup()(None, "MyGroup.MyNestedGroup:state1")
|
||||
assert not MyGroup()(None, "MyGroup:state2")
|
||||
assert MyGroup.MyNestedGroup()(None, "MyGroup.MyNestedGroup:state1")
|
||||
assert not MyGroup.MyNestedGroup()(None, "MyGroup:state1")
|
||||
|
||||
assert str(MyGroup()) == "StatesGroup MyGroup"
|
||||
assert str(MyGroup.MyNestedGroup()) == "StatesGroup MyGroup.MyNestedGroup"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue