From f5de712fcce18e866453491edf165dffe8fd1f67 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sun, 14 Aug 2022 15:53:20 +0300 Subject: [PATCH] Update tests. Added missing files. --- aiogram/methods/get_custom_emoji_stickers.py | 27 +++++++++++++ .../api/methods/get_custom_emoji_stickers.rst | 37 ++++++++++++++++++ .../test_get_custom_emoji_stickers.py | 39 ++++++++++++++++--- .../test_methods/test_get_sticker_set.py | 6 ++- .../test_methods/test_send_sticker.py | 2 + tests/test_utils/test_text_decorations.py | 12 +++++- 6 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 aiogram/methods/get_custom_emoji_stickers.py create mode 100644 docs/api/methods/get_custom_emoji_stickers.rst diff --git a/aiogram/methods/get_custom_emoji_stickers.py b/aiogram/methods/get_custom_emoji_stickers.py new file mode 100644 index 00000000..bdc265e0 --- /dev/null +++ b/aiogram/methods/get_custom_emoji_stickers.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Dict, List + +from ..types import Sticker +from .base import Request, TelegramMethod + +if TYPE_CHECKING: + from ..client.bot import Bot + + +class GetCustomEmojiStickers(TelegramMethod[List[Sticker]]): + """ + Use this method to get information about custom emoji stickers by their identifiers. Returns an Array of :class:`aiogram.types.sticker.Sticker` objects. + + Source: https://core.telegram.org/bots/api#getcustomemojistickers + """ + + __returning__ = List[Sticker] + + custom_emoji_ids: List[str] + """List of custom emoji identifiers. At most 200 custom emoji identifiers can be specified.""" + + def build_request(self, bot: Bot) -> Request: + data: Dict[str, Any] = self.dict() + + return Request(method="getCustomEmojiStickers", data=data) diff --git a/docs/api/methods/get_custom_emoji_stickers.rst b/docs/api/methods/get_custom_emoji_stickers.rst new file mode 100644 index 00000000..9c7455fd --- /dev/null +++ b/docs/api/methods/get_custom_emoji_stickers.rst @@ -0,0 +1,37 @@ +###################### +getCustomEmojiStickers +###################### + +Returns: :obj:`List[Sticker]` + +.. automodule:: aiogram.methods.get_custom_emoji_stickers + :members: + :member-order: bysource + :undoc-members: True + + +Usage +===== + +As bot method +------------- + +.. code-block:: + + result: List[Sticker] = await bot.get_custom_emoji_stickers(...) + + +Method as object +---------------- + +Imports: + +- :code:`from aiogram.methods.get_custom_emoji_stickers import GetCustomEmojiStickers` +- alias: :code:`from aiogram.methods import GetCustomEmojiStickers` + +With specific bot +~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + result: List[Sticker] = await bot(GetCustomEmojiStickers(...)) diff --git a/tests/test_api/test_methods/test_get_custom_emoji_stickers.py b/tests/test_api/test_methods/test_get_custom_emoji_stickers.py index b50e68b1..b47bc4c5 100644 --- a/tests/test_api/test_methods/test_get_custom_emoji_stickers.py +++ b/tests/test_api/test_methods/test_get_custom_emoji_stickers.py @@ -7,14 +7,28 @@ from aiogram.types import Sticker from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestGetCustomEmojiStickers: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(GetCustomEmojiStickers, ok=True, result=None) + prepare_result = bot.add_result_for( + GetCustomEmojiStickers, + ok=True, + result=[ + Sticker( + file_id="file id", + width=42, + height=42, + is_animated=False, + is_video=False, + file_unique_id="file id", + custom_emoji_id="1", + type="custom_emoji", + ) + ], + ) response: List[Sticker] = await GetCustomEmojiStickers( - custom_emoji_ids=..., + custom_emoji_ids=["1"], ) request: Request = bot.get_request() assert request.method == "getCustomEmojiStickers" @@ -23,10 +37,25 @@ class TestGetCustomEmojiStickers: @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(GetCustomEmojiStickers, ok=True, result=None) + prepare_result = bot.add_result_for( + GetCustomEmojiStickers, + ok=True, + result=[ + Sticker( + file_id="file id", + width=42, + height=42, + is_animated=False, + is_video=False, + file_unique_id="file id", + custom_emoji_id="1", + type="custom_emoji", + ) + ], + ) response: List[Sticker] = await bot.get_custom_emoji_stickers( - custom_emoji_ids=..., + custom_emoji_ids=["1", "2"], ) request: Request = bot.get_request() assert request.method == "getCustomEmojiStickers" diff --git a/tests/test_api/test_methods/test_get_sticker_set.py b/tests/test_api/test_methods/test_get_sticker_set.py index d778f1f7..377a81c0 100644 --- a/tests/test_api/test_methods/test_get_sticker_set.py +++ b/tests/test_api/test_methods/test_get_sticker_set.py @@ -17,7 +17,6 @@ class TestGetStickerSet: title="test", is_animated=False, is_video=False, - contains_masks=False, stickers=[ Sticker( file_id="file if", @@ -26,8 +25,10 @@ class TestGetStickerSet: is_animated=False, is_video=False, file_unique_id="file id", + type="regular", ) ], + sticker_type="regular", ), ) @@ -45,7 +46,6 @@ class TestGetStickerSet: title="test", is_animated=False, is_video=False, - contains_masks=False, stickers=[ Sticker( file_id="file if", @@ -54,8 +54,10 @@ class TestGetStickerSet: is_animated=False, is_video=False, file_unique_id="file id", + type="regular", ) ], + sticker_type="regular", ), ) diff --git a/tests/test_api/test_methods/test_send_sticker.py b/tests/test_api/test_methods/test_send_sticker.py index 239065eb..33bce785 100644 --- a/tests/test_api/test_methods/test_send_sticker.py +++ b/tests/test_api/test_methods/test_send_sticker.py @@ -24,6 +24,7 @@ class TestSendSticker: is_animated=False, is_video=False, file_unique_id="file id", + type="regular", ), chat=Chat(id=42, type="private"), ), @@ -48,6 +49,7 @@ class TestSendSticker: is_animated=False, is_video=False, file_unique_id="file id", + type="regular", ), chat=Chat(id=42, type="private"), ), diff --git a/tests/test_utils/test_text_decorations.py b/tests/test_utils/test_text_decorations.py index f87bbfe0..f19e2ae5 100644 --- a/tests/test_utils/test_text_decorations.py +++ b/tests/test_utils/test_text_decorations.py @@ -50,7 +50,12 @@ class TestTextDecoration: [ html_decoration, MessageEntity(type="spoiler", offset=0, length=5), - 'test', + "test", + ], + [ + html_decoration, + MessageEntity(type="custom_emoji", offset=0, length=5, custom_emoji_id="42"), + 'test', ], [ html_decoration, @@ -82,6 +87,11 @@ class TestTextDecoration: [markdown_decoration, MessageEntity(type="email", offset=0, length=5), "test"], [markdown_decoration, MessageEntity(type="phone_number", offset=0, length=5), "test"], [markdown_decoration, MessageEntity(type="spoiler", offset=0, length=5), "|test|"], + [ + markdown_decoration, + MessageEntity(type="custom_emoji", offset=0, length=5, custom_emoji_id="42"), + "[test](tg://emoji?id=42)", + ], [ markdown_decoration, MessageEntity(