mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Refactor dispatcher. Update docs. Fix tests.
This commit is contained in:
parent
9539c4e2fd
commit
d3b488e16d
290 changed files with 2153 additions and 1780 deletions
|
|
@ -3,9 +3,9 @@ from typing import TYPE_CHECKING, AsyncGenerator, Deque, Optional, Type
|
|||
|
||||
from aiogram import Bot
|
||||
from aiogram.client.session.base import BaseSession
|
||||
from aiogram.api.methods import TelegramMethod
|
||||
from aiogram.api.methods.base import Request, Response, T
|
||||
from aiogram.api.types import UNSET
|
||||
from aiogram.methods import TelegramMethod
|
||||
from aiogram.methods.base import Request, Response, T
|
||||
from aiogram.types import UNSET
|
||||
|
||||
|
||||
class MockedSession(BaseSession):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from aiogram.api.client.telegram import PRODUCTION
|
||||
from aiogram.client.telegram import PRODUCTION
|
||||
|
||||
|
||||
class TestAPIServer:
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ from aresponses import ResponsesMockServer
|
|||
|
||||
from aiogram import Bot
|
||||
from aiogram.client.session.aiohttp import AiohttpSession
|
||||
from aiogram.api.methods import GetFile, GetMe
|
||||
from aiogram.api.types import File, PhotoSize
|
||||
from aiogram.methods import GetFile, GetMe
|
||||
from aiogram.types import File, PhotoSize
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
try:
|
||||
|
|
@ -38,7 +38,7 @@ class TestBot:
|
|||
method = GetMe()
|
||||
|
||||
with patch(
|
||||
"aiogram.api.client.session.aiohttp.AiohttpSession.make_request",
|
||||
"aiogram.client.session.aiohttp.AiohttpSession.make_request",
|
||||
new_callable=CoroutineMock,
|
||||
) as mocked_make_request:
|
||||
await bot(method)
|
||||
|
|
@ -51,16 +51,16 @@ class TestBot:
|
|||
await session.create_session()
|
||||
|
||||
with patch(
|
||||
"aiogram.api.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
"aiogram.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
) as mocked_close:
|
||||
await bot.close()
|
||||
await bot.session.close()
|
||||
mocked_close.assert_awaited()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("close", [True, False])
|
||||
async def test_context_manager(self, close: bool):
|
||||
with patch(
|
||||
"aiogram.api.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
"aiogram.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
) as mocked_close:
|
||||
async with Bot("42:TEST", session=AiohttpSession()).context(auto_close=close) as bot:
|
||||
assert isinstance(bot, Bot)
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ from aresponses import ResponsesMockServer
|
|||
|
||||
from aiogram import Bot
|
||||
from aiogram.client.session.aiohttp import AiohttpSession
|
||||
from aiogram.api.methods import Request, TelegramMethod
|
||||
from aiogram.api.types import InputFile
|
||||
from aiogram.methods import Request, TelegramMethod
|
||||
from aiogram.types import InputFile
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
try:
|
||||
|
|
@ -171,7 +171,7 @@ class TestAiohttpSession:
|
|||
|
||||
call = TestMethod()
|
||||
with patch(
|
||||
"aiogram.api.client.session.base.BaseSession.raise_for_status"
|
||||
"aiogram.client.session.base.BaseSession.raise_for_status"
|
||||
) as patched_raise_for_status:
|
||||
result = await session.make_request(bot, call)
|
||||
assert isinstance(result, int)
|
||||
|
|
@ -205,10 +205,10 @@ class TestAiohttpSession:
|
|||
assert isinstance(session, AsyncContextManager)
|
||||
|
||||
with patch(
|
||||
"aiogram.api.client.session.aiohttp.AiohttpSession.create_session",
|
||||
"aiogram.client.session.aiohttp.AiohttpSession.create_session",
|
||||
new_callable=CoroutineMock,
|
||||
) as mocked_create_session, patch(
|
||||
"aiogram.api.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
"aiogram.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
) as mocked_close:
|
||||
async with session as ctx:
|
||||
assert session == ctx
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ from typing import AsyncContextManager, AsyncGenerator, Optional
|
|||
import pytest
|
||||
|
||||
from aiogram.client.session.base import BaseSession, T
|
||||
from aiogram.api.client.telegram import PRODUCTION, TelegramAPIServer
|
||||
from aiogram.api.methods import GetMe, Response, TelegramMethod
|
||||
from aiogram.api.types import UNSET
|
||||
from aiogram.client.telegram import PRODUCTION, TelegramAPIServer
|
||||
from aiogram.methods import GetMe, Response, TelegramMethod
|
||||
from aiogram.types import UNSET
|
||||
|
||||
try:
|
||||
from asynctest import CoroutineMock, patch
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import AddStickerToSet, Request
|
||||
from aiogram.methods import AddStickerToSet, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import AnswerCallbackQuery, Request
|
||||
from aiogram.methods import AnswerCallbackQuery, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import pytest
|
||||
|
||||
from aiogram import Bot
|
||||
from aiogram.api.methods import AnswerInlineQuery, Request
|
||||
from aiogram.api.types import InlineQueryResult, InlineQueryResultPhoto
|
||||
from aiogram.methods import AnswerInlineQuery, Request
|
||||
from aiogram.types import InlineQueryResult, InlineQueryResultPhoto
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import AnswerPreCheckoutQuery, Request
|
||||
from aiogram.methods import AnswerPreCheckoutQuery, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import AnswerShippingQuery, Request
|
||||
from aiogram.methods import AnswerShippingQuery, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from typing import Dict, Optional
|
|||
import pytest
|
||||
|
||||
from aiogram import Bot
|
||||
from aiogram.api.methods.base import prepare_parse_mode
|
||||
from aiogram.methods.base import prepare_parse_mode
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import CreateNewStickerSet, Request
|
||||
from aiogram.methods import CreateNewStickerSet, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import DeleteChatPhoto, Request
|
||||
from aiogram.methods import DeleteChatPhoto, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import DeleteChatStickerSet, Request
|
||||
from aiogram.methods import DeleteChatStickerSet, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import DeleteMessage, Request
|
||||
from aiogram.methods import DeleteMessage, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import DeleteStickerFromSet, Request
|
||||
from aiogram.methods import DeleteStickerFromSet, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import DeleteWebhook, Request
|
||||
from aiogram.methods import DeleteWebhook, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ from typing import Union
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import EditMessageCaption, Request
|
||||
from aiogram.api.types import Chat, Message
|
||||
from aiogram.methods import EditMessageCaption, Request
|
||||
from aiogram.types import Chat, Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ from typing import Union
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import EditMessageLiveLocation, Request
|
||||
from aiogram.api.types import Message
|
||||
from aiogram.methods import EditMessageLiveLocation, Request
|
||||
from aiogram.types import Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ from typing import Union
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import EditMessageMedia, Request
|
||||
from aiogram.api.types import BufferedInputFile, InputMedia, InputMediaPhoto, Message
|
||||
from aiogram.methods import EditMessageMedia, Request
|
||||
from aiogram.types import BufferedInputFile, InputMedia, InputMediaPhoto, Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ from typing import Union
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import EditMessageReplyMarkup, Request
|
||||
from aiogram.api.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
|
||||
from aiogram.methods import EditMessageReplyMarkup, Request
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ from typing import Union
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import EditMessageText, Request
|
||||
from aiogram.api.types import Message
|
||||
from aiogram.methods import EditMessageText, Request
|
||||
from aiogram.types import Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import ExportChatInviteLink, Request
|
||||
from aiogram.methods import ExportChatInviteLink, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import ForwardMessage, Request
|
||||
from aiogram.api.types import Chat, Message
|
||||
from aiogram.methods import ForwardMessage, Request
|
||||
from aiogram.types import Chat, Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetChat, Request
|
||||
from aiogram.api.types import Chat
|
||||
from aiogram.methods import GetChat, Request
|
||||
from aiogram.types import Chat
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ from typing import List
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetChatAdministrators, Request
|
||||
from aiogram.api.types import ChatMember, User
|
||||
from aiogram.methods import GetChatAdministrators, Request
|
||||
from aiogram.types import ChatMember, User
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetChatMember, Request
|
||||
from aiogram.api.types import ChatMember, User
|
||||
from aiogram.methods import GetChatMember, Request
|
||||
from aiogram.types import ChatMember, User
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetChatMembersCount, Request
|
||||
from aiogram.methods import GetChatMembersCount, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetFile, Request
|
||||
from aiogram.api.types import File
|
||||
from aiogram.methods import GetFile, Request
|
||||
from aiogram.types import File
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ from typing import List
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetGameHighScores, Request
|
||||
from aiogram.api.types import GameHighScore, User
|
||||
from aiogram.methods import GetGameHighScores, Request
|
||||
from aiogram.types import GameHighScore, User
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetMe, Request
|
||||
from aiogram.api.types import User
|
||||
from aiogram.methods import GetMe, Request
|
||||
from aiogram.types import User
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ from typing import List
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetMyCommands, Request
|
||||
from aiogram.api.types import BotCommand
|
||||
from aiogram.methods import GetMyCommands, Request
|
||||
from aiogram.types import BotCommand
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetStickerSet, Request
|
||||
from aiogram.api.types import Sticker, StickerSet
|
||||
from aiogram.methods import GetStickerSet, Request
|
||||
from aiogram.types import Sticker, StickerSet
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ from typing import List
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetUpdates, Request
|
||||
from aiogram.api.types import Update
|
||||
from aiogram.methods import GetUpdates, Request
|
||||
from aiogram.types import Update
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetUserProfilePhotos, Request
|
||||
from aiogram.api.types import PhotoSize, UserProfilePhotos
|
||||
from aiogram.methods import GetUserProfilePhotos, Request
|
||||
from aiogram.types import PhotoSize, UserProfilePhotos
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetWebhookInfo, Request
|
||||
from aiogram.api.types import WebhookInfo
|
||||
from aiogram.methods import GetWebhookInfo, Request
|
||||
from aiogram.types import WebhookInfo
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import KickChatMember, Request
|
||||
from aiogram.methods import KickChatMember, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import LeaveChat, Request
|
||||
from aiogram.methods import LeaveChat, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import PinChatMessage, Request
|
||||
from aiogram.methods import PinChatMessage, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import PromoteChatMember, Request
|
||||
from aiogram.methods import PromoteChatMember, Request
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, RestrictChatMember
|
||||
from aiogram.api.types import ChatPermissions
|
||||
from aiogram.methods import Request, RestrictChatMember
|
||||
from aiogram.types import ChatPermissions
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendAnimation
|
||||
from aiogram.api.types import Animation, Chat, Message
|
||||
from aiogram.methods import Request, SendAnimation
|
||||
from aiogram.types import Animation, Chat, Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendAudio
|
||||
from aiogram.api.types import Audio, Chat, File, Message
|
||||
from aiogram.methods import Request, SendAudio
|
||||
from aiogram.types import Audio, Chat, File, Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendChatAction
|
||||
from aiogram.methods import Request, SendChatAction
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendContact
|
||||
from aiogram.api.types import Chat, Contact, Message
|
||||
from aiogram.methods import Request, SendContact
|
||||
from aiogram.types import Chat, Contact, Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendDice
|
||||
from aiogram.api.types import Message
|
||||
from aiogram.methods import Request, SendDice
|
||||
from aiogram.types import Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendDocument
|
||||
from aiogram.api.types import Chat, Document, Message
|
||||
from aiogram.methods import Request, SendDocument
|
||||
from aiogram.types import Chat, Document, Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendGame
|
||||
from aiogram.api.types import Chat, Game, Message, PhotoSize
|
||||
from aiogram.methods import Request, SendGame
|
||||
from aiogram.types import Chat, Game, Message, PhotoSize
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendInvoice
|
||||
from aiogram.api.types import Chat, Invoice, LabeledPrice, Message
|
||||
from aiogram.methods import Request, SendInvoice
|
||||
from aiogram.types import Chat, Invoice, LabeledPrice, Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendLocation
|
||||
from aiogram.api.types import Chat, Location, Message
|
||||
from aiogram.methods import Request, SendLocation
|
||||
from aiogram.types import Chat, Location, Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ from typing import List
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendMediaGroup
|
||||
from aiogram.api.types import (
|
||||
from aiogram.methods import Request, SendMediaGroup
|
||||
from aiogram.types import (
|
||||
BufferedInputFile,
|
||||
Chat,
|
||||
InputMediaPhoto,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendMessage
|
||||
from aiogram.api.types import Chat, Message
|
||||
from aiogram.methods import Request, SendMessage
|
||||
from aiogram.types import Chat, Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendPhoto
|
||||
from aiogram.api.types import Chat, Message, PhotoSize
|
||||
from aiogram.methods import Request, SendPhoto
|
||||
from aiogram.types import Chat, Message, PhotoSize
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendPoll
|
||||
from aiogram.api.types import Chat, Message, Poll, PollOption
|
||||
from aiogram.methods import Request, SendPoll
|
||||
from aiogram.types import Chat, Message, Poll, PollOption
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendSticker
|
||||
from aiogram.api.types import Chat, Message, Sticker
|
||||
from aiogram.methods import Request, SendSticker
|
||||
from aiogram.types import Chat, Message, Sticker
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendVenue
|
||||
from aiogram.api.types import Chat, Location, Message, Venue
|
||||
from aiogram.methods import Request, SendVenue
|
||||
from aiogram.types import Chat, Location, Message, Venue
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendVideo
|
||||
from aiogram.api.types import Chat, Message, Video
|
||||
from aiogram.methods import Request, SendVideo
|
||||
from aiogram.types import Chat, Message, Video
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendVideoNote
|
||||
from aiogram.api.types import BufferedInputFile, Chat, Message, VideoNote
|
||||
from aiogram.methods import Request, SendVideoNote
|
||||
from aiogram.types import BufferedInputFile, Chat, Message, VideoNote
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SendVoice
|
||||
from aiogram.api.types import Chat, Message, Voice
|
||||
from aiogram.methods import Request, SendVoice
|
||||
from aiogram.types import Chat, Message, Voice
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SetChatAdministratorCustomTitle, SetChatTitle
|
||||
from aiogram.methods import Request, SetChatAdministratorCustomTitle, SetChatTitle
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SetChatDescription
|
||||
from aiogram.methods import Request, SetChatDescription
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SetChatPermissions
|
||||
from aiogram.api.types import ChatPermissions
|
||||
from aiogram.methods import Request, SetChatPermissions
|
||||
from aiogram.types import ChatPermissions
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SetChatPhoto
|
||||
from aiogram.api.types import BufferedInputFile, InputFile
|
||||
from aiogram.methods import Request, SetChatPhoto
|
||||
from aiogram.types import BufferedInputFile, InputFile
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SetChatStickerSet
|
||||
from aiogram.methods import Request, SetChatStickerSet
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SetChatTitle
|
||||
from aiogram.methods import Request, SetChatTitle
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ from typing import Union
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SetGameScore
|
||||
from aiogram.api.types import Message
|
||||
from aiogram.methods import Request, SetGameScore
|
||||
from aiogram.types import Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SetMyCommands
|
||||
from aiogram.api.types import BotCommand
|
||||
from aiogram.methods import Request, SetMyCommands
|
||||
from aiogram.types import BotCommand
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SetPassportDataErrors
|
||||
from aiogram.api.types import PassportElementError
|
||||
from aiogram.methods import Request, SetPassportDataErrors
|
||||
from aiogram.types import PassportElementError
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SetStickerPositionInSet
|
||||
from aiogram.methods import Request, SetStickerPositionInSet
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SetStickerSetThumb
|
||||
from aiogram.methods import Request, SetStickerSetThumb
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, SetWebhook
|
||||
from aiogram.methods import Request, SetWebhook
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ from typing import Union
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, StopMessageLiveLocation
|
||||
from aiogram.api.types import Message
|
||||
from aiogram.methods import Request, StopMessageLiveLocation
|
||||
from aiogram.types import Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, StopPoll
|
||||
from aiogram.api.types import Poll, PollOption
|
||||
from aiogram.methods import Request, StopPoll
|
||||
from aiogram.types import Poll, PollOption
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, UnbanChatMember
|
||||
from aiogram.methods import Request, UnbanChatMember
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, UnpinChatMessage
|
||||
from aiogram.methods import Request, UnpinChatMessage
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import Request, UploadStickerFile
|
||||
from aiogram.api.types import BufferedInputFile, File
|
||||
from aiogram.methods import Request, UploadStickerFile
|
||||
from aiogram.types import BufferedInputFile, File
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from aiogram.api.methods import AnswerCallbackQuery
|
||||
from aiogram.api.types import CallbackQuery, User
|
||||
from aiogram.methods import AnswerCallbackQuery
|
||||
from aiogram.types import CallbackQuery, User
|
||||
|
||||
|
||||
class TestCallbackQuery:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.types import ChatMember, User
|
||||
from aiogram.types import ChatMember, User
|
||||
|
||||
user = User(id=42, is_bot=False, first_name="User", last_name=None)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from aiogram.api.methods import AnswerInlineQuery
|
||||
from aiogram.api.types import InlineQuery, User
|
||||
from aiogram.methods import AnswerInlineQuery
|
||||
from aiogram.types import InlineQuery, User
|
||||
|
||||
|
||||
class TestInlineQuery:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import pytest
|
|||
from aresponses import ResponsesMockServer
|
||||
|
||||
from aiogram import Bot
|
||||
from aiogram.api.types import BufferedInputFile, FSInputFile, InputFile, URLInputFile
|
||||
from aiogram.types import BufferedInputFile, FSInputFile, InputFile, URLInputFile
|
||||
|
||||
|
||||
class TestInputFile:
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from typing import Any, Dict, Type, Union
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import (
|
||||
from aiogram.methods import (
|
||||
SendAnimation,
|
||||
SendAudio,
|
||||
SendContact,
|
||||
|
|
@ -22,7 +22,7 @@ from aiogram.api.methods import (
|
|||
SendVideoNote,
|
||||
SendVoice,
|
||||
)
|
||||
from aiogram.api.types import (
|
||||
from aiogram.types import (
|
||||
Animation,
|
||||
Audio,
|
||||
Chat,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from aiogram.api.methods import AnswerPreCheckoutQuery
|
||||
from aiogram.api.types import PreCheckoutQuery, User
|
||||
from aiogram.methods import AnswerPreCheckoutQuery
|
||||
from aiogram.types import PreCheckoutQuery, User
|
||||
|
||||
|
||||
class TestPreCheckoutQuery:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.types import ReplyKeyboardRemove
|
||||
from aiogram.types import ReplyKeyboardRemove
|
||||
|
||||
|
||||
class TestReplyKeyboardRemove:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from aiogram.api.methods import AnswerShippingQuery
|
||||
from aiogram.api.types import LabeledPrice, ShippingAddress, ShippingOption, ShippingQuery, User
|
||||
from aiogram.methods import AnswerShippingQuery
|
||||
from aiogram.types import LabeledPrice, ShippingAddress, ShippingOption, ShippingQuery, User
|
||||
|
||||
|
||||
class TestInlineQuery:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.types import User
|
||||
from aiogram.types import User
|
||||
|
||||
|
||||
class TestUser:
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ OBSERVERS = {
|
|||
"poll_answer",
|
||||
"pre_checkout_query",
|
||||
"shipping_query",
|
||||
"update",
|
||||
}
|
||||
|
||||
DEPRECATED_OBSERVERS = {observer + "_handler" for observer in OBSERVERS}
|
||||
|
|
|
|||
|
|
@ -2,15 +2,31 @@ import asyncio
|
|||
import datetime
|
||||
import time
|
||||
import warnings
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram import Bot
|
||||
from aiogram.api.methods import GetMe, GetUpdates, SendMessage
|
||||
from aiogram.api.types import Chat, Message, Update, User
|
||||
from aiogram.dispatcher.dispatcher import Dispatcher
|
||||
from aiogram.dispatcher.event.bases import NOT_HANDLED
|
||||
from aiogram.dispatcher.event.bases import UNHANDLED, SkipHandler
|
||||
from aiogram.dispatcher.middlewares.user_context import UserContextMiddleware
|
||||
from aiogram.dispatcher.router import Router
|
||||
from aiogram.methods import GetMe, GetUpdates, SendMessage
|
||||
from aiogram.types import (
|
||||
CallbackQuery,
|
||||
Chat,
|
||||
ChosenInlineResult,
|
||||
InlineQuery,
|
||||
Message,
|
||||
Poll,
|
||||
PollAnswer,
|
||||
PollOption,
|
||||
PreCheckoutQuery,
|
||||
ShippingAddress,
|
||||
ShippingQuery,
|
||||
Update,
|
||||
User,
|
||||
)
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
try:
|
||||
|
|
@ -43,6 +59,13 @@ UPDATE = Update(**RAW_UPDATE)
|
|||
|
||||
|
||||
class TestDispatcher:
|
||||
def test_init(self):
|
||||
dp = Dispatcher()
|
||||
|
||||
assert dp.update.handlers
|
||||
assert dp.update.handlers[0].callback == dp._listen_update
|
||||
assert dp.update.outer_middlewares
|
||||
|
||||
def test_parent_router(self):
|
||||
dp = Dispatcher()
|
||||
with pytest.raises(RuntimeError):
|
||||
|
|
@ -145,6 +168,290 @@ class TestDispatcher:
|
|||
|
||||
assert await dispatcher._process_update(bot=bot, update=Update(update_id=42))
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"event_type,update,has_chat,has_user",
|
||||
[
|
||||
pytest.param(
|
||||
"message",
|
||||
Update(
|
||||
update_id=42,
|
||||
message=Message(
|
||||
message_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
text="test",
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
),
|
||||
),
|
||||
True,
|
||||
True,
|
||||
),
|
||||
pytest.param(
|
||||
"edited_message",
|
||||
Update(
|
||||
update_id=42,
|
||||
edited_message=Message(
|
||||
message_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
text="edited test",
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
),
|
||||
),
|
||||
True,
|
||||
True,
|
||||
),
|
||||
pytest.param(
|
||||
"channel_post",
|
||||
Update(
|
||||
update_id=42,
|
||||
channel_post=Message(
|
||||
message_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
text="test",
|
||||
chat=Chat(id=-42, type="private"),
|
||||
),
|
||||
),
|
||||
True,
|
||||
False,
|
||||
),
|
||||
pytest.param(
|
||||
"edited_channel_post",
|
||||
Update(
|
||||
update_id=42,
|
||||
edited_channel_post=Message(
|
||||
message_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
text="test",
|
||||
chat=Chat(id=-42, type="private"),
|
||||
),
|
||||
),
|
||||
True,
|
||||
False,
|
||||
),
|
||||
pytest.param(
|
||||
"inline_query",
|
||||
Update(
|
||||
update_id=42,
|
||||
inline_query=InlineQuery(
|
||||
id="query id",
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
query="query",
|
||||
offset="offser",
|
||||
),
|
||||
),
|
||||
False,
|
||||
True,
|
||||
),
|
||||
pytest.param(
|
||||
"chosen_inline_result",
|
||||
Update(
|
||||
update_id=42,
|
||||
chosen_inline_result=ChosenInlineResult(
|
||||
result_id="result id",
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
query="query",
|
||||
),
|
||||
),
|
||||
False,
|
||||
True,
|
||||
),
|
||||
pytest.param(
|
||||
"callback_query",
|
||||
Update(
|
||||
update_id=42,
|
||||
callback_query=CallbackQuery(
|
||||
id="query id",
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
chat_instance="instance",
|
||||
data="placeholder",
|
||||
),
|
||||
),
|
||||
False,
|
||||
True,
|
||||
),
|
||||
pytest.param(
|
||||
"callback_query",
|
||||
Update(
|
||||
update_id=42,
|
||||
callback_query=CallbackQuery(
|
||||
id="query id",
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
chat_instance="instance",
|
||||
data="placeholder",
|
||||
message=Message(
|
||||
message_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
text="test",
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
),
|
||||
),
|
||||
),
|
||||
True,
|
||||
True,
|
||||
),
|
||||
pytest.param(
|
||||
"shipping_query",
|
||||
Update(
|
||||
update_id=42,
|
||||
shipping_query=ShippingQuery(
|
||||
id="id",
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
invoice_payload="payload",
|
||||
shipping_address=ShippingAddress(
|
||||
country_code="placeholder",
|
||||
state="placeholder",
|
||||
city="placeholder",
|
||||
street_line1="placeholder",
|
||||
street_line2="placeholder",
|
||||
post_code="placeholder",
|
||||
),
|
||||
),
|
||||
),
|
||||
False,
|
||||
True,
|
||||
),
|
||||
pytest.param(
|
||||
"pre_checkout_query",
|
||||
Update(
|
||||
update_id=42,
|
||||
pre_checkout_query=PreCheckoutQuery(
|
||||
id="query id",
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
currency="BTC",
|
||||
total_amount=1,
|
||||
invoice_payload="payload",
|
||||
),
|
||||
),
|
||||
False,
|
||||
True,
|
||||
),
|
||||
pytest.param(
|
||||
"poll",
|
||||
Update(
|
||||
update_id=42,
|
||||
poll=Poll(
|
||||
id="poll id",
|
||||
question="Q?",
|
||||
options=[
|
||||
PollOption(text="A1", voter_count=2),
|
||||
PollOption(text="A2", voter_count=3),
|
||||
],
|
||||
is_closed=False,
|
||||
is_anonymous=False,
|
||||
type="quiz",
|
||||
allows_multiple_answers=False,
|
||||
total_voter_count=0,
|
||||
correct_option_id=1,
|
||||
),
|
||||
),
|
||||
False,
|
||||
False,
|
||||
),
|
||||
pytest.param(
|
||||
"poll_answer",
|
||||
Update(
|
||||
update_id=42,
|
||||
poll_answer=PollAnswer(
|
||||
poll_id="poll id",
|
||||
user=User(id=42, is_bot=False, first_name="Test"),
|
||||
option_ids=[42],
|
||||
),
|
||||
),
|
||||
False,
|
||||
True,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_listen_update(
|
||||
self, event_type: str, update: Update, has_chat: bool, has_user: bool
|
||||
):
|
||||
router = Dispatcher()
|
||||
observer = router.observers[event_type]
|
||||
|
||||
@observer()
|
||||
async def my_handler(event: Any, **kwargs: Any):
|
||||
assert event == getattr(update, event_type)
|
||||
if has_chat:
|
||||
assert Chat.get_current(False)
|
||||
if has_user:
|
||||
assert User.get_current(False)
|
||||
return kwargs
|
||||
|
||||
result = await router.update.trigger(update, test="PASS")
|
||||
assert isinstance(result, dict)
|
||||
assert result["event_update"] == update
|
||||
assert result["event_router"] == router
|
||||
assert result["test"] == "PASS"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_listen_unknown_update(self):
|
||||
dp = Dispatcher()
|
||||
|
||||
with pytest.raises(SkipHandler):
|
||||
await dp._listen_update(Update(update_id=42))
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_listen_unhandled_update(self):
|
||||
dp = Dispatcher()
|
||||
observer = dp.observers["message"]
|
||||
|
||||
@observer(lambda event: False)
|
||||
async def handler(event: Any):
|
||||
pass
|
||||
|
||||
response = await dp._listen_update(
|
||||
Update(
|
||||
update_id=42,
|
||||
poll=Poll(
|
||||
id="poll id",
|
||||
question="Q?",
|
||||
options=[
|
||||
PollOption(text="A1", voter_count=2),
|
||||
PollOption(text="A2", voter_count=3),
|
||||
],
|
||||
is_closed=False,
|
||||
is_anonymous=False,
|
||||
type="quiz",
|
||||
allows_multiple_answers=False,
|
||||
total_voter_count=0,
|
||||
correct_option_id=0,
|
||||
),
|
||||
)
|
||||
)
|
||||
assert response is UNHANDLED
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_nested_router_listen_update(self):
|
||||
dp = Dispatcher()
|
||||
router0 = Router()
|
||||
router1 = Router()
|
||||
dp.include_router(router0)
|
||||
router0.include_router(router1)
|
||||
observer = router1.message
|
||||
|
||||
@observer()
|
||||
async def my_handler(event: Message, **kwargs: Any):
|
||||
return kwargs
|
||||
|
||||
update = Update(
|
||||
update_id=42,
|
||||
message=Message(
|
||||
message_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
text="test",
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
),
|
||||
)
|
||||
result = await dp._listen_update(update, test="PASS")
|
||||
assert isinstance(result, dict)
|
||||
assert result["event_update"] == update
|
||||
assert result["event_router"] == router1
|
||||
assert result["test"] == "PASS"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_process_update_call_request(self, bot: MockedBot):
|
||||
dispatcher = Dispatcher()
|
||||
|
|
@ -192,6 +499,45 @@ class TestDispatcher:
|
|||
await dispatcher._polling(bot=bot)
|
||||
mocked_process_update.assert_awaited()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_exception_handler_catch_exceptions(self):
|
||||
dp = Dispatcher()
|
||||
router = Router()
|
||||
dp.include_router(router)
|
||||
|
||||
@router.message()
|
||||
async def message_handler(message: Message):
|
||||
raise Exception("KABOOM")
|
||||
|
||||
update = Update(
|
||||
update_id=42,
|
||||
message=Message(
|
||||
message_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
text="test",
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
),
|
||||
)
|
||||
with pytest.raises(Exception, match="KABOOM"):
|
||||
await dp.update.trigger(update)
|
||||
|
||||
@router.errors()
|
||||
async def error_handler(event: Update, exception: Exception):
|
||||
return "KABOOM"
|
||||
|
||||
response = await dp.update.trigger(update)
|
||||
assert response == "KABOOM"
|
||||
|
||||
@dp.errors()
|
||||
async def root_error_handler(event: Update, exception: Exception):
|
||||
return exception
|
||||
|
||||
response = await dp.update.trigger(update)
|
||||
|
||||
assert isinstance(response, Exception)
|
||||
assert str(response) == "KABOOM"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_polling(self, bot: MockedBot):
|
||||
dispatcher = Dispatcher()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from typing import Any, Dict, Union
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.types import Update
|
||||
from aiogram.types import Update
|
||||
from aiogram.dispatcher.event.handler import CallableMixin, FilterObject, HandlerObject
|
||||
from aiogram.dispatcher.filters import Text
|
||||
from aiogram.dispatcher.filters.base import BaseFilter
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from typing import Any, Awaitable, Callable, Dict, NoReturn, Union
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.types import Chat, Message, User
|
||||
from aiogram.types import Chat, Message, User
|
||||
from aiogram.dispatcher.event.bases import SkipHandler
|
||||
from aiogram.dispatcher.event.handler import HandlerObject
|
||||
from aiogram.dispatcher.event.telegram import TelegramEventObserver
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ from typing import Match
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetMe
|
||||
from aiogram.api.types import Chat, Message, User
|
||||
from aiogram.methods import GetMe
|
||||
from aiogram.types import Chat, Message, User
|
||||
from aiogram.dispatcher.filters import Command, CommandObject
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from typing import cast
|
|||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from aiogram.api.types import ContentType, Message
|
||||
from aiogram.types import ContentType, Message
|
||||
from aiogram.dispatcher.filters import ContentTypesFilter
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from typing import Sequence, Type
|
|||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from aiogram.api.types import CallbackQuery, Chat, InlineQuery, Message, Poll, PollOption, User
|
||||
from aiogram.types import CallbackQuery, Chat, InlineQuery, Message, Poll, PollOption, User
|
||||
from aiogram.dispatcher.filters import BUILTIN_FILTERS
|
||||
from aiogram.dispatcher.filters.text import Text
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from typing import Any
|
|||
import pytest
|
||||
|
||||
from aiogram import Bot
|
||||
from aiogram.api.types import Chat, Message, Update
|
||||
from aiogram.types import Chat, Message, Update
|
||||
from aiogram.dispatcher.event.handler import HandlerObject
|
||||
from aiogram.dispatcher.handler.base import BaseHandler
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from typing import Any
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.types import CallbackQuery, User
|
||||
from aiogram.types import CallbackQuery, User
|
||||
from aiogram.dispatcher.handler import CallbackQueryHandler
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from typing import Any
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.types import CallbackQuery, ChosenInlineResult, User
|
||||
from aiogram.types import CallbackQuery, ChosenInlineResult, User
|
||||
from aiogram.dispatcher.handler import ChosenInlineResultHandler
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from typing import Any
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.types import (
|
||||
from aiogram.types import (
|
||||
CallbackQuery,
|
||||
InlineQuery,
|
||||
Poll,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from typing import Any
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.types import CallbackQuery, InlineQuery, User
|
||||
from aiogram.types import CallbackQuery, InlineQuery, User
|
||||
from aiogram.dispatcher.handler import InlineQueryHandler
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from typing import Any
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.types import Chat, Message, User
|
||||
from aiogram.types import Chat, Message, User
|
||||
from aiogram.dispatcher.filters import CommandObject
|
||||
from aiogram.dispatcher.handler.message import MessageHandler, MessageHandlerCommandMixin
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from typing import Any
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.types import (
|
||||
from aiogram.types import (
|
||||
CallbackQuery,
|
||||
InlineQuery,
|
||||
Poll,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from typing import Any
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.api.types import PreCheckoutQuery, User
|
||||
from aiogram.types import PreCheckoutQuery, User
|
||||
from aiogram.dispatcher.handler import PreCheckoutQueryHandler
|
||||
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue