mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Merge branch 'dev-3.x' into dev-3.x-flat-package
# Conflicts: # tests/test_filters/test_state.py
This commit is contained in:
commit
01e5b3e456
10 changed files with 133 additions and 11 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.methods import Request, SendChatAction
|
||||
from aiogram.types import ChatAction
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
|
@ -22,3 +23,12 @@ class TestSendChatAction:
|
|||
request: Request = bot.get_request()
|
||||
assert request.method == "sendChatAction"
|
||||
assert response == prepare_result.result
|
||||
|
||||
async def test_chat_action_class(self, bot: MockedBot):
|
||||
prepare_result = bot.add_result_for(SendChatAction, ok=True, result=True)
|
||||
|
||||
response: bool = await bot.send_chat_action(chat_id=42, action=ChatAction.TYPING)
|
||||
request: Request = bot.get_request()
|
||||
assert request.method == "sendChatAction"
|
||||
assert request.data["action"] == "typing"
|
||||
assert response == prepare_result.result
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
from copy import copy
|
||||
from inspect import isclass
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram.dispatcher.event.handler import FilterObject
|
||||
from aiogram.filters import StateFilter
|
||||
from aiogram.fsm.state import State, StatesGroup
|
||||
from aiogram.types import Update
|
||||
|
|
@ -50,3 +52,23 @@ class TestStateFilter:
|
|||
async def test_filter(self, state, current_state, result):
|
||||
f = StateFilter(state=state)
|
||||
assert bool(await f(obj=Update(update_id=42), raw_state=current_state)) is result
|
||||
|
||||
@pytestmark
|
||||
async def test_create_filter_from_state(self):
|
||||
FilterObject(callback=State(state="state"))
|
||||
|
||||
@pytestmark
|
||||
async def test_state_copy(self):
|
||||
class SG(StatesGroup):
|
||||
state = State()
|
||||
|
||||
assert SG.state == copy(SG.state)
|
||||
|
||||
assert SG.state == "SG:state"
|
||||
assert "SG:state" == SG.state
|
||||
|
||||
assert State() == State()
|
||||
assert SG.state != 1
|
||||
|
||||
states = {SG.state: "OK"}
|
||||
assert states.get(copy(SG.state)) == "OK"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue