From d2d4f337fb2215ee98322059b21031868a100463 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sat, 11 Jan 2020 19:56:38 +0200 Subject: [PATCH] Update tests --- tests/test_api/test_methods/test_get_file.py | 8 +++- .../test_methods/test_get_sticker_set.py | 20 +++++++- .../test_get_user_profile_photos.py | 10 +++- .../test_methods/test_send_animation.py | 8 +++- .../test_api/test_methods/test_send_audio.py | 4 +- .../test_methods/test_send_document.py | 4 +- tests/test_api/test_methods/test_send_game.py | 8 +++- .../test_methods/test_send_media_group.py | 24 ++++++++-- .../test_api/test_methods/test_send_photo.py | 8 +++- .../test_methods/test_send_sticker.py | 16 ++++++- .../test_api/test_methods/test_send_video.py | 8 +++- .../test_methods/test_send_video_note.py | 8 +++- .../test_api/test_methods/test_send_voice.py | 4 +- ...est_set_chat_administrator_custom_title.py | 28 +++++++++++ .../test_methods/test_upload_sticker_file.py | 4 +- tests/test_api/test_types/test_message.py | 48 +++++++++++++++---- 16 files changed, 170 insertions(+), 40 deletions(-) create mode 100644 tests/test_api/test_methods/test_set_chat_administrator_custom_title.py diff --git a/tests/test_api/test_methods/test_get_file.py b/tests/test_api/test_methods/test_get_file.py index 6b8e2ff0..1b8fe22a 100644 --- a/tests/test_api/test_methods/test_get_file.py +++ b/tests/test_api/test_methods/test_get_file.py @@ -8,7 +8,9 @@ from tests.mocked_bot import MockedBot class TestGetFile: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(GetFile, ok=True, result=File(file_id="file id")) + prepare_result = bot.add_result_for( + GetFile, ok=True, result=File(file_id="file id", file_unique_id="file id") + ) response: File = await GetFile(file_id="file id") request: Request = bot.get_request() @@ -17,7 +19,9 @@ class TestGetFile: @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(GetFile, ok=True, result=File(file_id="file id")) + prepare_result = bot.add_result_for( + GetFile, ok=True, result=File(file_id="file id", file_unique_id="file id") + ) response: File = await bot.get_file(file_id="file id") request: Request = bot.get_request() 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 236116ce..130de89a 100644 --- a/tests/test_api/test_methods/test_get_sticker_set.py +++ b/tests/test_api/test_methods/test_get_sticker_set.py @@ -16,7 +16,15 @@ class TestGetStickerSet: title="test", is_animated=False, contains_masks=False, - stickers=[Sticker(file_id="file if", width=42, height=42, is_animated=False)], + stickers=[ + Sticker( + file_id="file if", + width=42, + height=42, + is_animated=False, + file_unique_id="file id", + ) + ], ), ) @@ -35,7 +43,15 @@ class TestGetStickerSet: title="test", is_animated=False, contains_masks=False, - stickers=[Sticker(file_id="file if", width=42, height=42, is_animated=False)], + stickers=[ + Sticker( + file_id="file if", + width=42, + height=42, + is_animated=False, + file_unique_id="file id", + ) + ], ), ) 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 d30ee6dd..093dea82 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 @@ -12,7 +12,10 @@ class TestGetUserProfilePhotos: GetUserProfilePhotos, ok=True, result=UserProfilePhotos( - total_count=1, photos=[[PhotoSize(file_id="file_id", width=42, height=42)]] + total_count=1, + photos=[ + [PhotoSize(file_id="file_id", width=42, height=42, file_unique_id="file id")] + ], ), ) @@ -27,7 +30,10 @@ class TestGetUserProfilePhotos: GetUserProfilePhotos, ok=True, result=UserProfilePhotos( - total_count=1, photos=[[PhotoSize(file_id="file_id", width=42, height=42)]] + total_count=1, + photos=[ + [PhotoSize(file_id="file_id", width=42, height=42, file_unique_id="file id")] + ], ), ) diff --git a/tests/test_api/test_methods/test_send_animation.py b/tests/test_api/test_methods/test_send_animation.py index 06af5218..b02bad5f 100644 --- a/tests/test_api/test_methods/test_send_animation.py +++ b/tests/test_api/test_methods/test_send_animation.py @@ -16,7 +16,9 @@ class TestSendAnimation: result=Message( message_id=42, date=datetime.datetime.now(), - animation=Animation(file_id="file id", width=42, height=42, duration=0), + animation=Animation( + file_id="file id", width=42, height=42, duration=0, file_unique_id="file id" + ), chat=Chat(id=42, type="private"), ), ) @@ -34,7 +36,9 @@ class TestSendAnimation: result=Message( message_id=42, date=datetime.datetime.now(), - animation=Animation(file_id="file id", width=42, height=42, duration=0), + animation=Animation( + file_id="file id", width=42, height=42, duration=0, file_unique_id="file id" + ), chat=Chat(id=42, type="private"), ), ) diff --git a/tests/test_api/test_methods/test_send_audio.py b/tests/test_api/test_methods/test_send_audio.py index c15d6728..fdc06bdb 100644 --- a/tests/test_api/test_methods/test_send_audio.py +++ b/tests/test_api/test_methods/test_send_audio.py @@ -16,7 +16,7 @@ class TestSendAudio: result=Message( message_id=42, date=datetime.datetime.now(), - audio=Audio(file_id="file id", duration=42), + audio=Audio(file_id="file id", duration=42, file_unique_id="file id"), chat=Chat(id=42, type="private"), ), ) @@ -34,7 +34,7 @@ class TestSendAudio: result=Message( message_id=42, date=datetime.datetime.now(), - audio=Audio(file_id="file id", duration=42), + audio=Audio(file_id="file id", duration=42, file_unique_id="file id"), chat=Chat(id=42, type="private"), ), ) diff --git a/tests/test_api/test_methods/test_send_document.py b/tests/test_api/test_methods/test_send_document.py index aebccc1f..5ddd2e6a 100644 --- a/tests/test_api/test_methods/test_send_document.py +++ b/tests/test_api/test_methods/test_send_document.py @@ -16,7 +16,7 @@ class TestSendDocument: result=Message( message_id=42, date=datetime.datetime.now(), - document=Document(file_id="file id"), + document=Document(file_id="file id", file_unique_id="file id"), chat=Chat(id=42, type="private"), ), ) @@ -34,7 +34,7 @@ class TestSendDocument: result=Message( message_id=42, date=datetime.datetime.now(), - document=Document(file_id="file id"), + document=Document(file_id="file id", file_unique_id="file id"), chat=Chat(id=42, type="private"), ), ) diff --git a/tests/test_api/test_methods/test_send_game.py b/tests/test_api/test_methods/test_send_game.py index a26a1cc1..7728c079 100644 --- a/tests/test_api/test_methods/test_send_game.py +++ b/tests/test_api/test_methods/test_send_game.py @@ -19,7 +19,9 @@ class TestSendGame: game=Game( title="title", description="description", - photo=[PhotoSize(file_id="file id", width=42, height=42)], + photo=[ + PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id") + ], ), chat=Chat(id=42, type="private"), ), @@ -41,7 +43,9 @@ class TestSendGame: game=Game( title="title", description="description", - photo=[PhotoSize(file_id="file id", width=42, height=42)], + photo=[ + PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id") + ], ), chat=Chat(id=42, type="private"), ), 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 4a3c495c..14a30ccb 100644 --- a/tests/test_api/test_methods/test_send_media_group.py +++ b/tests/test_api/test_methods/test_send_media_group.py @@ -26,14 +26,22 @@ class TestSendMediaGroup: Message( message_id=42, date=datetime.datetime.now(), - photo=[PhotoSize(file_id="file id", width=42, height=42)], + photo=[ + PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id") + ], 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), + video=Video( + file_id="file id", + width=42, + height=42, + duration=0, + file_unique_id="file id", + ), media_group_id="media group", chat=Chat(id=42, type="private"), ), @@ -60,14 +68,22 @@ class TestSendMediaGroup: Message( message_id=42, date=datetime.datetime.now(), - photo=[PhotoSize(file_id="file id", width=42, height=42)], + photo=[ + PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id") + ], 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), + video=Video( + file_id="file id", + width=42, + height=42, + duration=0, + file_unique_id="file id", + ), media_group_id="media group", chat=Chat(id=42, type="private"), ), diff --git a/tests/test_api/test_methods/test_send_photo.py b/tests/test_api/test_methods/test_send_photo.py index 82ef4a84..2ff2b7c6 100644 --- a/tests/test_api/test_methods/test_send_photo.py +++ b/tests/test_api/test_methods/test_send_photo.py @@ -16,7 +16,9 @@ class TestSendPhoto: result=Message( message_id=42, date=datetime.datetime.now(), - photo=[PhotoSize(file_id="file id", width=42, height=42)], + photo=[ + PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id") + ], chat=Chat(id=42, type="private"), ), ) @@ -34,7 +36,9 @@ class TestSendPhoto: result=Message( message_id=42, date=datetime.datetime.now(), - photo=[PhotoSize(file_id="file id", width=42, height=42)], + photo=[ + PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id") + ], chat=Chat(id=42, type="private"), ), ) diff --git a/tests/test_api/test_methods/test_send_sticker.py b/tests/test_api/test_methods/test_send_sticker.py index 8ed2fe46..8475581e 100644 --- a/tests/test_api/test_methods/test_send_sticker.py +++ b/tests/test_api/test_methods/test_send_sticker.py @@ -16,7 +16,13 @@ class TestSendSticker: result=Message( message_id=42, date=datetime.datetime.now(), - sticker=Sticker(file_id="file id", width=42, height=42, is_animated=False), + sticker=Sticker( + file_id="file id", + width=42, + height=42, + is_animated=False, + file_unique_id="file id", + ), chat=Chat(id=42, type="private"), ), ) @@ -34,7 +40,13 @@ class TestSendSticker: result=Message( message_id=42, date=datetime.datetime.now(), - sticker=Sticker(file_id="file id", width=42, height=42, is_animated=False), + sticker=Sticker( + file_id="file id", + width=42, + height=42, + is_animated=False, + file_unique_id="file id", + ), chat=Chat(id=42, type="private"), ), ) diff --git a/tests/test_api/test_methods/test_send_video.py b/tests/test_api/test_methods/test_send_video.py index 7d6e9c8c..6d52f109 100644 --- a/tests/test_api/test_methods/test_send_video.py +++ b/tests/test_api/test_methods/test_send_video.py @@ -16,7 +16,9 @@ class TestSendVideo: result=Message( message_id=42, date=datetime.datetime.now(), - video=Video(file_id="file id", width=42, height=42, duration=0), + video=Video( + file_id="file id", width=42, height=42, duration=0, file_unique_id="file id" + ), chat=Chat(id=42, type="private"), ), ) @@ -34,7 +36,9 @@ class TestSendVideo: result=Message( message_id=42, date=datetime.datetime.now(), - video=Video(file_id="file id", width=42, height=42, duration=0), + video=Video( + file_id="file id", width=42, height=42, duration=0, file_unique_id="file id" + ), chat=Chat(id=42, type="private"), ), ) 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 704d13f3..bb235bed 100644 --- a/tests/test_api/test_methods/test_send_video_note.py +++ b/tests/test_api/test_methods/test_send_video_note.py @@ -16,7 +16,9 @@ class TestSendVideoNote: result=Message( message_id=42, date=datetime.datetime.now(), - video_note=VideoNote(file_id="file id", length=0, duration=0), + video_note=VideoNote( + file_id="file id", length=0, duration=0, file_unique_id="file id" + ), chat=Chat(id=42, type="private"), ), ) @@ -36,7 +38,9 @@ class TestSendVideoNote: result=Message( message_id=42, date=datetime.datetime.now(), - video_note=VideoNote(file_id="file id", length=0, duration=0), + video_note=VideoNote( + file_id="file id", length=0, duration=0, file_unique_id="file id" + ), chat=Chat(id=42, type="private"), ), ) diff --git a/tests/test_api/test_methods/test_send_voice.py b/tests/test_api/test_methods/test_send_voice.py index 1a7804e1..6dcab09d 100644 --- a/tests/test_api/test_methods/test_send_voice.py +++ b/tests/test_api/test_methods/test_send_voice.py @@ -16,7 +16,7 @@ class TestSendVoice: result=Message( message_id=42, date=datetime.datetime.now(), - voice=Voice(file_id="file id", duration=0), + voice=Voice(file_id="file id", duration=0, file_unique_id="file id"), chat=Chat(id=42, type="private"), ), ) @@ -34,7 +34,7 @@ class TestSendVoice: result=Message( message_id=42, date=datetime.datetime.now(), - voice=Voice(file_id="file id", duration=0), + voice=Voice(file_id="file id", duration=0, file_unique_id="file id"), chat=Chat(id=42, type="private"), ), ) diff --git a/tests/test_api/test_methods/test_set_chat_administrator_custom_title.py b/tests/test_api/test_methods/test_set_chat_administrator_custom_title.py new file mode 100644 index 00000000..e4372c3d --- /dev/null +++ b/tests/test_api/test_methods/test_set_chat_administrator_custom_title.py @@ -0,0 +1,28 @@ +import pytest + +from aiogram.api.methods import Request, SetChatAdministratorCustomTitle, SetChatTitle +from tests.mocked_bot import MockedBot + + +class TestSetChatTitle: + @pytest.mark.asyncio + async def test_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetChatAdministratorCustomTitle, ok=True, result=True) + + response: bool = await SetChatAdministratorCustomTitle( + chat_id=-42, user_id=42, custom_title="test chat" + ) + request: Request = bot.get_request() + assert request.method == "setChatAdministratorCustomTitle" + assert response == prepare_result.result + + @pytest.mark.asyncio + async def test_bot_method(self, bot: MockedBot): + prepare_result = bot.add_result_for(SetChatAdministratorCustomTitle, ok=True, result=True) + + response: bool = await bot.set_chat_administrator_custom_title( + chat_id=-42, user_id=42, custom_title="test chat" + ) + request: Request = bot.get_request() + assert request.method == "setChatAdministratorCustomTitle" + 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 6ab48c6f..a90b395b 100644 --- a/tests/test_api/test_methods/test_upload_sticker_file.py +++ b/tests/test_api/test_methods/test_upload_sticker_file.py @@ -9,7 +9,7 @@ class TestUploadStickerFile: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): prepare_result = bot.add_result_for( - UploadStickerFile, ok=True, result=File(file_id="file id") + UploadStickerFile, ok=True, result=File(file_id="file id", file_unique_id="file id") ) response: File = await UploadStickerFile( @@ -22,7 +22,7 @@ class TestUploadStickerFile: @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( - UploadStickerFile, ok=True, result=File(file_id="file id") + UploadStickerFile, ok=True, result=File(file_id="file id", file_unique_id="file id") ) response: File = await bot.upload_sticker_file( diff --git a/tests/test_api/test_types/test_message.py b/tests/test_api/test_types/test_message.py index f1497be8..cd6c1cb6 100644 --- a/tests/test_api/test_types/test_message.py +++ b/tests/test_api/test_types/test_message.py @@ -45,7 +45,7 @@ class TestMessage: Message( message_id=42, date=datetime.datetime.now(), - audio=Audio(file_id="file id", duration=42), + audio=Audio(file_id="file id", file_unique_id="file id", duration=42), chat=Chat(id=42, type="private"), from_user=User(id=42, is_bot=False, first_name="Test"), ), @@ -55,7 +55,13 @@ class TestMessage: Message( message_id=42, date=datetime.datetime.now(), - animation=Animation(file_id="file id", width=42, height=42, duration=0), + animation=Animation( + file_id="file id", + file_unique_id="file id", + width=42, + height=42, + duration=0, + ), chat=Chat(id=42, type="private"), from_user=User(id=42, is_bot=False, first_name="Test"), ), @@ -65,7 +71,7 @@ class TestMessage: Message( message_id=42, date=datetime.datetime.now(), - document=Document(file_id="file id"), + document=Document(file_id="file id", file_unique_id="file id"), chat=Chat(id=42, type="private"), from_user=User(id=42, is_bot=False, first_name="Test"), ), @@ -78,7 +84,11 @@ class TestMessage: game=Game( title="title", description="description", - photo=[PhotoSize(file_id="file id", width=42, height=42)], + photo=[ + PhotoSize( + file_id="file id", file_unique_id="file id", width=42, height=42 + ) + ], ), chat=Chat(id=42, type="private"), from_user=User(id=42, is_bot=False, first_name="Test"), @@ -89,7 +99,9 @@ class TestMessage: Message( message_id=42, date=datetime.datetime.now(), - photo=[PhotoSize(file_id="file id", width=42, height=42)], + photo=[ + PhotoSize(file_id="file id", file_unique_id="file id", width=42, height=42) + ], chat=Chat(id=42, type="private"), from_user=User(id=42, is_bot=False, first_name="Test"), ), @@ -99,7 +111,13 @@ class TestMessage: Message( message_id=42, date=datetime.datetime.now(), - sticker=Sticker(file_id="file id", width=42, height=42, is_animated=False), + sticker=Sticker( + file_id="file id", + file_unique_id="file id", + width=42, + height=42, + is_animated=False, + ), chat=Chat(id=42, type="private"), from_user=User(id=42, is_bot=False, first_name="Test"), ), @@ -109,7 +127,13 @@ class TestMessage: Message( message_id=42, date=datetime.datetime.now(), - video=Video(file_id="file id", width=42, height=42, duration=0), + video=Video( + file_id="file id", + file_unique_id="file id", + width=42, + height=42, + duration=0, + ), chat=Chat(id=42, type="private"), from_user=User(id=42, is_bot=False, first_name="Test"), ), @@ -119,7 +143,9 @@ class TestMessage: Message( message_id=42, date=datetime.datetime.now(), - video_note=VideoNote(file_id="file id", length=0, duration=0), + video_note=VideoNote( + file_id="file id", file_unique_id="file id", length=0, duration=0 + ), chat=Chat(id=42, type="private"), from_user=User(id=42, is_bot=False, first_name="Test"), ), @@ -129,7 +155,7 @@ class TestMessage: Message( message_id=42, date=datetime.datetime.now(), - voice=Voice(file_id="file id", duration=0), + voice=Voice(file_id="file id", file_unique_id="file id", duration=0), chat=Chat(id=42, type="private"), from_user=User(id=42, is_bot=False, first_name="Test"), ), @@ -282,7 +308,9 @@ class TestMessage: Message( message_id=42, date=datetime.datetime.now(), - new_chat_photo=[PhotoSize(file_id="file id", width=42, height=42)], + new_chat_photo=[ + PhotoSize(file_id="file id", file_unique_id="file id", width=42, height=42) + ], chat=Chat(id=42, type="private"), from_user=User(id=42, is_bot=False, first_name="Test"), ),