diff --git a/aiogram/client/session/middlewares/request_logging.py b/aiogram/client/session/middlewares/request_logging.py index ea9ffab9..af7b9d6e 100644 --- a/aiogram/client/session/middlewares/request_logging.py +++ b/aiogram/client/session/middlewares/request_logging.py @@ -35,27 +35,3 @@ class RequestLogging(BaseRequestMiddleware): bot.id, ) return await make_request(bot, method) - - -class VerboseRequestLogging(BaseRequestMiddleware): - def __init__(self, ignore_methods: Optional[List[Type[TelegramMethod[Any]]]] = None): - """ - Middleware for logging outgoing requests - - :param ignore_methods: methods to ignore in logging middleware - """ - self.ignore_methods = ignore_methods if ignore_methods else [] - - async def __call__( - self, - make_request: NextRequestMiddlewareType[TelegramType], - bot: "Bot", - method: TelegramMethod[TelegramType], - ) -> Response[TelegramType]: - if type(method) not in self.ignore_methods: - loggers.middlewares.info( - "Make request with method=%r by bot id=%d", - method, - bot.id, - ) - return await make_request(bot, method) diff --git a/tests/test_api/test_methods/test_add_sticker_to_set.py b/tests/test_api/test_methods/test_add_sticker_to_set.py index 0bc6472c..94e9c3f1 100644 --- a/tests/test_api/test_methods/test_add_sticker_to_set.py +++ b/tests/test_api/test_methods/test_add_sticker_to_set.py @@ -1,4 +1,5 @@ from aiogram.methods import AddStickerToSet, Request +from aiogram.types import InputSticker from tests.mocked_bot import MockedBot @@ -7,7 +8,9 @@ class TestAddStickerToSet: prepare_result = bot.add_result_for(AddStickerToSet, ok=True, result=True) response: bool = await AddStickerToSet( - user_id=42, name="test stickers pack", png_sticker="file id", emojis=":)" + user_id=42, + name="test stickers pack", + sticker=InputSticker(sticker="file id", emoji_list=[":)"]), ) request: Request = bot.get_request() assert request.method == "addStickerToSet" @@ -17,7 +20,9 @@ class TestAddStickerToSet: prepare_result = bot.add_result_for(AddStickerToSet, ok=True, result=True) response: bool = await bot.add_sticker_to_set( - user_id=42, name="test stickers pack", png_sticker="file id", emojis=":)" + user_id=42, + name="test stickers pack", + sticker=InputSticker(sticker="file id", emoji_list=[":)"]), ) request: Request = bot.get_request() assert request.method == "addStickerToSet" diff --git a/tests/test_api/test_methods/test_answer_inline_query.py b/tests/test_api/test_methods/test_answer_inline_query.py index c2d11b43..c3b35a2e 100644 --- a/tests/test_api/test_methods/test_answer_inline_query.py +++ b/tests/test_api/test_methods/test_answer_inline_query.py @@ -32,7 +32,9 @@ class TestAnswerInlineQuery: def test_parse_mode(self, bot: MockedBot): query = AnswerInlineQuery( inline_query_id="query id", - results=[InlineQueryResultPhoto(id="result id", photo_url="photo", thumb_url="thumb")], + results=[ + InlineQueryResultPhoto(id="result id", photo_url="photo", thumbnail_url="thumb") + ], ) request = query.build_request(bot) assert request.data["results"][0]["parse_mode"] is None @@ -48,7 +50,7 @@ class TestAnswerInlineQuery: InlineQueryResultPhoto( id="result id", photo_url="photo", - thumb_url="thumb", + thumbnail_url="thumb", input_message_content=InputTextMessageContent(message_text="test"), ) ], diff --git a/tests/test_api/test_methods/test_create_new_sticker_set.py b/tests/test_api/test_methods/test_create_new_sticker_set.py index b82b1974..ba44266e 100644 --- a/tests/test_api/test_methods/test_create_new_sticker_set.py +++ b/tests/test_api/test_methods/test_create_new_sticker_set.py @@ -1,4 +1,6 @@ +from aiogram.enums import StickerFormat from aiogram.methods import CreateNewStickerSet, Request +from aiogram.types import FSInputFile, InputSticker from tests.mocked_bot import MockedBot @@ -7,7 +9,14 @@ class TestCreateNewStickerSet: prepare_result = bot.add_result_for(CreateNewStickerSet, ok=True, result=True) response: bool = await CreateNewStickerSet( - user_id=42, name="name", title="title", png_sticker="file id", emojis=":)" + user_id=42, + name="name", + title="title", + stickers=[ + InputSticker(sticker="file id", emoji_list=[":)"]), + InputSticker(sticker=FSInputFile("file.png"), emoji_list=["=("]), + ], + sticker_format=StickerFormat.STATIC, ) request: Request = bot.get_request() assert request.method == "createNewStickerSet" @@ -17,7 +26,14 @@ class TestCreateNewStickerSet: prepare_result = bot.add_result_for(CreateNewStickerSet, ok=True, result=True) response: bool = await bot.create_new_sticker_set( - user_id=42, name="name", title="title", png_sticker="file id", emojis=":)" + user_id=42, + name="name", + title="title", + stickers=[ + InputSticker(sticker="file id", emoji_list=[":)"]), + InputSticker(sticker=FSInputFile("file.png"), emoji_list=["=("]), + ], + sticker_format=StickerFormat.STATIC, ) request: Request = bot.get_request() assert request.method == "createNewStickerSet" diff --git a/tests/test_api/test_methods/test_delete_sticker_set.py b/tests/test_api/test_methods/test_delete_sticker_set.py new file mode 100644 index 00000000..4ab6a1a0 --- /dev/null +++ b/tests/test_api/test_methods/test_delete_sticker_set.py @@ -0,0 +1,20 @@ +from aiogram.methods import DeleteStickerSet, Request +from tests.mocked_bot import MockedBot + + +class TestDeleteStickerSet: + async def test_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(DeleteStickerSet, ok=True, result=True) + + response: bool = await DeleteStickerSet(name="test") + request: Request = bot.get_request() + assert request.method == "deleteStickerSet" + assert response == prepare_result.result + + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(DeleteStickerSet, ok=True, result=True) + + response: bool = await bot.delete_sticker_set(name="test") + request: Request = bot.get_request() + assert request.method == "deleteStickerSet" + assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_my_description.py b/tests/test_api/test_methods/test_get_my_description.py new file mode 100644 index 00000000..8a861ecb --- /dev/null +++ b/tests/test_api/test_methods/test_get_my_description.py @@ -0,0 +1,25 @@ +from aiogram.methods import GetMyDescription, Request +from aiogram.types import BotDescription +from tests.mocked_bot import MockedBot + + +class TestGetMyDescription: + async def test_method(self, bot: MockedBot): + prepare_result = bot.add_result_for( + GetMyDescription, ok=True, result=BotDescription(description="Test") + ) + + response: BotDescription = await GetMyDescription() + request: Request = bot.get_request() + assert request.method == "getMyDescription" + assert response == prepare_result.result + + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for( + GetMyDescription, ok=True, result=BotDescription(description="Test") + ) + + response: BotDescription = await bot.get_my_description() + request: Request = bot.get_request() + assert request.method == "getMyDescription" + assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_my_short_description.py b/tests/test_api/test_methods/test_get_my_short_description.py new file mode 100644 index 00000000..5d362fdb --- /dev/null +++ b/tests/test_api/test_methods/test_get_my_short_description.py @@ -0,0 +1,25 @@ +from aiogram.methods import GetMyShortDescription, Request +from aiogram.types import BotShortDescription +from tests.mocked_bot import MockedBot + + +class TestGetMyShortDescription: + async def test_method(self, bot: MockedBot): + prepare_result = bot.add_result_for( + GetMyShortDescription, ok=True, result=BotShortDescription(short_description="Test") + ) + + response: BotShortDescription = await GetMyShortDescription() + request: Request = bot.get_request() + assert request.method == "getMyShortDescription" + assert response == prepare_result.result + + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for( + GetMyShortDescription, ok=True, result=BotShortDescription(short_description="Test") + ) + + response: BotShortDescription = await bot.get_my_short_description() + request: Request = bot.get_request() + assert request.method == "getMyShortDescription" + assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_video_note.py b/tests/test_api/test_methods/test_send_video_note.py index e9afee41..bec233c7 100644 --- a/tests/test_api/test_methods/test_send_video_note.py +++ b/tests/test_api/test_methods/test_send_video_note.py @@ -21,7 +21,9 @@ class TestSendVideoNote: ) response: Message = await SendVideoNote( - chat_id=42, video_note="file id", thumb=BufferedInputFile(b"", "file.png") + chat_id=42, + video_note="file id", + thumbnail=BufferedInputFile(b"", "file.png"), ) request: Request = bot.get_request() assert request.method == "sendVideoNote" @@ -42,7 +44,9 @@ class TestSendVideoNote: ) response: Message = await bot.send_video_note( - chat_id=42, video_note="file id", thumb=BufferedInputFile(b"", "file.png") + chat_id=42, + video_note="file id", + thumbnail=BufferedInputFile(b"", "file.png"), ) request: Request = bot.get_request() assert request.method == "sendVideoNote" diff --git a/tests/test_api/test_methods/test_set_custom_emoji_sticker_set_thumbnail.py b/tests/test_api/test_methods/test_set_custom_emoji_sticker_set_thumbnail.py new file mode 100644 index 00000000..20ad08c9 --- /dev/null +++ b/tests/test_api/test_methods/test_set_custom_emoji_sticker_set_thumbnail.py @@ -0,0 +1,28 @@ +from aiogram.methods import Request, SetCustomEmojiStickerSetThumbnail +from tests.mocked_bot import MockedBot + + +class TestSetCustomEmojiStickerSetThumbnail: + async def test_method(self, bot: MockedBot): + prepare_result = bot.add_result_for( + SetCustomEmojiStickerSetThumbnail, ok=True, result=True + ) + + response: bool = await SetCustomEmojiStickerSetThumbnail( + name="test", custom_emoji_id="custom id" + ) + request: Request = bot.get_request() + assert request.method == "setCustomEmojiStickerSetThumbnail" + assert response == prepare_result.result + + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for( + SetCustomEmojiStickerSetThumbnail, ok=True, result=True + ) + + response: bool = await bot.set_custom_emoji_sticker_set_thumbnail( + name="test", custom_emoji_id="custom id" + ) + request: Request = bot.get_request() + assert request.method == "setCustomEmojiStickerSetThumbnail" + assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_my_description.py b/tests/test_api/test_methods/test_set_my_description.py new file mode 100644 index 00000000..843b66d2 --- /dev/null +++ b/tests/test_api/test_methods/test_set_my_description.py @@ -0,0 +1,20 @@ +from aiogram.methods import Request, SetMyDescription +from tests.mocked_bot import MockedBot + + +class TestSetMyDescription: + async def test_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetMyDescription, ok=True, result=True) + + response: bool = await SetMyDescription(description="Test") + request: Request = bot.get_request() + assert request.method == "setMyDescription" + assert response == prepare_result.result + + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetMyDescription, ok=True, result=True) + + response: bool = await bot.set_my_description(description="Test") + request: Request = bot.get_request() + assert request.method == "setMyDescription" + assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_my_short_description.py b/tests/test_api/test_methods/test_set_my_short_description.py new file mode 100644 index 00000000..c985dee2 --- /dev/null +++ b/tests/test_api/test_methods/test_set_my_short_description.py @@ -0,0 +1,20 @@ +from aiogram.methods import Request, SetMyDescription, SetMyShortDescription +from tests.mocked_bot import MockedBot + + +class TestSetMyShortDescription: + async def test_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetMyShortDescription, ok=True, result=True) + + response: bool = await SetMyShortDescription(short_description="Test") + request: Request = bot.get_request() + assert request.method == "setMyShortDescription" + assert response == prepare_result.result + + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetMyShortDescription, ok=True, result=True) + + response: bool = await bot.set_my_short_description(short_description="Test") + request: Request = bot.get_request() + assert request.method == "setMyShortDescription" + assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_sticker_emoji_list.py b/tests/test_api/test_methods/test_set_sticker_emoji_list.py new file mode 100644 index 00000000..b5ae829c --- /dev/null +++ b/tests/test_api/test_methods/test_set_sticker_emoji_list.py @@ -0,0 +1,20 @@ +from aiogram.methods import Request, SetStickerEmojiList +from tests.mocked_bot import MockedBot + + +class TestSetStickerEmojiList: + async def test_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetStickerEmojiList, ok=True, result=True) + + response: bool = await SetStickerEmojiList(sticker="sticker id", emoji_list=["X"]) + request: Request = bot.get_request() + assert request.method == "setStickerEmojiList" + assert response == prepare_result.result + + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetStickerEmojiList, ok=True, result=True) + + response: bool = await bot.set_sticker_emoji_list(sticker="sticker id", emoji_list=["X"]) + request: Request = bot.get_request() + assert request.method == "setStickerEmojiList" + assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_sticker_keywords.py b/tests/test_api/test_methods/test_set_sticker_keywords.py new file mode 100644 index 00000000..7cea6cae --- /dev/null +++ b/tests/test_api/test_methods/test_set_sticker_keywords.py @@ -0,0 +1,20 @@ +from aiogram.methods import Request, SetStickerKeywords +from tests.mocked_bot import MockedBot + + +class TestSetStickerKeywords: + async def test_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetStickerKeywords, ok=True, result=True) + + response: bool = await SetStickerKeywords(sticker="sticker id", keywords=["X"]) + request: Request = bot.get_request() + assert request.method == "setStickerKeywords" + assert response == prepare_result.result + + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetStickerKeywords, ok=True, result=True) + + response: bool = await bot.set_sticker_keywords(sticker="sticker id", keywords=["X"]) + request: Request = bot.get_request() + assert request.method == "setStickerKeywords" + assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_sticker_mask_position.py b/tests/test_api/test_methods/test_set_sticker_mask_position.py new file mode 100644 index 00000000..dec92d19 --- /dev/null +++ b/tests/test_api/test_methods/test_set_sticker_mask_position.py @@ -0,0 +1,20 @@ +from aiogram.methods import Request, SetStickerEmojiList, SetStickerMaskPosition +from tests.mocked_bot import MockedBot + + +class TestSetStickerEmojiList: + async def test_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetStickerMaskPosition, ok=True, result=True) + + response: bool = await SetStickerMaskPosition(sticker="sticker id") + request: Request = bot.get_request() + assert request.method == "setStickerMaskPosition" + assert response == prepare_result.result + + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetStickerMaskPosition, ok=True, result=True) + + response: bool = await bot.set_sticker_mask_position(sticker="sticker id") + request: Request = bot.get_request() + assert request.method == "setStickerMaskPosition" + assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_sticker_set_thumb.py b/tests/test_api/test_methods/test_set_sticker_set_thumb.py deleted file mode 100644 index ca1b596a..00000000 --- a/tests/test_api/test_methods/test_set_sticker_set_thumb.py +++ /dev/null @@ -1,22 +0,0 @@ -from aiogram.methods import Request, SetStickerSetThumb -from tests.mocked_bot import MockedBot - - -class TestSetStickerSetThumb: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetStickerSetThumb, ok=True, result=None) - - response: bool = await SetStickerSetThumb(name="test", user_id=42) - request: Request = bot.get_request() - assert request.method == "setStickerSetThumb" - # assert request.data == {} - assert response == prepare_result.result - - async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetStickerSetThumb, ok=True, result=None) - - response: bool = await bot.set_sticker_set_thumb(name="test", user_id=42) - request: Request = bot.get_request() - assert request.method == "setStickerSetThumb" - # assert request.data == {} - assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_sticker_set_thumbnail.py b/tests/test_api/test_methods/test_set_sticker_set_thumbnail.py new file mode 100644 index 00000000..41795be6 --- /dev/null +++ b/tests/test_api/test_methods/test_set_sticker_set_thumbnail.py @@ -0,0 +1,22 @@ +from aiogram.methods import Request, SetStickerSetThumbnail +from tests.mocked_bot import MockedBot + + +class TestSetStickerSetThumbnail: + async def test_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetStickerSetThumbnail, ok=True, result=None) + + response: bool = await SetStickerSetThumbnail(name="test", user_id=42) + request: Request = bot.get_request() + assert request.method == "setStickerSetThumbnail" + # assert request.data == {} + assert response == prepare_result.result + + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetStickerSetThumbnail, ok=True, result=None) + + response: bool = await bot.set_sticker_set_thumbnail(name="test", user_id=42) + request: Request = bot.get_request() + assert request.method == "setStickerSetThumbnail" + # assert request.data == {} + assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_sticker_set_title.py b/tests/test_api/test_methods/test_set_sticker_set_title.py new file mode 100644 index 00000000..1dc306bc --- /dev/null +++ b/tests/test_api/test_methods/test_set_sticker_set_title.py @@ -0,0 +1,20 @@ +from aiogram.methods import Request, SetStickerEmojiList, SetStickerSetTitle +from tests.mocked_bot import MockedBot + + +class TestSetStickerSetTitle: + async def test_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetStickerSetTitle, ok=True, result=True) + + response: bool = await SetStickerSetTitle(name="test", title="Test") + request: Request = bot.get_request() + assert request.method == "setStickerSetTitle" + assert response == prepare_result.result + + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetStickerSetTitle, ok=True, result=True) + + response: bool = await bot.set_sticker_set_title(name="test", title="Test") + request: Request = bot.get_request() + assert request.method == "setStickerSetTitle" + assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_upload_sticker_file.py b/tests/test_api/test_methods/test_upload_sticker_file.py index f8332815..7a6bded9 100644 --- a/tests/test_api/test_methods/test_upload_sticker_file.py +++ b/tests/test_api/test_methods/test_upload_sticker_file.py @@ -1,3 +1,4 @@ +from aiogram.enums import StickerFormat from aiogram.methods import Request, UploadStickerFile from aiogram.types import BufferedInputFile, File from tests.mocked_bot import MockedBot @@ -10,7 +11,9 @@ class TestUploadStickerFile: ) response: File = await UploadStickerFile( - user_id=42, png_sticker=BufferedInputFile(b"", "file.png") + user_id=42, + sticker=BufferedInputFile(b"", "file.png"), + sticker_format=StickerFormat.STATIC, ) request: Request = bot.get_request() assert request.method == "uploadStickerFile" @@ -22,7 +25,9 @@ class TestUploadStickerFile: ) response: File = await bot.upload_sticker_file( - user_id=42, png_sticker=BufferedInputFile(b"", "file.png") + user_id=42, + sticker=BufferedInputFile(b"", "file.png"), + sticker_format=StickerFormat.STATIC, ) request: Request = bot.get_request() assert request.method == "uploadStickerFile"