From 23abe35212cc1938b754d8c3bebe00e1d9ed77ea Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Tue, 19 Nov 2019 22:44:12 +0200 Subject: [PATCH] Update tests for all methods --- aiogram/api/methods/base.py | 4 +- aiogram/api/methods/send_media_group.py | 5 +- .../test_methods/test_edit_message_media.py | 11 ++- .../test_get_user_profile_photos.py | 1 - .../test_methods/test_send_media_group.py | 82 +++++++++++++++---- .../test_methods/test_send_message.py | 32 ++++++-- .../test_api/test_methods/test_send_photo.py | 32 ++++++-- tests/test_api/test_methods/test_send_poll.py | 48 +++++++++-- .../test_methods/test_send_sticker.py | 32 ++++++-- .../test_api/test_methods/test_send_venue.py | 52 ++++++++++-- .../test_api/test_methods/test_send_video.py | 33 ++++++-- .../test_methods/test_send_video_note.py | 37 +++++++-- .../test_api/test_methods/test_send_voice.py | 33 ++++++-- .../test_methods/test_set_chat_description.py | 11 +-- .../test_methods/test_set_chat_permissions.py | 17 ++-- .../test_methods/test_set_chat_photo.py | 17 ++-- .../test_methods/test_set_chat_sticker_set.py | 12 +-- .../test_methods/test_set_chat_title.py | 11 +-- .../test_methods/test_set_game_score.py | 19 +++-- .../test_set_passport_data_errors.py | 12 ++- .../test_set_sticker_position_in_set.py | 11 +-- .../test_api/test_methods/test_set_webhook.py | 12 +-- .../test_stop_message_live_location.py | 19 +++-- tests/test_api/test_methods/test_stop_poll.py | 31 +++++-- .../test_methods/test_unban_chat_member.py | 11 +-- .../test_methods/test_unpin_chat_message.py | 11 +-- .../test_methods/test_upload_sticker_file.py | 21 +++-- 27 files changed, 428 insertions(+), 189 deletions(-) diff --git a/aiogram/api/methods/base.py b/aiogram/api/methods/base.py index ee475913..6ed25176 100644 --- a/aiogram/api/methods/base.py +++ b/aiogram/api/methods/base.py @@ -4,7 +4,7 @@ import abc import secrets from typing import TYPE_CHECKING, Any, Dict, Generic, Optional, Type, TypeVar -from pydantic import BaseConfig, BaseModel +from pydantic import BaseConfig, BaseModel, Extra from pydantic.generics import GenericModel from ..types import InputFile, ResponseParameters @@ -35,7 +35,7 @@ class Response(ResponseParameters, GenericModel, Generic[T]): class TelegramMethod(abc.ABC, BaseModel, Generic[T]): class Config(BaseConfig): # use_enum_values = True - # extra = Extra.allow + extra = Extra.allow allow_population_by_field_name = True arbitrary_types_allowed = True orm_mode = True diff --git a/aiogram/api/methods/send_media_group.py b/aiogram/api/methods/send_media_group.py index 0f8aebcd..ce713b14 100644 --- a/aiogram/api/methods/send_media_group.py +++ b/aiogram/api/methods/send_media_group.py @@ -33,9 +33,8 @@ class SendMediaGroup(TelegramMethod[List[Message]]): return Request(method="sendMediaGroup", data=data, files=files) - def prepare_input_media(self, data: Dict[str, Any], files: Dict[str, InputFile]) -> None: - if not self.media: - return + @staticmethod + def prepare_input_media(data: Dict[str, Any], files: Dict[str, InputFile]) -> None: for input_media in data.get("media", []): # type: Dict[str, Union[str, InputFile]] if ( "media" in input_media diff --git a/tests/test_api/test_methods/test_edit_message_media.py b/tests/test_api/test_methods/test_edit_message_media.py index 11f94be4..de3be9df 100644 --- a/tests/test_api/test_methods/test_edit_message_media.py +++ b/tests/test_api/test_methods/test_edit_message_media.py @@ -1,9 +1,8 @@ from typing import Union import pytest - from aiogram.api.methods import EditMessageMedia, Request -from aiogram.api.types import InputMedia, Message +from aiogram.api.types import BufferedInputFile, InputMedia, InputMediaPhoto, Message from tests.mocked_bot import MockedBot @@ -12,7 +11,9 @@ class TestEditMessageMedia: async def test_method(self, bot: MockedBot): prepare_result = bot.add_result_for(EditMessageMedia, ok=True, result=True) - response: Union[Message, bool] = await EditMessageMedia(media=InputMedia()) + response: Union[Message, bool] = await EditMessageMedia( + media=InputMediaPhoto(media=BufferedInputFile(b"", "photo.png")) + ) request: Request = bot.get_request() assert request.method == "editMessageMedia" assert response == prepare_result.result @@ -21,7 +22,9 @@ class TestEditMessageMedia: async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(EditMessageMedia, ok=True, result=True) - response: Union[Message, bool] = await bot.edit_message_media(media=InputMedia()) + response: Union[Message, bool] = await bot.edit_message_media( + media=InputMediaPhoto(media=BufferedInputFile(b"", "photo.png")) + ) request: Request = bot.get_request() assert request.method == "editMessageMedia" assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_user_profile_photos.py b/tests/test_api/test_methods/test_get_user_profile_photos.py index 9d277f98..d30ee6dd 100644 --- a/tests/test_api/test_methods/test_get_user_profile_photos.py +++ b/tests/test_api/test_methods/test_get_user_profile_photos.py @@ -5,7 +5,6 @@ from aiogram.api.types import PhotoSize, UserProfilePhotos from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestGetUserProfilePhotos: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): diff --git a/tests/test_api/test_methods/test_send_media_group.py b/tests/test_api/test_methods/test_send_media_group.py index 93d58b36..e9784742 100644 --- a/tests/test_api/test_methods/test_send_media_group.py +++ b/tests/test_api/test_methods/test_send_media_group.py @@ -1,31 +1,85 @@ +import datetime from typing import List import pytest - from aiogram.api.methods import Request, SendMediaGroup -from aiogram.api.types import Message, InputMediaPhoto +from aiogram.api.types import ( + BufferedInputFile, + Chat, + InputMediaPhoto, + InputMediaVideo, + Message, + PhotoSize, + Video, +) from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSendMediaGroup: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendMediaGroup, ok=True, result=...) + prepare_result = bot.add_result_for( + SendMediaGroup, + ok=True, + result=[ + Message( + message_id=42, + date=datetime.datetime.now(), + photo=[PhotoSize(file_id="file id", width=42, height=42)], + media_group_id="media group", + chat=Chat(id=42, type="private"), + ), + Message( + message_id=43, + date=datetime.datetime.now(), + video=Video(file_id="file id", width=42, height=42, duration=0), + media_group_id="media group", + chat=Chat(id=42, type="private"), + ), + ], + ) response: List[Message] = await SendMediaGroup( - chat_id=42, media=[InputMediaPhoto(media="file id")] + chat_id=42, + media=[ + InputMediaPhoto(media="file id"), + InputMediaVideo(media=BufferedInputFile(b"", "video.mp4")), + ], ) request: Request = bot.get_request() assert request.method == "sendMediaGroup" assert response == prepare_result.result - # - # @pytest.mark.asyncio - # async def test_bot_method(self, bot: MockedBot): - # prepare_result = bot.add_result_for(SendMediaGroup, ok=True, result=None) - # - # response: List[Message] = await bot.send_media_group(chat_id=..., media=...) - # request: Request = bot.get_request() - # assert request.method == "sendMediaGroup" - # assert response == prepare_result.result + @pytest.mark.asyncio + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for( + SendMediaGroup, + ok=True, + result=[ + Message( + message_id=42, + date=datetime.datetime.now(), + photo=[PhotoSize(file_id="file id", width=42, height=42)], + media_group_id="media group", + chat=Chat(id=42, type="private"), + ), + Message( + message_id=43, + date=datetime.datetime.now(), + video=Video(file_id="file id", width=42, height=42, duration=0), + media_group_id="media group", + chat=Chat(id=42, type="private"), + ), + ], + ) + + response: List[Message] = await bot.send_media_group( + chat_id=42, + media=[ + InputMediaPhoto(media="file id"), + InputMediaVideo(media=BufferedInputFile(b"", "video.mp4")), + ], + ) + request: Request = bot.get_request() + assert request.method == "sendMediaGroup" + assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_message.py b/tests/test_api/test_methods/test_send_message.py index 6fb8d34a..9c09284e 100644 --- a/tests/test_api/test_methods/test_send_message.py +++ b/tests/test_api/test_methods/test_send_message.py @@ -1,27 +1,45 @@ +import datetime + import pytest from aiogram.api.methods import Request, SendMessage +from aiogram.api.types import Chat, Message from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSendMessage: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendMessage, ok=True, result=None) + prepare_result = bot.add_result_for( + SendMessage, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + text="test", + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await SendMessage(chat_id=..., text=...) + response: Message = await SendMessage(chat_id=42, text="test") request: Request = bot.get_request() assert request.method == "sendMessage" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendMessage, ok=True, result=None) + prepare_result = bot.add_result_for( + SendMessage, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + text="test", + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await bot.send_message(chat_id=..., text=...) + response: Message = await bot.send_message(chat_id=42, text="test") request: Request = bot.get_request() assert request.method == "sendMessage" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_photo.py b/tests/test_api/test_methods/test_send_photo.py index 08f02ead..82ef4a84 100644 --- a/tests/test_api/test_methods/test_send_photo.py +++ b/tests/test_api/test_methods/test_send_photo.py @@ -1,27 +1,45 @@ +import datetime + import pytest from aiogram.api.methods import Request, SendPhoto +from aiogram.api.types import Chat, Message, PhotoSize from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSendPhoto: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendPhoto, ok=True, result=None) + prepare_result = bot.add_result_for( + SendPhoto, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + photo=[PhotoSize(file_id="file id", width=42, height=42)], + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await SendPhoto(chat_id=..., photo=...) + response: Message = await SendPhoto(chat_id=42, photo="file id") request: Request = bot.get_request() assert request.method == "sendPhoto" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendPhoto, ok=True, result=None) + prepare_result = bot.add_result_for( + SendPhoto, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + photo=[PhotoSize(file_id="file id", width=42, height=42)], + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await bot.send_photo(chat_id=..., photo=...) + response: Message = await bot.send_photo(chat_id=42, photo="file id") request: Request = bot.get_request() assert request.method == "sendPhoto" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_poll.py b/tests/test_api/test_methods/test_send_poll.py index d7a96ab1..50bc488c 100644 --- a/tests/test_api/test_methods/test_send_poll.py +++ b/tests/test_api/test_methods/test_send_poll.py @@ -1,27 +1,61 @@ +import datetime + import pytest from aiogram.api.methods import Request, SendPoll +from aiogram.api.types import Chat, Message, Poll, PollOption from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSendPoll: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendPoll, ok=True, result=None) + prepare_result = bot.add_result_for( + SendPoll, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + poll=Poll( + id="QA", + question="Q", + options=[ + PollOption(text="A", voter_count=0), + PollOption(text="B", voter_count=0), + ], + is_closed=False, + ), + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await SendPoll(chat_id=..., question=..., options=...) + response: Message = await SendPoll(chat_id=42, question="Q?", options=["A", "B"]) request: Request = bot.get_request() assert request.method == "sendPoll" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendPoll, ok=True, result=None) + prepare_result = bot.add_result_for( + SendPoll, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + poll=Poll( + id="QA", + question="Q", + options=[ + PollOption(text="A", voter_count=0), + PollOption(text="B", voter_count=0), + ], + is_closed=False, + ), + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await bot.send_poll(chat_id=..., question=..., options=...) + response: Message = await bot.send_poll(chat_id=42, question="Q?", options=["A", "B"]) request: Request = bot.get_request() assert request.method == "sendPoll" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_sticker.py b/tests/test_api/test_methods/test_send_sticker.py index 81a4e345..8ed2fe46 100644 --- a/tests/test_api/test_methods/test_send_sticker.py +++ b/tests/test_api/test_methods/test_send_sticker.py @@ -1,27 +1,45 @@ +import datetime + import pytest from aiogram.api.methods import Request, SendSticker +from aiogram.api.types import Chat, Message, Sticker from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSendSticker: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendSticker, ok=True, result=None) + prepare_result = bot.add_result_for( + SendSticker, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + sticker=Sticker(file_id="file id", width=42, height=42, is_animated=False), + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await SendSticker(chat_id=..., sticker=...) + response: Message = await SendSticker(chat_id=42, sticker="file id") request: Request = bot.get_request() assert request.method == "sendSticker" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendSticker, ok=True, result=None) + prepare_result = bot.add_result_for( + SendSticker, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + sticker=Sticker(file_id="file id", width=42, height=42, is_animated=False), + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await bot.send_sticker(chat_id=..., sticker=...) + response: Message = await bot.send_sticker(chat_id=42, sticker="file id") request: Request = bot.get_request() assert request.method == "sendSticker" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_venue.py b/tests/test_api/test_methods/test_send_venue.py index f2d09cea..bad987af 100644 --- a/tests/test_api/test_methods/test_send_venue.py +++ b/tests/test_api/test_methods/test_send_venue.py @@ -1,31 +1,69 @@ +import datetime + import pytest from aiogram.api.methods import Request, SendVenue +from aiogram.api.types import Chat, Location, Message, Venue from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSendVenue: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendVenue, ok=True, result=None) + prepare_result = bot.add_result_for( + SendVenue, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + venue=Venue( + location=Location(latitude=3.14, longitude=3.14), + title="Cupboard Under the Stairs", + address="Under the stairs, 4 Privet Drive, " + "Little Whinging, Surrey, England, Great Britain", + ), + chat=Chat(id=42, type="private"), + ), + ) response: Message = await SendVenue( - chat_id=..., latitude=..., longitude=..., title=..., address=... + chat_id=42, + latitude=3.14, + longitude=3.14, + title="Cupboard Under the Stairs", + address="Under the stairs, 4 Privet Drive, " + "Little Whinging, Surrey, England, Great Britain", ) request: Request = bot.get_request() assert request.method == "sendVenue" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendVenue, ok=True, result=None) + prepare_result = bot.add_result_for( + SendVenue, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + venue=Venue( + location=Location(latitude=3.14, longitude=3.14), + title="Cupboard Under the Stairs", + address="Under the stairs, 4 Privet Drive, " + "Little Whinging, Surrey, England, Great Britain", + ), + chat=Chat(id=42, type="private"), + ), + ) response: Message = await bot.send_venue( - chat_id=..., latitude=..., longitude=..., title=..., address=... + chat_id=42, + latitude=3.14, + longitude=3.14, + title="Cupboard Under the Stairs", + address="Under the stairs, 4 Privet Drive, " + "Little Whinging, Surrey, England, Great Britain", ) request: Request = bot.get_request() assert request.method == "sendVenue" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_video.py b/tests/test_api/test_methods/test_send_video.py index ea3c9220..e10f90df 100644 --- a/tests/test_api/test_methods/test_send_video.py +++ b/tests/test_api/test_methods/test_send_video.py @@ -1,27 +1,44 @@ -import pytest +import datetime +import pytest from aiogram.api.methods import Request, SendVideo +from aiogram.api.types import Chat, Message, Video from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSendVideo: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendVideo, ok=True, result=None) + prepare_result = bot.add_result_for( + SendVideo, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + video=Video(file_id="file id", width=42, height=42, duration=0), + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await SendVideo(chat_id=..., video=...) + response: Message = await SendVideo(chat_id=42, video="file id") request: Request = bot.get_request() assert request.method == "sendVideo" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendVideo, ok=True, result=None) + prepare_result = bot.add_result_for( + SendVideo, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + video=Video(file_id="file id", width=42, height=42, duration=0), + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await bot.send_video(chat_id=..., video=...) + response: Message = await bot.send_video(chat_id=42, video="file id") request: Request = bot.get_request() assert request.method == "sendVideo" - # assert request.data == {} 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 e5b27f68..7a906d3c 100644 --- a/tests/test_api/test_methods/test_send_video_note.py +++ b/tests/test_api/test_methods/test_send_video_note.py @@ -1,27 +1,48 @@ -import pytest +import datetime +import pytest from aiogram.api.methods import Request, SendVideoNote +from aiogram.api.types import BufferedInputFile, Chat, Message, VideoNote from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSendVideoNote: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendVideoNote, ok=True, result=None) + prepare_result = bot.add_result_for( + SendVideoNote, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + video_note=VideoNote(file_id="file id", length=0, duration=0), + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await SendVideoNote(chat_id=..., video_note=...) + response: Message = await SendVideoNote( + chat_id=42, video_note="file id", thumb=BufferedInputFile(b"", "file.png") + ) request: Request = bot.get_request() assert request.method == "sendVideoNote" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendVideoNote, ok=True, result=None) + prepare_result = bot.add_result_for( + SendVideoNote, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + video_note=VideoNote(file_id="file id", length=0, duration=0), + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await bot.send_video_note(chat_id=..., video_note=...) + response: Message = await bot.send_video_note( + chat_id=42, video_note="file id", thumb=BufferedInputFile(b"", "file.png") + ) request: Request = bot.get_request() assert request.method == "sendVideoNote" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_voice.py b/tests/test_api/test_methods/test_send_voice.py index 2bed25b6..0699f2f1 100644 --- a/tests/test_api/test_methods/test_send_voice.py +++ b/tests/test_api/test_methods/test_send_voice.py @@ -1,27 +1,44 @@ -import pytest +import datetime +import pytest from aiogram.api.methods import Request, SendVoice +from aiogram.api.types import Chat, Message, Voice from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSendVoice: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendVoice, ok=True, result=None) + prepare_result = bot.add_result_for( + SendVoice, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + voice=Voice(file_id="file id", duration=0), + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await SendVoice(chat_id=..., voice=...) + response: Message = await SendVoice(chat_id=42, voice="file id") request: Request = bot.get_request() assert request.method == "sendVoice" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendVoice, ok=True, result=None) + prepare_result = bot.add_result_for( + SendVoice, + ok=True, + result=Message( + message_id=42, + date=datetime.datetime.now(), + voice=Voice(file_id="file id", duration=0), + chat=Chat(id=42, type="private"), + ), + ) - response: Message = await bot.send_voice(chat_id=..., voice=...) + response: Message = await bot.send_voice(chat_id=42, voice="file id") request: Request = bot.get_request() assert request.method == "sendVoice" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_chat_description.py b/tests/test_api/test_methods/test_set_chat_description.py index 8ac46632..219bbc7e 100644 --- a/tests/test_api/test_methods/test_set_chat_description.py +++ b/tests/test_api/test_methods/test_set_chat_description.py @@ -4,24 +4,21 @@ from aiogram.api.methods import Request, SetChatDescription from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSetChatDescription: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatDescription, ok=True, result=None) + prepare_result = bot.add_result_for(SetChatDescription, ok=True, result=True) - response: bool = await SetChatDescription(chat_id=...) + response: bool = await SetChatDescription(chat_id=-42, description='awesome chat') request: Request = bot.get_request() assert request.method == "setChatDescription" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatDescription, ok=True, result=None) + prepare_result = bot.add_result_for(SetChatDescription, ok=True, result=True) - response: bool = await bot.set_chat_description(chat_id=...) + response: bool = await bot.set_chat_description(chat_id=-42, description='awesome chat') request: Request = bot.get_request() assert request.method == "setChatDescription" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_chat_permissions.py b/tests/test_api/test_methods/test_set_chat_permissions.py index 933ed677..ae85cbbc 100644 --- a/tests/test_api/test_methods/test_set_chat_permissions.py +++ b/tests/test_api/test_methods/test_set_chat_permissions.py @@ -1,27 +1,28 @@ import pytest - from aiogram.api.methods import Request, SetChatPermissions +from aiogram.api.types import ChatPermissions from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSetChatPermissions: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatPermissions, ok=True, result=None) + prepare_result = bot.add_result_for(SetChatPermissions, ok=True, result=True) - response: bool = await SetChatPermissions(chat_id=..., permissions=...) + response: bool = await SetChatPermissions( + chat_id=-42, permissions=ChatPermissions(can_send_messages=False) + ) request: Request = bot.get_request() assert request.method == "setChatPermissions" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatPermissions, ok=True, result=None) + prepare_result = bot.add_result_for(SetChatPermissions, ok=True, result=True) - response: bool = await bot.set_chat_permissions(chat_id=..., permissions=...) + response: bool = await bot.set_chat_permissions( + chat_id=-42, permissions=ChatPermissions(can_send_messages=False) + ) request: Request = bot.get_request() assert request.method == "setChatPermissions" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_chat_photo.py b/tests/test_api/test_methods/test_set_chat_photo.py index ce20f997..5f4901ed 100644 --- a/tests/test_api/test_methods/test_set_chat_photo.py +++ b/tests/test_api/test_methods/test_set_chat_photo.py @@ -1,27 +1,28 @@ import pytest - from aiogram.api.methods import Request, SetChatPhoto +from aiogram.api.types import BufferedInputFile, InputFile from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSetChatPhoto: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatPhoto, ok=True, result=None) + prepare_result = bot.add_result_for(SetChatPhoto, ok=True, result=True) - response: bool = await SetChatPhoto(chat_id=..., photo=...) + response: bool = await SetChatPhoto( + chat_id=-42, photo=BufferedInputFile(b"", filename="file.png") + ) request: Request = bot.get_request() assert request.method == "setChatPhoto" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatPhoto, ok=True, result=None) + prepare_result = bot.add_result_for(SetChatPhoto, ok=True, result=True) - response: bool = await bot.set_chat_photo(chat_id=..., photo=...) + response: bool = await bot.set_chat_photo( + chat_id=-42, photo=BufferedInputFile(b"", filename="file.png") + ) request: Request = bot.get_request() assert request.method == "setChatPhoto" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_chat_sticker_set.py b/tests/test_api/test_methods/test_set_chat_sticker_set.py index c8b0108e..fff8239e 100644 --- a/tests/test_api/test_methods/test_set_chat_sticker_set.py +++ b/tests/test_api/test_methods/test_set_chat_sticker_set.py @@ -1,27 +1,23 @@ import pytest - from aiogram.api.methods import Request, SetChatStickerSet from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSetChatStickerSet: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatStickerSet, ok=True, result=None) + prepare_result = bot.add_result_for(SetChatStickerSet, ok=True, result=True) - response: bool = await SetChatStickerSet(chat_id=..., sticker_set_name=...) + response: bool = await SetChatStickerSet(chat_id=-42, sticker_set_name="test") request: Request = bot.get_request() assert request.method == "setChatStickerSet" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatStickerSet, ok=True, result=None) + prepare_result = bot.add_result_for(SetChatStickerSet, ok=True, result=True) - response: bool = await bot.set_chat_sticker_set(chat_id=..., sticker_set_name=...) + response: bool = await bot.set_chat_sticker_set(chat_id=-42, sticker_set_name="test") request: Request = bot.get_request() assert request.method == "setChatStickerSet" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_chat_title.py b/tests/test_api/test_methods/test_set_chat_title.py index cce2b768..de558ebd 100644 --- a/tests/test_api/test_methods/test_set_chat_title.py +++ b/tests/test_api/test_methods/test_set_chat_title.py @@ -4,24 +4,21 @@ from aiogram.api.methods import Request, SetChatTitle from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSetChatTitle: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatTitle, ok=True, result=None) + prepare_result = bot.add_result_for(SetChatTitle, ok=True, result=True) - response: bool = await SetChatTitle(chat_id=..., title=...) + response: bool = await SetChatTitle(chat_id=-42, title='test chat') request: Request = bot.get_request() assert request.method == "setChatTitle" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatTitle, ok=True, result=None) + prepare_result = bot.add_result_for(SetChatTitle, ok=True, result=True) - response: bool = await bot.set_chat_title(chat_id=..., title=...) + response: bool = await bot.set_chat_title(chat_id=-42, title='test chat') request: Request = bot.get_request() assert request.method == "setChatTitle" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_game_score.py b/tests/test_api/test_methods/test_set_game_score.py index 27183a7d..01c7179d 100644 --- a/tests/test_api/test_methods/test_set_game_score.py +++ b/tests/test_api/test_methods/test_set_game_score.py @@ -1,27 +1,30 @@ -import pytest +from typing import Union +import pytest from aiogram.api.methods import Request, SetGameScore +from aiogram.api.types import Message from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSetGameScore: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetGameScore, ok=True, result=None) + prepare_result = bot.add_result_for(SetGameScore, ok=True, result=True) - response: Union[Message, bool] = await SetGameScore(user_id=..., score=...) + response: Union[Message, bool] = await SetGameScore( + user_id=42, score=100500, inline_message_id="inline message" + ) request: Request = bot.get_request() assert request.method == "setGameScore" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetGameScore, ok=True, result=None) + prepare_result = bot.add_result_for(SetGameScore, ok=True, result=True) - response: Union[Message, bool] = await bot.set_game_score(user_id=..., score=...) + response: Union[Message, bool] = await bot.set_game_score( + user_id=42, score=100500, inline_message_id="inline message" + ) request: Request = bot.get_request() assert request.method == "setGameScore" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_passport_data_errors.py b/tests/test_api/test_methods/test_set_passport_data_errors.py index fe74df09..6d4fb76e 100644 --- a/tests/test_api/test_methods/test_set_passport_data_errors.py +++ b/tests/test_api/test_methods/test_set_passport_data_errors.py @@ -1,27 +1,25 @@ import pytest from aiogram.api.methods import Request, SetPassportDataErrors +from aiogram.api.types import PassportElementError from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSetPassportDataErrors: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetPassportDataErrors, ok=True, result=None) + prepare_result = bot.add_result_for(SetPassportDataErrors, ok=True, result=True) - response: bool = await SetPassportDataErrors(user_id=..., errors=...) + response: bool = await SetPassportDataErrors(user_id=42, errors=[PassportElementError()]) request: Request = bot.get_request() assert request.method == "setPassportDataErrors" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetPassportDataErrors, ok=True, result=None) + prepare_result = bot.add_result_for(SetPassportDataErrors, ok=True, result=True) - response: bool = await bot.set_passport_data_errors(user_id=..., errors=...) + response: bool = await bot.set_passport_data_errors(user_id=42, errors=[PassportElementError()]) request: Request = bot.get_request() assert request.method == "setPassportDataErrors" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_sticker_position_in_set.py b/tests/test_api/test_methods/test_set_sticker_position_in_set.py index a31f7920..da84e691 100644 --- a/tests/test_api/test_methods/test_set_sticker_position_in_set.py +++ b/tests/test_api/test_methods/test_set_sticker_position_in_set.py @@ -4,24 +4,21 @@ from aiogram.api.methods import Request, SetStickerPositionInSet from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSetStickerPositionInSet: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetStickerPositionInSet, ok=True, result=None) + prepare_result = bot.add_result_for(SetStickerPositionInSet, ok=True, result=True) - response: bool = await SetStickerPositionInSet(sticker=..., position=...) + response: bool = await SetStickerPositionInSet(sticker='sticker', position=42) request: Request = bot.get_request() assert request.method == "setStickerPositionInSet" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetStickerPositionInSet, ok=True, result=None) + prepare_result = bot.add_result_for(SetStickerPositionInSet, ok=True, result=True) - response: bool = await bot.set_sticker_position_in_set(sticker=..., position=...) + response: bool = await bot.set_sticker_position_in_set(sticker='sticker', position=42) request: Request = bot.get_request() assert request.method == "setStickerPositionInSet" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_webhook.py b/tests/test_api/test_methods/test_set_webhook.py index cccee5d3..e4a9b3c0 100644 --- a/tests/test_api/test_methods/test_set_webhook.py +++ b/tests/test_api/test_methods/test_set_webhook.py @@ -1,27 +1,23 @@ import pytest - from aiogram.api.methods import Request, SetWebhook from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestSetWebhook: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetWebhook, ok=True, result=None) + prepare_result = bot.add_result_for(SetWebhook, ok=True, result=True) - response: bool = await SetWebhook(url=...) + response: bool = await SetWebhook(url="https://example.com") request: Request = bot.get_request() assert request.method == "setWebhook" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetWebhook, ok=True, result=None) + prepare_result = bot.add_result_for(SetWebhook, ok=True, result=True) - response: bool = await bot.set_webhook(url=...) + response: bool = await bot.set_webhook(url="https://example.com") request: Request = bot.get_request() assert request.method == "setWebhook" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_stop_message_live_location.py b/tests/test_api/test_methods/test_stop_message_live_location.py index e7d927c2..a9834897 100644 --- a/tests/test_api/test_methods/test_stop_message_live_location.py +++ b/tests/test_api/test_methods/test_stop_message_live_location.py @@ -1,27 +1,30 @@ -import pytest +from typing import Union +import pytest from aiogram.api.methods import Request, StopMessageLiveLocation +from aiogram.api.types import Message from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestStopMessageLiveLocation: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(StopMessageLiveLocation, ok=True, result=None) + prepare_result = bot.add_result_for(StopMessageLiveLocation, ok=True, result=True) - response: Union[Message, bool] = await StopMessageLiveLocation() + response: Union[Message, bool] = await StopMessageLiveLocation( + inline_message_id="inline message id" + ) request: Request = bot.get_request() assert request.method == "stopMessageLiveLocation" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(StopMessageLiveLocation, ok=True, result=None) + prepare_result = bot.add_result_for(StopMessageLiveLocation, ok=True, result=True) - response: Union[Message, bool] = await bot.stop_message_live_location() + response: Union[Message, bool] = await bot.stop_message_live_location( + inline_message_id="inline message id" + ) request: Request = bot.get_request() assert request.method == "stopMessageLiveLocation" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_stop_poll.py b/tests/test_api/test_methods/test_stop_poll.py index 5141d2c4..b7284e40 100644 --- a/tests/test_api/test_methods/test_stop_poll.py +++ b/tests/test_api/test_methods/test_stop_poll.py @@ -1,27 +1,42 @@ import pytest - from aiogram.api.methods import Request, StopPoll +from aiogram.api.types import Poll, PollOption from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestStopPoll: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(StopPoll, ok=True, result=None) + prepare_result = bot.add_result_for( + StopPoll, + ok=True, + result=Poll( + id="QA", + question="Q", + options=[PollOption(text="A", voter_count=0), PollOption(text="B", voter_count=0)], + is_closed=False, + ), + ) - response: Poll = await StopPoll(chat_id=..., message_id=...) + response: Poll = await StopPoll(chat_id=42, message_id=42) request: Request = bot.get_request() assert request.method == "stopPoll" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(StopPoll, ok=True, result=None) + prepare_result = bot.add_result_for( + StopPoll, + ok=True, + result=Poll( + id="QA", + question="Q", + options=[PollOption(text="A", voter_count=0), PollOption(text="B", voter_count=0)], + is_closed=False, + ), + ) - response: Poll = await bot.stop_poll(chat_id=..., message_id=...) + response: Poll = await bot.stop_poll(chat_id=42, message_id=42) request: Request = bot.get_request() assert request.method == "stopPoll" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_unban_chat_member.py b/tests/test_api/test_methods/test_unban_chat_member.py index 9ca14ad2..64abe810 100644 --- a/tests/test_api/test_methods/test_unban_chat_member.py +++ b/tests/test_api/test_methods/test_unban_chat_member.py @@ -4,24 +4,21 @@ from aiogram.api.methods import Request, UnbanChatMember from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestUnbanChatMember: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(UnbanChatMember, ok=True, result=None) + prepare_result = bot.add_result_for(UnbanChatMember, ok=True, result=True) - response: bool = await UnbanChatMember(chat_id=..., user_id=...) + response: bool = await UnbanChatMember(chat_id=-42, user_id=42) request: Request = bot.get_request() assert request.method == "unbanChatMember" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(UnbanChatMember, ok=True, result=None) + prepare_result = bot.add_result_for(UnbanChatMember, ok=True, result=True) - response: bool = await bot.unban_chat_member(chat_id=..., user_id=...) + response: bool = await bot.unban_chat_member(chat_id=-42, user_id=42) request: Request = bot.get_request() assert request.method == "unbanChatMember" - # assert request.data == {} assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_unpin_chat_message.py b/tests/test_api/test_methods/test_unpin_chat_message.py index a12efeab..315b3165 100644 --- a/tests/test_api/test_methods/test_unpin_chat_message.py +++ b/tests/test_api/test_methods/test_unpin_chat_message.py @@ -4,24 +4,21 @@ from aiogram.api.methods import Request, UnpinChatMessage from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestUnpinChatMessage: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(UnpinChatMessage, ok=True, result=None) + prepare_result = bot.add_result_for(UnpinChatMessage, ok=True, result=True) - response: bool = await UnpinChatMessage(chat_id=...) + response: bool = await UnpinChatMessage(chat_id=-42) request: Request = bot.get_request() assert request.method == "unpinChatMessage" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(UnpinChatMessage, ok=True, result=None) + prepare_result = bot.add_result_for(UnpinChatMessage, ok=True, result=True) - response: bool = await bot.unpin_chat_message(chat_id=...) + response: bool = await bot.unpin_chat_message(chat_id=-42) request: Request = bot.get_request() assert request.method == "unpinChatMessage" - # assert request.data == {} 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 1a24522d..8bad0058 100644 --- a/tests/test_api/test_methods/test_upload_sticker_file.py +++ b/tests/test_api/test_methods/test_upload_sticker_file.py @@ -1,27 +1,32 @@ import pytest - from aiogram.api.methods import Request, UploadStickerFile +from aiogram.api.types import BufferedInputFile, File from tests.mocked_bot import MockedBot -@pytest.mark.skip class TestUploadStickerFile: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(UploadStickerFile, ok=True, result=None) + prepare_result = bot.add_result_for( + UploadStickerFile, ok=True, result=File(file_id="file id") + ) - response: File = await UploadStickerFile(user_id=..., png_sticker=...) + response: File = await UploadStickerFile( + user_id=42, png_sticker=BufferedInputFile(b"", "file.png") + ) request: Request = bot.get_request() assert request.method == "uploadStickerFile" - # assert request.data == {} assert response == prepare_result.result @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(UploadStickerFile, ok=True, result=None) + prepare_result = bot.add_result_for( + UploadStickerFile, ok=True, result=File(file_id="file id") + ) - response: File = await bot.upload_sticker_file(user_id=..., png_sticker=...) + response: File = await bot.upload_sticker_file( + user_id=42, png_sticker=BufferedInputFile(b"", "file.png") + ) request: Request = bot.get_request() assert request.method == "uploadStickerFile" - # assert request.data == {} assert response == prepare_result.result