From fea1b7b0a385e4dd701ea644fd6e9052ec95c587 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sat, 11 Mar 2023 20:46:36 +0200 Subject: [PATCH] Reworked request builder (#1142) * Reworked request builder * Added more default values * Update tests * Fixed timestamp * Fixed Py3.8 support * Describe changes --- .butcher/methods/copyMessage/replace.yml | 4 +- .../methods/editMessageCaption/replace.yml | 2 +- .butcher/methods/editMessageText/replace.yml | 4 +- .butcher/methods/forwardMessage/replace.yml | 3 + .butcher/methods/sendAnimation/replace.yml | 4 +- .butcher/methods/sendAudio/replace.yml | 4 +- .butcher/methods/sendContact/replace.yml | 3 + .butcher/methods/sendDice/replace.yml | 3 + .butcher/methods/sendDocument/replace.yml | 4 +- .butcher/methods/sendGame/replace.yml | 3 + .butcher/methods/sendInvoice/replace.yml | 3 + .butcher/methods/sendLocation/replace.yml | 3 + .butcher/methods/sendMediaGroup/replace.yml | 3 + .butcher/methods/sendMessage/replace.yml | 6 +- .butcher/methods/sendPhoto/replace.yml | 4 +- .butcher/methods/sendPoll/replace.yml | 4 +- .butcher/methods/sendSticker/replace.yml | 3 + .butcher/methods/sendVenue/replace.yml | 3 + .butcher/methods/sendVideo/replace.yml | 4 +- .butcher/methods/sendVideoNote/replace.yml | 3 + .butcher/methods/sendVoice/replace.yml | 4 +- .../types/InlineQueryResultAudio/replace.yml | 2 +- .../InlineQueryResultCachedAudio/replace.yml | 2 +- .../replace.yml | 2 +- .../InlineQueryResultCachedGif/replace.yml | 2 +- .../replace.yml | 2 +- .../InlineQueryResultCachedPhoto/replace.yml | 2 +- .../InlineQueryResultCachedVideo/replace.yml | 2 +- .../InlineQueryResultCachedVoice/replace.yml | 2 +- .../InlineQueryResultDocument/replace.yml | 2 +- .../types/InlineQueryResultGif/replace.yml | 2 +- .../InlineQueryResultMpeg4Gif/replace.yml | 2 +- .../types/InlineQueryResultPhoto/replace.yml | 2 +- .../types/InlineQueryResultVideo/replace.yml | 2 +- .../types/InlineQueryResultVoice/replace.yml | 2 +- .../types/InputMediaAnimation/replace.yml | 2 +- .butcher/types/InputMediaAudio/replace.yml | 2 +- .butcher/types/InputMediaDocument/replace.yml | 2 +- .butcher/types/InputMediaPhoto/replace.yml | 2 +- .butcher/types/InputMediaVideo/replace.yml | 2 +- .../types/InputTextMessageContent/replace.yml | 4 +- CHANGES/1142.misc.rst | 2 + aiogram/client/bot.py | 75 ++++++----- aiogram/client/session/aiohttp.py | 24 ++-- aiogram/client/session/base.py | 85 +++++++++--- aiogram/dispatcher/dispatcher.py | 7 +- aiogram/methods/add_sticker_to_set.py | 18 +-- aiogram/methods/answer_callback_query.py | 13 +- aiogram/methods/answer_inline_query.py | 20 +-- aiogram/methods/answer_pre_checkout_query.py | 13 +- aiogram/methods/answer_shipping_query.py | 13 +- aiogram/methods/answer_web_app_query.py | 17 +-- aiogram/methods/approve_chat_join_request.py | 13 +- aiogram/methods/ban_chat_member.py | 13 +- aiogram/methods/ban_chat_sender_chat.py | 13 +- aiogram/methods/base.py | 120 ++--------------- aiogram/methods/close.py | 13 +- aiogram/methods/close_forum_topic.py | 13 +- aiogram/methods/close_general_forum_topic.py | 13 +- aiogram/methods/copy_message.py | 24 +--- aiogram/methods/create_chat_invite_link.py | 13 +- aiogram/methods/create_forum_topic.py | 13 +- aiogram/methods/create_invoice_link.py | 13 +- aiogram/methods/create_new_sticker_set.py | 18 +-- aiogram/methods/decline_chat_join_request.py | 13 +- aiogram/methods/delete_chat_photo.py | 13 +- aiogram/methods/delete_chat_sticker_set.py | 13 +- aiogram/methods/delete_forum_topic.py | 13 +- aiogram/methods/delete_message.py | 13 +- aiogram/methods/delete_my_commands.py | 13 +- aiogram/methods/delete_sticker_from_set.py | 13 +- aiogram/methods/delete_sticker_set.py | 13 +- aiogram/methods/delete_webhook.py | 13 +- aiogram/methods/edit_chat_invite_link.py | 13 +- aiogram/methods/edit_forum_topic.py | 13 +- aiogram/methods/edit_general_forum_topic.py | 13 +- aiogram/methods/edit_message_caption.py | 21 +-- aiogram/methods/edit_message_live_location.py | 13 +- aiogram/methods/edit_message_media.py | 18 +-- aiogram/methods/edit_message_reply_markup.py | 13 +- aiogram/methods/edit_message_text.py | 24 +--- aiogram/methods/export_chat_invite_link.py | 13 +- aiogram/methods/forward_message.py | 16 +-- aiogram/methods/get_chat.py | 13 +- aiogram/methods/get_chat_administrators.py | 13 +- aiogram/methods/get_chat_member.py | 13 +- aiogram/methods/get_chat_member_count.py | 13 +- aiogram/methods/get_chat_menu_button.py | 13 +- aiogram/methods/get_custom_emoji_stickers.py | 13 +- aiogram/methods/get_file.py | 13 +- .../methods/get_forum_topic_icon_stickers.py | 13 +- aiogram/methods/get_game_high_scores.py | 13 +- aiogram/methods/get_me.py | 13 +- aiogram/methods/get_my_commands.py | 13 +- .../get_my_default_administrator_rights.py | 13 +- aiogram/methods/get_my_description.py | 13 +- aiogram/methods/get_my_short_description.py | 13 +- aiogram/methods/get_sticker_set.py | 13 +- aiogram/methods/get_updates.py | 13 +- aiogram/methods/get_user_profile_photos.py | 13 +- aiogram/methods/get_webhook_info.py | 13 +- aiogram/methods/hide_general_forum_topic.py | 13 +- aiogram/methods/leave_chat.py | 13 +- aiogram/methods/log_out.py | 13 +- aiogram/methods/pin_chat_message.py | 13 +- aiogram/methods/promote_chat_member.py | 13 +- aiogram/methods/reopen_forum_topic.py | 13 +- aiogram/methods/reopen_general_forum_topic.py | 13 +- aiogram/methods/restrict_chat_member.py | 13 +- aiogram/methods/revoke_chat_invite_link.py | 13 +- aiogram/methods/send_animation.py | 28 +--- aiogram/methods/send_audio.py | 28 +--- aiogram/methods/send_chat_action.py | 13 +- aiogram/methods/send_contact.py | 16 +-- aiogram/methods/send_dice.py | 16 +-- aiogram/methods/send_document.py | 28 +--- aiogram/methods/send_game.py | 16 +-- aiogram/methods/send_invoice.py | 16 +-- aiogram/methods/send_location.py | 16 +-- aiogram/methods/send_media_group.py | 21 +-- aiogram/methods/send_message.py | 26 ++-- aiogram/methods/send_photo.py | 27 +--- aiogram/methods/send_poll.py | 27 +--- aiogram/methods/send_sticker.py | 19 +-- aiogram/methods/send_venue.py | 16 +-- aiogram/methods/send_video.py | 28 +--- aiogram/methods/send_video_note.py | 20 +-- aiogram/methods/send_voice.py | 27 +--- .../set_chat_administrator_custom_title.py | 13 +- aiogram/methods/set_chat_description.py | 13 +- aiogram/methods/set_chat_menu_button.py | 13 +- aiogram/methods/set_chat_permissions.py | 13 +- aiogram/methods/set_chat_photo.py | 16 +-- aiogram/methods/set_chat_sticker_set.py | 13 +- aiogram/methods/set_chat_title.py | 13 +- .../set_custom_emoji_sticker_set_thumbnail.py | 13 +- aiogram/methods/set_game_score.py | 13 +- aiogram/methods/set_my_commands.py | 13 +- .../set_my_default_administrator_rights.py | 13 +- aiogram/methods/set_my_description.py | 13 +- aiogram/methods/set_my_short_description.py | 13 +- aiogram/methods/set_passport_data_errors.py | 13 +- aiogram/methods/set_sticker_emoji_list.py | 13 +- aiogram/methods/set_sticker_keywords.py | 13 +- aiogram/methods/set_sticker_mask_position.py | 13 +- .../methods/set_sticker_position_in_set.py | 13 +- aiogram/methods/set_sticker_set_thumbnail.py | 16 +-- aiogram/methods/set_sticker_set_title.py | 13 +- aiogram/methods/set_webhook.py | 16 +-- aiogram/methods/stop_message_live_location.py | 13 +- aiogram/methods/stop_poll.py | 13 +- aiogram/methods/unban_chat_member.py | 13 +- aiogram/methods/unban_chat_sender_chat.py | 13 +- aiogram/methods/unhide_general_forum_topic.py | 13 +- aiogram/methods/unpin_all_chat_messages.py | 13 +- .../methods/unpin_all_forum_topic_messages.py | 13 +- aiogram/methods/unpin_chat_message.py | 13 +- aiogram/methods/upload_sticker_file.py | 16 +-- aiogram/types/__init__.py | 4 +- aiogram/types/base.py | 8 +- aiogram/types/inline_query_result_audio.py | 4 +- .../types/inline_query_result_cached_audio.py | 4 +- .../inline_query_result_cached_document.py | 4 +- .../types/inline_query_result_cached_gif.py | 4 +- .../inline_query_result_cached_mpeg4_gif.py | 4 +- .../types/inline_query_result_cached_photo.py | 4 +- .../types/inline_query_result_cached_video.py | 4 +- .../types/inline_query_result_cached_voice.py | 4 +- aiogram/types/inline_query_result_document.py | 4 +- aiogram/types/inline_query_result_gif.py | 4 +- .../types/inline_query_result_mpeg4_gif.py | 4 +- aiogram/types/inline_query_result_photo.py | 4 +- aiogram/types/inline_query_result_video.py | 4 +- aiogram/types/inline_query_result_voice.py | 4 +- aiogram/types/input_media_animation.py | 4 +- aiogram/types/input_media_audio.py | 4 +- aiogram/types/input_media_document.py | 4 +- aiogram/types/input_media_photo.py | 4 +- aiogram/types/input_media_video.py | 4 +- aiogram/types/input_text_message_content.py | 6 +- aiogram/types/message.py | 123 +++++++++--------- aiogram/webhook/aiohttp_server.py | 32 +++-- pyproject.toml | 4 +- tests/mocked_bot.py | 17 ++- .../test_session/test_aiohttp_session.py | 76 ++++++----- .../test_session/test_base_session.py | 107 ++++++++------- .../test_methods/test_add_sticker_to_set.py | 17 +-- .../test_answer_callback_query.py | 11 +- .../test_methods/test_answer_inline_query.py | 46 +------ .../test_answer_pre_checkout_query.py | 11 +- .../test_answer_shipping_query.py | 11 +- .../test_methods/test_answer_web_app_query.py | 16 +-- .../test_approve_chat_join_request.py | 14 +- .../test_methods/test_ban_chat_member.py | 11 +- .../test_methods/test_ban_chat_sender_chat.py | 16 +-- tests/test_api/test_methods/test_base.py | 64 +++------ tests/test_api/test_methods/test_close.py | 13 +- .../test_methods/test_close_forum_topic.py | 16 +-- .../test_close_general_forum_topic.py | 11 +- .../test_methods/test_copy_message.py | 17 +-- .../test_create_chat_invite_link.py | 25 +--- .../test_methods/test_create_forum_topic.py | 20 +-- .../test_methods/test_create_invoice_link.py | 20 +-- .../test_create_new_sticker_set.py | 20 +-- .../test_decline_chat_join_request.py | 14 +- .../test_methods/test_delete_chat_photo.py | 11 +- .../test_delete_chat_sticker_set.py | 11 +- .../test_methods/test_delete_forum_topic.py | 16 +-- .../test_methods/test_delete_message.py | 11 +- .../test_methods/test_delete_my_commands.py | 11 +- .../test_delete_sticker_from_set.py | 11 +- .../test_methods/test_delete_sticker_set.py | 11 +- .../test_methods/test_delete_webhook.py | 11 +- .../test_edit_chat_invite_link.py | 23 +--- .../test_methods/test_edit_forum_topic.py | 19 +-- .../test_edit_general_forum_topic.py | 11 +- .../test_methods/test_edit_message_caption.py | 20 +-- .../test_edit_message_live_location.py | 13 +- .../test_methods/test_edit_message_media.py | 13 +- .../test_edit_message_reply_markup.py | 19 +-- .../test_methods/test_edit_message_text.py | 13 +- .../test_export_chat_invite_link.py | 13 +- .../test_methods/test_forward_message.py | 22 +--- tests/test_api/test_methods/test_get_chat.py | 13 +- .../test_get_chat_administrators.py | 19 +-- .../test_methods/test_get_chat_member.py | 20 +-- .../test_get_chat_member_count.py | 11 +- .../test_methods/test_get_chat_menu_button.py | 13 +- .../test_get_custom_emoji_stickers.py | 30 +---- tests/test_api/test_methods/test_get_file.py | 13 +- .../test_get_forum_topic_icon_stickers.py | 13 +- .../test_methods/test_get_game_high_scores.py | 19 +-- tests/test_api/test_methods/test_get_me.py | 15 +-- .../test_methods/test_get_my_commands.py | 11 +- ...est_get_my_default_administrator_rights.py | 26 +--- .../test_methods/test_get_my_description.py | 13 +- .../test_get_my_short_description.py | 13 +- .../test_methods/test_get_sticker_set.py | 32 +---- .../test_api/test_methods/test_get_updates.py | 11 +- .../test_get_user_profile_photos.py | 20 +-- .../test_methods/test_get_webhook_info.py | 17 +-- .../test_hide_general_forum_topic.py | 11 +- .../test_api/test_methods/test_leave_chat.py | 11 +- tests/test_api/test_methods/test_log_out.py | 13 +- .../test_methods/test_pin_chat_message.py | 11 +- .../test_methods/test_promote_chat_member.py | 11 +- .../test_methods/test_reopen_forum_topic.py | 16 +-- .../test_reopen_general_forum_topic.py | 11 +- .../test_methods/test_restrict_chat_member.py | 13 +- .../test_revoke_chat_invite_link.py | 24 +--- .../test_methods/test_send_animation.py | 22 +--- .../test_api/test_methods/test_send_audio.py | 20 +-- .../test_methods/test_send_chat_action.py | 20 +-- .../test_methods/test_send_contact.py | 20 +-- tests/test_api/test_methods/test_send_dice.py | 11 +- .../test_methods/test_send_document.py | 20 +-- tests/test_api/test_methods/test_send_game.py | 26 +--- .../test_methods/test_send_invoice.py | 35 +---- .../test_methods/test_send_location.py | 20 +-- .../test_methods/test_send_media_group.py | 44 +------ .../test_methods/test_send_message.py | 20 +-- .../test_api/test_methods/test_send_photo.py | 22 +--- tests/test_api/test_methods/test_send_poll.py | 35 +---- .../test_methods/test_send_sticker.py | 28 +--- .../test_api/test_methods/test_send_venue.py | 32 +---- .../test_api/test_methods/test_send_video.py | 22 +--- .../test_methods/test_send_video_note.py | 26 +--- .../test_api/test_methods/test_send_voice.py | 20 +-- ...est_set_chat_administrator_custom_title.py | 13 +- .../test_methods/test_set_chat_description.py | 11 +- .../test_methods/test_set_chat_menu_button.py | 13 +- .../test_methods/test_set_chat_permissions.py | 13 +- .../test_methods/test_set_chat_photo.py | 13 +- .../test_methods/test_set_chat_sticker_set.py | 11 +- .../test_methods/test_set_chat_title.py | 11 +- ..._set_custom_emoji_sticker_set_thumbnail.py | 15 +-- .../test_methods/test_set_game_score.py | 13 +- .../test_methods/test_set_my_commands.py | 14 +- ...est_set_my_default_administrator_rights.py | 13 +- .../test_methods/test_set_my_description.py | 11 +- .../test_set_my_short_description.py | 11 +- .../test_set_passport_data_errors.py | 11 +- .../test_set_sticker_emoji_list.py | 11 +- .../test_methods/test_set_sticker_keywords.py | 11 +- .../test_set_sticker_mask_position.py | 11 +- .../test_set_sticker_position_in_set.py | 11 +- .../test_set_sticker_set_thumbnail.py | 13 +- .../test_set_sticker_set_title.py | 11 +- .../test_api/test_methods/test_set_webhook.py | 11 +- .../test_stop_message_live_location.py | 13 +- tests/test_api/test_methods/test_stop_poll.py | 25 +--- .../test_methods/test_unban_chat_member.py | 11 +- .../test_unban_chat_sender_chat.py | 16 +-- .../test_unhide_general_forum_topic.py | 11 +- .../test_unpin_all_chat_messages.py | 15 +-- .../test_unpin_all_forum_topic_messages.py | 16 +-- .../test_methods/test_unpin_chat_message.py | 11 +- .../test_methods/test_upload_sticker_file.py | 17 +-- tests/test_dispatcher/test_dispatcher.py | 6 +- tests/test_webhook/test_aiohtt_server.py | 3 +- 300 files changed, 1003 insertions(+), 3448 deletions(-) create mode 100644 .butcher/methods/forwardMessage/replace.yml create mode 100644 .butcher/methods/sendContact/replace.yml create mode 100644 .butcher/methods/sendDice/replace.yml create mode 100644 .butcher/methods/sendGame/replace.yml create mode 100644 .butcher/methods/sendInvoice/replace.yml create mode 100644 .butcher/methods/sendLocation/replace.yml create mode 100644 .butcher/methods/sendMediaGroup/replace.yml create mode 100644 .butcher/methods/sendSticker/replace.yml create mode 100644 .butcher/methods/sendVenue/replace.yml create mode 100644 .butcher/methods/sendVideoNote/replace.yml create mode 100644 CHANGES/1142.misc.rst diff --git a/.butcher/methods/copyMessage/replace.yml b/.butcher/methods/copyMessage/replace.yml index 1feb5360..cc4fe9b2 100644 --- a/.butcher/methods/copyMessage/replace.yml +++ b/.butcher/methods/copyMessage/replace.yml @@ -1,3 +1,5 @@ annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/editMessageCaption/replace.yml b/.butcher/methods/editMessageCaption/replace.yml index 1feb5360..e87fb9b3 100644 --- a/.butcher/methods/editMessageCaption/replace.yml +++ b/.butcher/methods/editMessageCaption/replace.yml @@ -1,3 +1,3 @@ annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/methods/editMessageText/replace.yml b/.butcher/methods/editMessageText/replace.yml index 1feb5360..ebc1d7e9 100644 --- a/.butcher/methods/editMessageText/replace.yml +++ b/.butcher/methods/editMessageText/replace.yml @@ -1,3 +1,5 @@ annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE + disable_web_page_preview: + value: UNSET_DISABLE_WEB_PAGE_PREVIEW diff --git a/.butcher/methods/forwardMessage/replace.yml b/.butcher/methods/forwardMessage/replace.yml new file mode 100644 index 00000000..39cba814 --- /dev/null +++ b/.butcher/methods/forwardMessage/replace.yml @@ -0,0 +1,3 @@ +annotations: + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendAnimation/replace.yml b/.butcher/methods/sendAnimation/replace.yml index 1feb5360..cc4fe9b2 100644 --- a/.butcher/methods/sendAnimation/replace.yml +++ b/.butcher/methods/sendAnimation/replace.yml @@ -1,3 +1,5 @@ annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendAudio/replace.yml b/.butcher/methods/sendAudio/replace.yml index 1feb5360..cc4fe9b2 100644 --- a/.butcher/methods/sendAudio/replace.yml +++ b/.butcher/methods/sendAudio/replace.yml @@ -1,3 +1,5 @@ annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendContact/replace.yml b/.butcher/methods/sendContact/replace.yml new file mode 100644 index 00000000..39cba814 --- /dev/null +++ b/.butcher/methods/sendContact/replace.yml @@ -0,0 +1,3 @@ +annotations: + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendDice/replace.yml b/.butcher/methods/sendDice/replace.yml new file mode 100644 index 00000000..39cba814 --- /dev/null +++ b/.butcher/methods/sendDice/replace.yml @@ -0,0 +1,3 @@ +annotations: + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendDocument/replace.yml b/.butcher/methods/sendDocument/replace.yml index 1feb5360..cc4fe9b2 100644 --- a/.butcher/methods/sendDocument/replace.yml +++ b/.butcher/methods/sendDocument/replace.yml @@ -1,3 +1,5 @@ annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendGame/replace.yml b/.butcher/methods/sendGame/replace.yml new file mode 100644 index 00000000..39cba814 --- /dev/null +++ b/.butcher/methods/sendGame/replace.yml @@ -0,0 +1,3 @@ +annotations: + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendInvoice/replace.yml b/.butcher/methods/sendInvoice/replace.yml new file mode 100644 index 00000000..39cba814 --- /dev/null +++ b/.butcher/methods/sendInvoice/replace.yml @@ -0,0 +1,3 @@ +annotations: + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendLocation/replace.yml b/.butcher/methods/sendLocation/replace.yml new file mode 100644 index 00000000..39cba814 --- /dev/null +++ b/.butcher/methods/sendLocation/replace.yml @@ -0,0 +1,3 @@ +annotations: + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendMediaGroup/replace.yml b/.butcher/methods/sendMediaGroup/replace.yml new file mode 100644 index 00000000..39cba814 --- /dev/null +++ b/.butcher/methods/sendMediaGroup/replace.yml @@ -0,0 +1,3 @@ +annotations: + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendMessage/replace.yml b/.butcher/methods/sendMessage/replace.yml index 1feb5360..68d7bef9 100644 --- a/.butcher/methods/sendMessage/replace.yml +++ b/.butcher/methods/sendMessage/replace.yml @@ -1,3 +1,7 @@ annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE + disable_web_page_preview: + value: UNSET_DISABLE_WEB_PAGE_PREVIEW + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendPhoto/replace.yml b/.butcher/methods/sendPhoto/replace.yml index 1feb5360..cc4fe9b2 100644 --- a/.butcher/methods/sendPhoto/replace.yml +++ b/.butcher/methods/sendPhoto/replace.yml @@ -1,3 +1,5 @@ annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendPoll/replace.yml b/.butcher/methods/sendPoll/replace.yml index 92d645dd..4b39b8ab 100644 --- a/.butcher/methods/sendPoll/replace.yml +++ b/.butcher/methods/sendPoll/replace.yml @@ -1,6 +1,8 @@ annotations: explanation_parse_mode: - value: UNSET + value: UNSET_PARSE_MODE + protect_content: + value: UNSET_PROTECT_CONTENT close_date: parsed_type: type: union diff --git a/.butcher/methods/sendSticker/replace.yml b/.butcher/methods/sendSticker/replace.yml new file mode 100644 index 00000000..39cba814 --- /dev/null +++ b/.butcher/methods/sendSticker/replace.yml @@ -0,0 +1,3 @@ +annotations: + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendVenue/replace.yml b/.butcher/methods/sendVenue/replace.yml new file mode 100644 index 00000000..39cba814 --- /dev/null +++ b/.butcher/methods/sendVenue/replace.yml @@ -0,0 +1,3 @@ +annotations: + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendVideo/replace.yml b/.butcher/methods/sendVideo/replace.yml index 1feb5360..cc4fe9b2 100644 --- a/.butcher/methods/sendVideo/replace.yml +++ b/.butcher/methods/sendVideo/replace.yml @@ -1,3 +1,5 @@ annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendVideoNote/replace.yml b/.butcher/methods/sendVideoNote/replace.yml new file mode 100644 index 00000000..39cba814 --- /dev/null +++ b/.butcher/methods/sendVideoNote/replace.yml @@ -0,0 +1,3 @@ +annotations: + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/methods/sendVoice/replace.yml b/.butcher/methods/sendVoice/replace.yml index 1feb5360..cc4fe9b2 100644 --- a/.butcher/methods/sendVoice/replace.yml +++ b/.butcher/methods/sendVoice/replace.yml @@ -1,3 +1,5 @@ annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE + protect_content: + value: UNSET_PROTECT_CONTENT diff --git a/.butcher/types/InlineQueryResultAudio/replace.yml b/.butcher/types/InlineQueryResultAudio/replace.yml index b877a94d..cd89306d 100644 --- a/.butcher/types/InlineQueryResultAudio/replace.yml +++ b/.butcher/types/InlineQueryResultAudio/replace.yml @@ -3,4 +3,4 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InlineQueryResultCachedAudio/replace.yml b/.butcher/types/InlineQueryResultCachedAudio/replace.yml index b877a94d..cd89306d 100644 --- a/.butcher/types/InlineQueryResultCachedAudio/replace.yml +++ b/.butcher/types/InlineQueryResultCachedAudio/replace.yml @@ -3,4 +3,4 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InlineQueryResultCachedDocument/replace.yml b/.butcher/types/InlineQueryResultCachedDocument/replace.yml index b877a94d..cd89306d 100644 --- a/.butcher/types/InlineQueryResultCachedDocument/replace.yml +++ b/.butcher/types/InlineQueryResultCachedDocument/replace.yml @@ -3,4 +3,4 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InlineQueryResultCachedGif/replace.yml b/.butcher/types/InlineQueryResultCachedGif/replace.yml index b877a94d..cd89306d 100644 --- a/.butcher/types/InlineQueryResultCachedGif/replace.yml +++ b/.butcher/types/InlineQueryResultCachedGif/replace.yml @@ -3,4 +3,4 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InlineQueryResultCachedMpeg4Gif/replace.yml b/.butcher/types/InlineQueryResultCachedMpeg4Gif/replace.yml index b877a94d..cd89306d 100644 --- a/.butcher/types/InlineQueryResultCachedMpeg4Gif/replace.yml +++ b/.butcher/types/InlineQueryResultCachedMpeg4Gif/replace.yml @@ -3,4 +3,4 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InlineQueryResultCachedPhoto/replace.yml b/.butcher/types/InlineQueryResultCachedPhoto/replace.yml index b877a94d..cd89306d 100644 --- a/.butcher/types/InlineQueryResultCachedPhoto/replace.yml +++ b/.butcher/types/InlineQueryResultCachedPhoto/replace.yml @@ -3,4 +3,4 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InlineQueryResultCachedVideo/replace.yml b/.butcher/types/InlineQueryResultCachedVideo/replace.yml index b877a94d..cd89306d 100644 --- a/.butcher/types/InlineQueryResultCachedVideo/replace.yml +++ b/.butcher/types/InlineQueryResultCachedVideo/replace.yml @@ -3,4 +3,4 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InlineQueryResultCachedVoice/replace.yml b/.butcher/types/InlineQueryResultCachedVoice/replace.yml index b877a94d..cd89306d 100644 --- a/.butcher/types/InlineQueryResultCachedVoice/replace.yml +++ b/.butcher/types/InlineQueryResultCachedVoice/replace.yml @@ -3,4 +3,4 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InlineQueryResultDocument/replace.yml b/.butcher/types/InlineQueryResultDocument/replace.yml index b877a94d..cd89306d 100644 --- a/.butcher/types/InlineQueryResultDocument/replace.yml +++ b/.butcher/types/InlineQueryResultDocument/replace.yml @@ -3,4 +3,4 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InlineQueryResultGif/replace.yml b/.butcher/types/InlineQueryResultGif/replace.yml index b877a94d..cd89306d 100644 --- a/.butcher/types/InlineQueryResultGif/replace.yml +++ b/.butcher/types/InlineQueryResultGif/replace.yml @@ -3,4 +3,4 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InlineQueryResultMpeg4Gif/replace.yml b/.butcher/types/InlineQueryResultMpeg4Gif/replace.yml index b877a94d..cd89306d 100644 --- a/.butcher/types/InlineQueryResultMpeg4Gif/replace.yml +++ b/.butcher/types/InlineQueryResultMpeg4Gif/replace.yml @@ -3,4 +3,4 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InlineQueryResultPhoto/replace.yml b/.butcher/types/InlineQueryResultPhoto/replace.yml index b877a94d..cd89306d 100644 --- a/.butcher/types/InlineQueryResultPhoto/replace.yml +++ b/.butcher/types/InlineQueryResultPhoto/replace.yml @@ -3,4 +3,4 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InlineQueryResultVideo/replace.yml b/.butcher/types/InlineQueryResultVideo/replace.yml index b877a94d..cd89306d 100644 --- a/.butcher/types/InlineQueryResultVideo/replace.yml +++ b/.butcher/types/InlineQueryResultVideo/replace.yml @@ -3,4 +3,4 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InlineQueryResultVoice/replace.yml b/.butcher/types/InlineQueryResultVoice/replace.yml index cd07671d..6c32c60f 100644 --- a/.butcher/types/InlineQueryResultVoice/replace.yml +++ b/.butcher/types/InlineQueryResultVoice/replace.yml @@ -2,4 +2,4 @@ bases: - InlineQueryResult annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InputMediaAnimation/replace.yml b/.butcher/types/InputMediaAnimation/replace.yml index d2375f89..a2756429 100644 --- a/.butcher/types/InputMediaAnimation/replace.yml +++ b/.butcher/types/InputMediaAnimation/replace.yml @@ -12,4 +12,4 @@ annotations: category: types name: InputFile parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InputMediaAudio/replace.yml b/.butcher/types/InputMediaAudio/replace.yml index d2375f89..a2756429 100644 --- a/.butcher/types/InputMediaAudio/replace.yml +++ b/.butcher/types/InputMediaAudio/replace.yml @@ -12,4 +12,4 @@ annotations: category: types name: InputFile parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InputMediaDocument/replace.yml b/.butcher/types/InputMediaDocument/replace.yml index d2375f89..a2756429 100644 --- a/.butcher/types/InputMediaDocument/replace.yml +++ b/.butcher/types/InputMediaDocument/replace.yml @@ -12,4 +12,4 @@ annotations: category: types name: InputFile parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InputMediaPhoto/replace.yml b/.butcher/types/InputMediaPhoto/replace.yml index d2375f89..a2756429 100644 --- a/.butcher/types/InputMediaPhoto/replace.yml +++ b/.butcher/types/InputMediaPhoto/replace.yml @@ -12,4 +12,4 @@ annotations: category: types name: InputFile parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InputMediaVideo/replace.yml b/.butcher/types/InputMediaVideo/replace.yml index d2375f89..a2756429 100644 --- a/.butcher/types/InputMediaVideo/replace.yml +++ b/.butcher/types/InputMediaVideo/replace.yml @@ -12,4 +12,4 @@ annotations: category: types name: InputFile parse_mode: - value: UNSET + value: UNSET_PARSE_MODE diff --git a/.butcher/types/InputTextMessageContent/replace.yml b/.butcher/types/InputTextMessageContent/replace.yml index c79933d0..63741e83 100644 --- a/.butcher/types/InputTextMessageContent/replace.yml +++ b/.butcher/types/InputTextMessageContent/replace.yml @@ -3,4 +3,6 @@ bases: annotations: parse_mode: - value: UNSET + value: UNSET_PARSE_MODE + disable_web_page_preview: + value: UNSET_DISABLE_WEB_PAGE_PREVIEW diff --git a/CHANGES/1142.misc.rst b/CHANGES/1142.misc.rst new file mode 100644 index 00000000..c17fb588 --- /dev/null +++ b/CHANGES/1142.misc.rst @@ -0,0 +1,2 @@ +Added global defaults `disable_web_page_preview` and `protect_content` in addition to `parse_mode` to the Bot instance, +reworked internal request builder mechanism. diff --git a/aiogram/client/bot.py b/aiogram/client/bot.py index 91dd91fa..6f874a88 100644 --- a/aiogram/client/bot.py +++ b/aiogram/client/bot.py @@ -136,7 +136,7 @@ from ..methods import ( UploadStickerFile, ) from ..types import ( - UNSET, + UNSET_PARSE_MODE, BotCommand, BotCommandScope, BotDescription, @@ -186,6 +186,7 @@ from ..types import ( UserProfilePhotos, WebhookInfo, ) +from ..types.base import UNSET_DISABLE_WEB_PAGE_PREVIEW, UNSET_PROTECT_CONTENT from .session.aiohttp import AiohttpSession from .session.base import BaseSession @@ -198,6 +199,8 @@ class Bot(ContextInstanceMixin["Bot"]): token: str, session: Optional[BaseSession] = None, parse_mode: Optional[str] = None, + disable_web_page_preview: Optional[bool] = None, + protect_content: Optional[bool] = None, ) -> None: """ Bot class @@ -207,6 +210,10 @@ class Bot(ContextInstanceMixin["Bot"]): If not specified it will be automatically created. :param parse_mode: Default parse mode. If specified it will be propagated into the API methods at runtime. + :param disable_web_page_preview: Default disable_web_page_preview mode. + If specified it will be propagated into the API methods at runtime. + :param protect_content: Default protect_content mode. + If specified it will be propagated into the API methods at runtime. :raise TokenValidationError: When token has invalid format this exception will be raised """ @@ -217,6 +224,8 @@ class Bot(ContextInstanceMixin["Bot"]): self.session = session self.parse_mode = parse_mode + self.disable_web_page_preview = disable_web_page_preview + self.protect_content = protect_content self.__token = token self._me: Optional[User] = None @@ -704,10 +713,10 @@ class Bot(ContextInstanceMixin["Bot"]): message_id: int, message_thread_id: Optional[int] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -1188,7 +1197,7 @@ class Bot(ContextInstanceMixin["Bot"]): message_id: Optional[int] = None, inline_message_id: Optional[str] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, request_timeout: Optional[int] = None, @@ -1331,9 +1340,9 @@ class Bot(ContextInstanceMixin["Bot"]): chat_id: Optional[Union[int, str]] = None, message_id: Optional[int] = None, inline_message_id: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, entities: Optional[List[MessageEntity]] = None, - disable_web_page_preview: Optional[bool] = None, + disable_web_page_preview: Optional[bool] = UNSET_DISABLE_WEB_PAGE_PREVIEW, reply_markup: Optional[InlineKeyboardMarkup] = None, request_timeout: Optional[int] = None, ) -> Union[Message, bool]: @@ -1395,7 +1404,7 @@ class Bot(ContextInstanceMixin["Bot"]): message_id: int, message_thread_id: Optional[int] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, request_timeout: Optional[int] = None, ) -> Message: """ @@ -1995,11 +2004,11 @@ class Bot(ContextInstanceMixin["Bot"]): height: Optional[int] = None, thumbnail: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, has_spoiler: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2058,14 +2067,14 @@ class Bot(ContextInstanceMixin["Bot"]): audio: Union[InputFile, str], message_thread_id: Optional[int] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, duration: Optional[int] = None, performer: Optional[str] = None, title: Optional[str] = None, thumbnail: Optional[Union[InputFile, str]] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2156,7 +2165,7 @@ class Bot(ContextInstanceMixin["Bot"]): last_name: Optional[str] = None, vcard: Optional[str] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2205,7 +2214,7 @@ class Bot(ContextInstanceMixin["Bot"]): message_thread_id: Optional[int] = None, emoji: Optional[str] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2249,11 +2258,11 @@ class Bot(ContextInstanceMixin["Bot"]): message_thread_id: Optional[int] = None, thumbnail: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, disable_content_type_detection: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2306,7 +2315,7 @@ class Bot(ContextInstanceMixin["Bot"]): game_short_name: str, message_thread_id: Optional[int] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, @@ -2367,7 +2376,7 @@ class Bot(ContextInstanceMixin["Bot"]): send_email_to_provider: Optional[bool] = None, is_flexible: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, @@ -2453,7 +2462,7 @@ class Bot(ContextInstanceMixin["Bot"]): heading: Optional[int] = None, proximity_alert_radius: Optional[int] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2506,7 +2515,7 @@ class Bot(ContextInstanceMixin["Bot"]): media: List[Union[InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo]], message_thread_id: Optional[int] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, request_timeout: Optional[int] = None, @@ -2543,11 +2552,11 @@ class Bot(ContextInstanceMixin["Bot"]): chat_id: Union[int, str], text: str, message_thread_id: Optional[int] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, entities: Optional[List[MessageEntity]] = None, - disable_web_page_preview: Optional[bool] = None, + disable_web_page_preview: Optional[bool] = UNSET_DISABLE_WEB_PAGE_PREVIEW, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2596,11 +2605,11 @@ class Bot(ContextInstanceMixin["Bot"]): photo: Union[InputFile, str], message_thread_id: Optional[int] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, has_spoiler: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2656,13 +2665,13 @@ class Bot(ContextInstanceMixin["Bot"]): allows_multiple_answers: Optional[bool] = None, correct_option_id: Optional[int] = None, explanation: Optional[str] = None, - explanation_parse_mode: Optional[str] = UNSET, + explanation_parse_mode: Optional[str] = UNSET_PARSE_MODE, explanation_entities: Optional[List[MessageEntity]] = None, open_period: Optional[int] = None, close_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None, is_closed: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2728,7 +2737,7 @@ class Bot(ContextInstanceMixin["Bot"]): message_thread_id: Optional[int] = None, emoji: Optional[str] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2780,7 +2789,7 @@ class Bot(ContextInstanceMixin["Bot"]): google_place_id: Optional[str] = None, google_place_type: Optional[str] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2841,12 +2850,12 @@ class Bot(ContextInstanceMixin["Bot"]): height: Optional[int] = None, thumbnail: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, has_spoiler: Optional[bool] = None, supports_streaming: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2910,7 +2919,7 @@ class Bot(ContextInstanceMixin["Bot"]): length: Optional[int] = None, thumbnail: Optional[Union[InputFile, str]] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2959,11 +2968,11 @@ class Bot(ContextInstanceMixin["Bot"]): voice: Union[InputFile, str], message_thread_id: Optional[int] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, duration: Optional[int] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ diff --git a/aiogram/client/session/aiohttp.py b/aiogram/client/session/aiohttp.py index 3f35a0e0..279f61f9 100644 --- a/aiogram/client/session/aiohttp.py +++ b/aiogram/client/session/aiohttp.py @@ -19,12 +19,12 @@ from typing import ( import certifi from aiohttp import BasicAuth, ClientError, ClientSession, FormData, TCPConnector -from aiogram.methods import Request, TelegramMethod +from aiogram.methods import TelegramMethod from ...exceptions import TelegramNetworkError from ...methods.base import TelegramType from ...types import InputFile -from .base import UNSET, BaseSession +from .base import BaseSession if TYPE_CHECKING: from ..bot import Bot @@ -130,15 +130,16 @@ class AiohttpSession(BaseSession): if self._session is not None and not self._session.closed: await self._session.close() - def build_form_data(self, request: Request) -> FormData: + def build_form_data(self, bot: Bot, method: TelegramMethod[TelegramType]) -> FormData: form = FormData(quote_fields=False) - for key, value in request.data.items(): - if value is None or value is UNSET: + files: Dict[str, InputFile] = {} + for key, value in method.dict().items(): + value = self.prepare_value(value, bot=bot, files=files) + if not value: continue - form.add_field(key, self.prepare_value(value)) - if request.files: - for key, value in request.files.items(): - form.add_field(key, value, filename=value.filename or key) + form.add_field(key, value) + for key, value in files.items(): + form.add_field(key, value, filename=value.filename or key) return form async def make_request( @@ -146,9 +147,8 @@ class AiohttpSession(BaseSession): ) -> TelegramType: session = await self.create_session() - request = method.build_request(bot) - url = self.api.api_url(token=bot.token, method=request.method) - form = self.build_form_data(request) + url = self.api.api_url(token=bot.token, method=method.__api_method__) + form = self.build_form_data(bot=bot, method=method) try: async with session.post( diff --git a/aiogram/client/session/base.py b/aiogram/client/session/base.py index 971d9a32..a66eb7cc 100644 --- a/aiogram/client/session/base.py +++ b/aiogram/client/session/base.py @@ -3,6 +3,7 @@ from __future__ import annotations import abc import datetime import json +import secrets from enum import Enum from http import HTTPStatus from types import TracebackType @@ -11,10 +12,10 @@ from typing import ( Any, AsyncGenerator, Callable, + Dict, Final, Optional, Type, - Union, cast, ) @@ -37,7 +38,8 @@ from aiogram.exceptions import ( from ...methods import Response, TelegramMethod from ...methods.base import TelegramType -from ...types import UNSET +from ...types import UNSET_PARSE_MODE, InputFile +from ...types.base import UNSET_DISABLE_WEB_PAGE_PREVIEW, UNSET_PROTECT_CONTENT from ..telegram import PRODUCTION, TelegramAPIServer from .middlewares.manager import RequestMiddlewareManager @@ -138,7 +140,10 @@ class BaseSession(abc.ABC): @abc.abstractmethod async def make_request( - self, bot: Bot, method: TelegramMethod[TelegramType], timeout: Optional[int] = UNSET + self, + bot: Bot, + method: TelegramMethod[TelegramType], + timeout: Optional[int] = None, ) -> TelegramType: # pragma: no cover """ Make request to Telegram Bot API @@ -160,35 +165,81 @@ class BaseSession(abc.ABC): """ yield b"" - def prepare_value(self, value: Any) -> Union[str, int, bool]: + def prepare_value( + self, + value: Any, + bot: Bot, + files: Dict[str, Any], + _dumps_json: bool = True, + ) -> Any: """ Prepare value before send """ + if value is None: + return None if isinstance(value, str): return value - if isinstance(value, (list, dict)): - return self.json_dumps(self.clean_json(value)) + if value is UNSET_PARSE_MODE: + return self.prepare_value( + bot.parse_mode, bot=bot, files=files, _dumps_json=_dumps_json + ) + if value is UNSET_DISABLE_WEB_PAGE_PREVIEW: + return self.prepare_value( + bot.disable_web_page_preview, bot=bot, files=files, _dumps_json=_dumps_json + ) + if value is UNSET_PROTECT_CONTENT: + return self.prepare_value( + bot.protect_content, bot=bot, files=files, _dumps_json=_dumps_json + ) + if isinstance(value, InputFile): + key = secrets.token_urlsafe(10) + files[key] = value + return f"attach://{key}" + if isinstance(value, dict): + value = { + key: prepared_item + for key, item in value.items() + if ( + prepared_item := self.prepare_value( + item, bot=bot, files=files, _dumps_json=False + ) + ) + is not None + } + if _dumps_json: + return self.json_dumps(value) + return value + if isinstance(value, list): + value = [ + prepared_item + for item in value + if ( + prepared_item := self.prepare_value( + item, bot=bot, files=files, _dumps_json=False + ) + ) + is not None + ] + if _dumps_json: + return self.json_dumps(value) + return value if isinstance(value, datetime.timedelta): now = datetime.datetime.now() return str(round((now + value).timestamp())) if isinstance(value, datetime.datetime): return str(round(value.timestamp())) if isinstance(value, Enum): - return self.prepare_value(value.value) - return str(value) + return self.prepare_value(value.value, bot=bot, files=files) - def clean_json(self, value: Any) -> Any: - """ - Clean data before send - """ - if isinstance(value, list): - return [self.clean_json(v) for v in value if v is not None] - if isinstance(value, dict): - return {k: self.clean_json(v) for k, v in value.items() if v is not None} + if _dumps_json: + return self.json_dumps(value) return value async def __call__( - self, bot: Bot, method: TelegramMethod[TelegramType], timeout: Optional[int] = UNSET + self, + bot: Bot, + method: TelegramMethod[TelegramType], + timeout: Optional[int] = None, ) -> TelegramType: middleware = self.middleware.wrap_middlewares(self.make_request, timeout=timeout) return cast(TelegramType, await middleware(bot, method)) diff --git a/aiogram/dispatcher/dispatcher.py b/aiogram/dispatcher/dispatcher.py index 63eb9a3a..71791f72 100644 --- a/aiogram/dispatcher/dispatcher.py +++ b/aiogram/dispatcher/dispatcher.py @@ -15,7 +15,8 @@ from ..fsm.middleware import FSMContextMiddleware from ..fsm.storage.base import BaseEventIsolation, BaseStorage from ..fsm.storage.memory import DisabledEventIsolation, MemoryStorage from ..fsm.strategy import FSMStrategy -from ..methods import GetUpdates, Request, TelegramMethod +from ..methods import GetUpdates, TelegramMethod +from ..methods.base import TelegramType from ..types import Update, User from ..types.update import UpdateTypeLookupError from ..utils.backoff import Backoff, BackoffConfig @@ -364,7 +365,7 @@ class Dispatcher(Router): async def feed_webhook_update( self, bot: Bot, update: Union[Update, Dict[str, Any]], _timeout: float = 55, **kwargs: Any - ) -> Optional[Request]: + ) -> Optional[TelegramMethod[TelegramType]]: if not isinstance(update, Update): # Allow to use raw updates update = Update(**update) @@ -410,7 +411,7 @@ class Dispatcher(Router): # TODO: handle exceptions response: Any = process_updates.result() if isinstance(response, TelegramMethod): - return response.build_request(bot=bot) + return response else: process_updates.remove_done_callback(release_waiter) diff --git a/aiogram/methods/add_sticker_to_set.py b/aiogram/methods/add_sticker_to_set.py index 75b8387a..49759b84 100644 --- a/aiogram/methods/add_sticker_to_set.py +++ b/aiogram/methods/add_sticker_to_set.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING -from ..types import InputFile, InputSticker -from .base import Request, TelegramMethod, prepare_input_sticker - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types import InputSticker +from .base import TelegramMethod class AddStickerToSet(TelegramMethod[bool]): @@ -17,6 +14,7 @@ class AddStickerToSet(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "addStickerToSet" user_id: int """User identifier of sticker set owner""" @@ -24,11 +22,3 @@ class AddStickerToSet(TelegramMethod[bool]): """Sticker set name""" sticker: InputSticker """A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set isn't changed.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - files: Dict[str, InputFile] = {} - prepare_input_sticker(input_sticker=data["sticker"], files=files) - - return Request(method="addStickerToSet", data=data, files=files) diff --git a/aiogram/methods/answer_callback_query.py b/aiogram/methods/answer_callback_query.py index 8d932f51..4b3e16fd 100644 --- a/aiogram/methods/answer_callback_query.py +++ b/aiogram/methods/answer_callback_query.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class AnswerCallbackQuery(TelegramMethod[bool]): @@ -18,6 +15,7 @@ class AnswerCallbackQuery(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "answerCallbackQuery" callback_query_id: str """Unique identifier for the query to be answered""" @@ -29,8 +27,3 @@ class AnswerCallbackQuery(TelegramMethod[bool]): """URL that will be opened by the user's client. If you have created a :class:`aiogram.types.game.Game` and accepted the conditions via `@BotFather `_, specify the URL that opens your game - note that this will only work if the query comes from a `https://core.telegram.org/bots/api#inlinekeyboardbutton `_ *callback_game* button.""" cache_time: Optional[int] = None """The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="answerCallbackQuery", data=data) diff --git a/aiogram/methods/answer_inline_query.py b/aiogram/methods/answer_inline_query.py index 56422180..f7760cb0 100644 --- a/aiogram/methods/answer_inline_query.py +++ b/aiogram/methods/answer_inline_query.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional +from typing import TYPE_CHECKING, List, Optional from ..types import InlineQueryResult -from .base import Request, TelegramMethod, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class AnswerInlineQuery(TelegramMethod[bool]): @@ -19,6 +16,7 @@ class AnswerInlineQuery(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "answerInlineQuery" inline_query_id: str """Unique identifier for the answered query""" @@ -34,15 +32,3 @@ class AnswerInlineQuery(TelegramMethod[bool]): """If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter *switch_pm_parameter*""" switch_pm_parameter: Optional[str] = None """`Deep-linking `_ parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only :code:`A-Z`, :code:`a-z`, :code:`0-9`, :code:`_` and :code:`-` are allowed.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - input_message_contents = [] - for result in data["results"]: - input_message_content = result.get("input_message_content", None) - if input_message_content is not None: - input_message_contents.append(input_message_content) - - prepare_parse_mode(bot, data["results"] + input_message_contents) - return Request(method="answerInlineQuery", data=data) diff --git a/aiogram/methods/answer_pre_checkout_query.py b/aiogram/methods/answer_pre_checkout_query.py index 507f8158..a87929fb 100644 --- a/aiogram/methods/answer_pre_checkout_query.py +++ b/aiogram/methods/answer_pre_checkout_query.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class AnswerPreCheckoutQuery(TelegramMethod[bool]): @@ -16,6 +13,7 @@ class AnswerPreCheckoutQuery(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "answerPreCheckoutQuery" pre_checkout_query_id: str """Unique identifier for the query to be answered""" @@ -23,8 +21,3 @@ class AnswerPreCheckoutQuery(TelegramMethod[bool]): """Specify :code:`True` if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use :code:`False` if there are any problems.""" error_message: Optional[str] = None """Required if *ok* is :code:`False`. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="answerPreCheckoutQuery", data=data) diff --git a/aiogram/methods/answer_shipping_query.py b/aiogram/methods/answer_shipping_query.py index 99f093a9..4e62d0cb 100644 --- a/aiogram/methods/answer_shipping_query.py +++ b/aiogram/methods/answer_shipping_query.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional +from typing import TYPE_CHECKING, List, Optional from ..types import ShippingOption -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class AnswerShippingQuery(TelegramMethod[bool]): @@ -17,6 +14,7 @@ class AnswerShippingQuery(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "answerShippingQuery" shipping_query_id: str """Unique identifier for the query to be answered""" @@ -26,8 +24,3 @@ class AnswerShippingQuery(TelegramMethod[bool]): """Required if *ok* is :code:`True`. A JSON-serialized array of available shipping options.""" error_message: Optional[str] = None """Required if *ok* is :code:`False`. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="answerShippingQuery", data=data) diff --git a/aiogram/methods/answer_web_app_query.py b/aiogram/methods/answer_web_app_query.py index c9315ee8..d45e249d 100644 --- a/aiogram/methods/answer_web_app_query.py +++ b/aiogram/methods/answer_web_app_query.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING from ..types import InlineQueryResult, SentWebAppMessage -from .base import Request, TelegramMethod, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class AnswerWebAppQuery(TelegramMethod[SentWebAppMessage]): @@ -17,17 +14,9 @@ class AnswerWebAppQuery(TelegramMethod[SentWebAppMessage]): """ __returning__ = SentWebAppMessage + __api_method__ = "answerWebAppQuery" web_app_query_id: str """Unique identifier for the query to be answered""" result: InlineQueryResult """A JSON-serialized object describing the message to be sent""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - prepare_parse_mode( - bot, data["result"], parse_mode_property="parse_mode", entities_property="entities" - ) - - return Request(method="answerWebAppQuery", data=data) diff --git a/aiogram/methods/approve_chat_join_request.py b/aiogram/methods/approve_chat_join_request.py index 5c4008af..83e34599 100644 --- a/aiogram/methods/approve_chat_join_request.py +++ b/aiogram/methods/approve_chat_join_request.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class ApproveChatJoinRequest(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class ApproveChatJoinRequest(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "approveChatJoinRequest" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" user_id: int """Unique identifier of the target user""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="approveChatJoinRequest", data=data) diff --git a/aiogram/methods/ban_chat_member.py b/aiogram/methods/ban_chat_member.py index 3252af1b..ecc468ee 100644 --- a/aiogram/methods/ban_chat_member.py +++ b/aiogram/methods/ban_chat_member.py @@ -1,12 +1,9 @@ from __future__ import annotations import datetime -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class BanChatMember(TelegramMethod[bool]): @@ -17,6 +14,7 @@ class BanChatMember(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "banChatMember" chat_id: Union[int, str] """Unique identifier for the target group or username of the target supergroup or channel (in the format :code:`@channelusername`)""" @@ -26,8 +24,3 @@ class BanChatMember(TelegramMethod[bool]): """Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only.""" revoke_messages: Optional[bool] = None """Pass :code:`True` to delete all messages from the chat for the user that is being removed. If :code:`False`, the user will be able to see messages in the group that were sent before the user was removed. Always :code:`True` for supergroups and channels.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="banChatMember", data=data) diff --git a/aiogram/methods/ban_chat_sender_chat.py b/aiogram/methods/ban_chat_sender_chat.py index c68d8f29..e63f2ecc 100644 --- a/aiogram/methods/ban_chat_sender_chat.py +++ b/aiogram/methods/ban_chat_sender_chat.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class BanChatSenderChat(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class BanChatSenderChat(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "banChatSenderChat" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" sender_chat_id: int """Unique identifier of the target sender chat""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="banChatSenderChat", data=data) diff --git a/aiogram/methods/base.py b/aiogram/methods/base.py index 8f9db0d4..33045bf0 100644 --- a/aiogram/methods/base.py +++ b/aiogram/methods/base.py @@ -1,22 +1,13 @@ from __future__ import annotations -import abc -import secrets -from typing import ( - TYPE_CHECKING, - Any, - Dict, - Generator, - Generic, - Optional, - TypeVar, - Union, -) +from abc import ABC, abstractmethod +from typing import TYPE_CHECKING, Any, Dict, Generator, Generic, Optional, TypeVar from pydantic import BaseConfig, BaseModel, Extra, root_validator from pydantic.generics import GenericModel -from ..types import UNSET, InputFile, ResponseParameters +from ..types import InputFile, ResponseParameters +from ..types.base import UNSET_TYPE if TYPE_CHECKING: from ..client.bot import Bot @@ -42,7 +33,7 @@ class Response(GenericModel, Generic[TelegramType]): parameters: Optional[ResponseParameters] = None -class TelegramMethod(abc.ABC, BaseModel, Generic[TelegramType]): +class TelegramMethod(ABC, BaseModel, Generic[TelegramType]): class Config(BaseConfig): # use_enum_values = True extra = Extra.allow @@ -54,25 +45,23 @@ class TelegramMethod(abc.ABC, BaseModel, Generic[TelegramType]): @root_validator(pre=True) def remove_unset(cls, values: Dict[str, Any]) -> Dict[str, Any]: """ - Remove UNSET from `parse_mode` before fields validation. + Remove UNSET before fields validation. We use UNSET as a sentinel value for `parse_mode` and replace it to real value later. - It isn't a problem when it's just default value for a model field, but UNSET might be passing to - a model initialization from `Bot.method_name`, so we must take care of it and - remove it before fields validation. + It isn't a problem when it's just default value for a model field, + but UNSET might be passing to a model initialization from `Bot.method_name`, + so we must take care of it and remove it before fields validation. """ - for parse_mode_attribute in {"parse_mode", "explanation_parse_mode"}: - if parse_mode_attribute in values and values[parse_mode_attribute] is UNSET: - values.pop(parse_mode_attribute) - return values + return {k: v for k, v in values.items() if not isinstance(v, UNSET_TYPE)} @property - @abc.abstractmethod + @abstractmethod def __returning__(self) -> type: # pragma: no cover pass - @abc.abstractmethod - def build_request(self, bot: Bot) -> Request: # pragma: no cover + @property + @abstractmethod + def __api_method__(self) -> str: pass def dict(self, **kwargs: Any) -> Any: @@ -95,84 +84,3 @@ class TelegramMethod(abc.ABC, BaseModel, Generic[TelegramType]): bot = Bot.get_current(no_error=False) return self.emit(bot).__await__() - - -def prepare_file(name: str, value: Any, data: Dict[str, Any], files: Dict[str, Any]) -> None: - if not value: - return - if name == "thumbnail": - tag = secrets.token_urlsafe(10) - files[tag] = value - data["thumbnail"] = f"attach://{tag}" - elif isinstance(value, InputFile): - files[name] = value - else: - data[name] = value - - -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 - and input_media["media"] - and isinstance(input_media["media"], InputFile) - ): - tag = secrets.token_urlsafe(10) - files[tag] = input_media.pop("media") # type: ignore - input_media["media"] = f"attach://{tag}" - - -def prepare_input_sticker(input_sticker: Dict[str, Any], files: Dict[str, InputFile]) -> None: - if ( - "sticker" in input_sticker - and input_sticker["sticker"] - and isinstance(input_sticker["sticker"], InputFile) - ): - tag = secrets.token_urlsafe(10) - files[tag] = input_sticker.pop("sticker") - input_sticker["sticker"] = f"attach://{tag}" - - -def prepare_input_stickers(data: Dict[str, Any], files: Dict[str, InputFile]) -> None: - for input_sticker in data["stickers"]: - prepare_input_sticker(input_sticker, files=files) - - -def prepare_media_file(data: Dict[str, Any], files: Dict[str, InputFile]) -> None: - if ( - data["media"] - and "media" in data["media"] - and isinstance(data["media"]["media"], InputFile) - ): - tag = secrets.token_urlsafe(10) - files[tag] = data["media"].pop("media") - data["media"]["media"] = f"attach://{tag}" - - -def prepare_parse_mode( - bot: Bot, - root: Any, - parse_mode_property: str = "parse_mode", - entities_property: str = "entities", -) -> None: - """ - Find and set parse_mode with highest priority. - - Developer can manually set parse_mode for each message (or message-like) object, - but if parse_mode was unset we should use value from Bot object. - - We can't use None for "unset state", because None itself is the parse_mode option. - """ - if isinstance(root, list): - for item in root: - prepare_parse_mode( - bot=bot, - root=item, - parse_mode_property=parse_mode_property, - entities_property=entities_property, - ) - elif root.get(parse_mode_property, UNSET) is UNSET: - if bot.parse_mode and root.get(entities_property, None) is None: - root[parse_mode_property] = bot.parse_mode - else: - root[parse_mode_property] = None diff --git a/aiogram/methods/close.py b/aiogram/methods/close.py index 78e8f07d..c8e9008d 100644 --- a/aiogram/methods/close.py +++ b/aiogram/methods/close.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class Close(TelegramMethod[bool]): @@ -16,8 +13,4 @@ class Close(TelegramMethod[bool]): """ __returning__ = bool - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="close", data=data) + __api_method__ = "close" diff --git a/aiogram/methods/close_forum_topic.py b/aiogram/methods/close_forum_topic.py index da9eedec..7ab5a479 100644 --- a/aiogram/methods/close_forum_topic.py +++ b/aiogram/methods/close_forum_topic.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class CloseForumTopic(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class CloseForumTopic(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "closeForumTopic" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" message_thread_id: int """Unique identifier for the target message thread of the forum topic""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="closeForumTopic", data=data) diff --git a/aiogram/methods/close_general_forum_topic.py b/aiogram/methods/close_general_forum_topic.py index 1dea28c4..bc44bde5 100644 --- a/aiogram/methods/close_general_forum_topic.py +++ b/aiogram/methods/close_general_forum_topic.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class CloseGeneralForumTopic(TelegramMethod[bool]): @@ -16,11 +13,7 @@ class CloseGeneralForumTopic(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "closeGeneralForumTopic" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="closeGeneralForumTopic", data=data) diff --git a/aiogram/methods/copy_message.py b/aiogram/methods/copy_message.py index fc30b8fe..5e34bb7d 100644 --- a/aiogram/methods/copy_message.py +++ b/aiogram/methods/copy_message.py @@ -1,9 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from ..types import ( - UNSET, + UNSET_PARSE_MODE, ForceReply, InlineKeyboardMarkup, MessageEntity, @@ -11,10 +11,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class CopyMessage(TelegramMethod[MessageId]): @@ -25,6 +23,7 @@ class CopyMessage(TelegramMethod[MessageId]): """ __returning__ = MessageId + __api_method__ = "copyMessage" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -36,13 +35,13 @@ class CopyMessage(TelegramMethod[MessageId]): """Unique identifier for the target message thread (topic) of the forum; for forum supergroups only""" caption: Optional[str] = None """New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """Mode for parsing entities in the new caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """A JSON-serialized list of special entities that appear in the new caption, which can be specified instead of *parse_mode*""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -52,12 +51,3 @@ class CopyMessage(TelegramMethod[MessageId]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - prepare_parse_mode( - bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" - ) - - return Request(method="copyMessage", data=data) diff --git a/aiogram/methods/create_chat_invite_link.py b/aiogram/methods/create_chat_invite_link.py index a9cf9144..539115bb 100644 --- a/aiogram/methods/create_chat_invite_link.py +++ b/aiogram/methods/create_chat_invite_link.py @@ -1,13 +1,10 @@ from __future__ import annotations import datetime -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import ChatInviteLink -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class CreateChatInviteLink(TelegramMethod[ChatInviteLink]): @@ -18,6 +15,7 @@ class CreateChatInviteLink(TelegramMethod[ChatInviteLink]): """ __returning__ = ChatInviteLink + __api_method__ = "createChatInviteLink" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -29,8 +27,3 @@ class CreateChatInviteLink(TelegramMethod[ChatInviteLink]): """The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999""" creates_join_request: Optional[bool] = None """:code:`True`, if users joining the chat via the link need to be approved by chat administrators. If :code:`True`, *member_limit* can't be specified""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="createChatInviteLink", data=data) diff --git a/aiogram/methods/create_forum_topic.py b/aiogram/methods/create_forum_topic.py index bafd8ef4..f4b3f4da 100644 --- a/aiogram/methods/create_forum_topic.py +++ b/aiogram/methods/create_forum_topic.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import ForumTopic -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class CreateForumTopic(TelegramMethod[ForumTopic]): @@ -17,6 +14,7 @@ class CreateForumTopic(TelegramMethod[ForumTopic]): """ __returning__ = ForumTopic + __api_method__ = "createForumTopic" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" @@ -26,8 +24,3 @@ class CreateForumTopic(TelegramMethod[ForumTopic]): """Color of the topic icon in RGB format. Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F)""" icon_custom_emoji_id: Optional[str] = None """Unique identifier of the custom emoji shown as the topic icon. Use :class:`aiogram.methods.get_forum_topic_icon_stickers.GetForumTopicIconStickers` to get all allowed custom emoji identifiers.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="createForumTopic", data=data) diff --git a/aiogram/methods/create_invoice_link.py b/aiogram/methods/create_invoice_link.py index 5ba21a9d..de6497c1 100644 --- a/aiogram/methods/create_invoice_link.py +++ b/aiogram/methods/create_invoice_link.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional +from typing import TYPE_CHECKING, List, Optional from ..types import LabeledPrice -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class CreateInvoiceLink(TelegramMethod[str]): @@ -17,6 +14,7 @@ class CreateInvoiceLink(TelegramMethod[str]): """ __returning__ = str + __api_method__ = "createInvoiceLink" title: str """Product name, 1-32 characters""" @@ -58,8 +56,3 @@ class CreateInvoiceLink(TelegramMethod[str]): """Pass :code:`True` if the user's email address should be sent to the provider""" is_flexible: Optional[bool] = None """Pass :code:`True` if the final price depends on the shipping method""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="createInvoiceLink", data=data) diff --git a/aiogram/methods/create_new_sticker_set.py b/aiogram/methods/create_new_sticker_set.py index 651c6672..6406df81 100644 --- a/aiogram/methods/create_new_sticker_set.py +++ b/aiogram/methods/create_new_sticker_set.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional +from typing import TYPE_CHECKING, List, Optional -from ..types import InputFile, InputSticker -from .base import Request, TelegramMethod, prepare_input_sticker, prepare_input_stickers - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types import InputSticker +from .base import TelegramMethod class CreateNewStickerSet(TelegramMethod[bool]): @@ -17,6 +14,7 @@ class CreateNewStickerSet(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "createNewStickerSet" user_id: int """User identifier of created sticker set owner""" @@ -32,11 +30,3 @@ class CreateNewStickerSet(TelegramMethod[bool]): """Type of stickers in the set, pass 'regular', 'mask', or 'custom_emoji'. By default, a regular sticker set is created.""" needs_repainting: Optional[bool] = None """Pass :code:`True` if stickers in the sticker set must be repainted to the color of text when used in messages, the accent color if used as emoji status, white on chat photos, or another appropriate color based on context; for custom emoji sticker sets only""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - files: Dict[str, InputFile] = {} - - prepare_input_stickers(data=data, files=files) - - return Request(method="createNewStickerSet", data=data, files=files) diff --git a/aiogram/methods/decline_chat_join_request.py b/aiogram/methods/decline_chat_join_request.py index 6bc03c9e..7861b7bb 100644 --- a/aiogram/methods/decline_chat_join_request.py +++ b/aiogram/methods/decline_chat_join_request.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class DeclineChatJoinRequest(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class DeclineChatJoinRequest(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "declineChatJoinRequest" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" user_id: int """Unique identifier of the target user""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="declineChatJoinRequest", data=data) diff --git a/aiogram/methods/delete_chat_photo.py b/aiogram/methods/delete_chat_photo.py index 9fe12a65..11a3836e 100644 --- a/aiogram/methods/delete_chat_photo.py +++ b/aiogram/methods/delete_chat_photo.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class DeleteChatPhoto(TelegramMethod[bool]): @@ -16,11 +13,7 @@ class DeleteChatPhoto(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "deleteChatPhoto" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="deleteChatPhoto", data=data) diff --git a/aiogram/methods/delete_chat_sticker_set.py b/aiogram/methods/delete_chat_sticker_set.py index 18fbaf82..681293df 100644 --- a/aiogram/methods/delete_chat_sticker_set.py +++ b/aiogram/methods/delete_chat_sticker_set.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class DeleteChatStickerSet(TelegramMethod[bool]): @@ -16,11 +13,7 @@ class DeleteChatStickerSet(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "deleteChatStickerSet" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="deleteChatStickerSet", data=data) diff --git a/aiogram/methods/delete_forum_topic.py b/aiogram/methods/delete_forum_topic.py index acbe8858..4733c67d 100644 --- a/aiogram/methods/delete_forum_topic.py +++ b/aiogram/methods/delete_forum_topic.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class DeleteForumTopic(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class DeleteForumTopic(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "deleteForumTopic" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" message_thread_id: int """Unique identifier for the target message thread of the forum topic""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="deleteForumTopic", data=data) diff --git a/aiogram/methods/delete_message.py b/aiogram/methods/delete_message.py index 09279969..468411d5 100644 --- a/aiogram/methods/delete_message.py +++ b/aiogram/methods/delete_message.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class DeleteMessage(TelegramMethod[bool]): @@ -34,13 +31,9 @@ class DeleteMessage(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "deleteMessage" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" message_id: int """Identifier of the message to delete""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="deleteMessage", data=data) diff --git a/aiogram/methods/delete_my_commands.py b/aiogram/methods/delete_my_commands.py index 0e475625..d73814db 100644 --- a/aiogram/methods/delete_my_commands.py +++ b/aiogram/methods/delete_my_commands.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional from ..types import BotCommandScope -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class DeleteMyCommands(TelegramMethod[bool]): @@ -17,13 +14,9 @@ class DeleteMyCommands(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "deleteMyCommands" scope: Optional[BotCommandScope] = None """A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to :class:`aiogram.types.bot_command_scope_default.BotCommandScopeDefault`.""" language_code: Optional[str] = None """A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="deleteMyCommands", data=data) diff --git a/aiogram/methods/delete_sticker_from_set.py b/aiogram/methods/delete_sticker_from_set.py index cb40c366..96219c15 100644 --- a/aiogram/methods/delete_sticker_from_set.py +++ b/aiogram/methods/delete_sticker_from_set.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class DeleteStickerFromSet(TelegramMethod[bool]): @@ -16,11 +13,7 @@ class DeleteStickerFromSet(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "deleteStickerFromSet" sticker: str """File identifier of the sticker""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="deleteStickerFromSet", data=data) diff --git a/aiogram/methods/delete_sticker_set.py b/aiogram/methods/delete_sticker_set.py index 2ffa48f2..d5a0f67e 100644 --- a/aiogram/methods/delete_sticker_set.py +++ b/aiogram/methods/delete_sticker_set.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class DeleteStickerSet(TelegramMethod[bool]): @@ -16,11 +13,7 @@ class DeleteStickerSet(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "deleteStickerSet" name: str """Sticker set name""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="deleteStickerSet", data=data) diff --git a/aiogram/methods/delete_webhook.py b/aiogram/methods/delete_webhook.py index a68bf78d..b9d6cd7b 100644 --- a/aiogram/methods/delete_webhook.py +++ b/aiogram/methods/delete_webhook.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class DeleteWebhook(TelegramMethod[bool]): @@ -16,11 +13,7 @@ class DeleteWebhook(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "deleteWebhook" drop_pending_updates: Optional[bool] = None """Pass :code:`True` to drop all pending updates""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="deleteWebhook", data=data) diff --git a/aiogram/methods/edit_chat_invite_link.py b/aiogram/methods/edit_chat_invite_link.py index 3bd3a4c3..26f4ccc3 100644 --- a/aiogram/methods/edit_chat_invite_link.py +++ b/aiogram/methods/edit_chat_invite_link.py @@ -1,13 +1,10 @@ from __future__ import annotations import datetime -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import ChatInviteLink -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class EditChatInviteLink(TelegramMethod[ChatInviteLink]): @@ -18,6 +15,7 @@ class EditChatInviteLink(TelegramMethod[ChatInviteLink]): """ __returning__ = ChatInviteLink + __api_method__ = "editChatInviteLink" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -31,8 +29,3 @@ class EditChatInviteLink(TelegramMethod[ChatInviteLink]): """The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999""" creates_join_request: Optional[bool] = None """:code:`True`, if users joining the chat via the link need to be approved by chat administrators. If :code:`True`, *member_limit* can't be specified""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="editChatInviteLink", data=data) diff --git a/aiogram/methods/edit_forum_topic.py b/aiogram/methods/edit_forum_topic.py index 2e76a190..f87d0cea 100644 --- a/aiogram/methods/edit_forum_topic.py +++ b/aiogram/methods/edit_forum_topic.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class EditForumTopic(TelegramMethod[bool]): @@ -16,6 +13,7 @@ class EditForumTopic(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "editForumTopic" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" @@ -25,8 +23,3 @@ class EditForumTopic(TelegramMethod[bool]): """New topic name, 0-128 characters. If not specified or empty, the current name of the topic will be kept""" icon_custom_emoji_id: Optional[str] = None """New unique identifier of the custom emoji shown as the topic icon. Use :class:`aiogram.methods.get_forum_topic_icon_stickers.GetForumTopicIconStickers` to get all allowed custom emoji identifiers. Pass an empty string to remove the icon. If not specified, the current icon will be kept""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="editForumTopic", data=data) diff --git a/aiogram/methods/edit_general_forum_topic.py b/aiogram/methods/edit_general_forum_topic.py index 532e05b7..f35c2048 100644 --- a/aiogram/methods/edit_general_forum_topic.py +++ b/aiogram/methods/edit_general_forum_topic.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class EditGeneralForumTopic(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class EditGeneralForumTopic(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "editGeneralForumTopic" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" name: str """New topic name, 1-128 characters""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="editGeneralForumTopic", data=data) diff --git a/aiogram/methods/edit_message_caption.py b/aiogram/methods/edit_message_caption.py index 8360ccf5..66cdeac9 100644 --- a/aiogram/methods/edit_message_caption.py +++ b/aiogram/methods/edit_message_caption.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union -from ..types import UNSET, InlineKeyboardMarkup, Message, MessageEntity -from .base import Request, TelegramMethod, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types import UNSET_PARSE_MODE, InlineKeyboardMarkup, Message, MessageEntity +from .base import TelegramMethod class EditMessageCaption(TelegramMethod[Union[Message, bool]]): @@ -17,6 +14,7 @@ class EditMessageCaption(TelegramMethod[Union[Message, bool]]): """ __returning__ = Union[Message, bool] + __api_method__ = "editMessageCaption" chat_id: Optional[Union[int, str]] = None """Required if *inline_message_id* is not specified. Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -26,18 +24,9 @@ class EditMessageCaption(TelegramMethod[Union[Message, bool]]): """Required if *chat_id* and *message_id* are not specified. Identifier of the inline message""" caption: Optional[str] = None """New caption of the message, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """Mode for parsing entities in the message caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """A JSON-serialized list of special entities that appear in the caption, which can be specified instead of *parse_mode*""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for an `inline keyboard `_.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - prepare_parse_mode( - bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" - ) - - return Request(method="editMessageCaption", data=data) diff --git a/aiogram/methods/edit_message_live_location.py b/aiogram/methods/edit_message_live_location.py index 35a72912..e35c3225 100644 --- a/aiogram/methods/edit_message_live_location.py +++ b/aiogram/methods/edit_message_live_location.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import InlineKeyboardMarkup, Message -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class EditMessageLiveLocation(TelegramMethod[Union[Message, bool]]): @@ -17,6 +14,7 @@ class EditMessageLiveLocation(TelegramMethod[Union[Message, bool]]): """ __returning__ = Union[Message, bool] + __api_method__ = "editMessageLiveLocation" latitude: float """Latitude of new location""" @@ -36,8 +34,3 @@ class EditMessageLiveLocation(TelegramMethod[Union[Message, bool]]): """The maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for a new `inline keyboard `_.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="editMessageLiveLocation", data=data) diff --git a/aiogram/methods/edit_message_media.py b/aiogram/methods/edit_message_media.py index b2434105..f986a841 100644 --- a/aiogram/methods/edit_message_media.py +++ b/aiogram/methods/edit_message_media.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union -from ..types import InlineKeyboardMarkup, InputFile, InputMedia, Message -from .base import Request, TelegramMethod, prepare_media_file, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types import InlineKeyboardMarkup, InputMedia, Message +from .base import TelegramMethod class EditMessageMedia(TelegramMethod[Union[Message, bool]]): @@ -17,6 +14,7 @@ class EditMessageMedia(TelegramMethod[Union[Message, bool]]): """ __returning__ = Union[Message, bool] + __api_method__ = "editMessageMedia" media: InputMedia """A JSON-serialized object for a new media content of the message""" @@ -28,11 +26,3 @@ class EditMessageMedia(TelegramMethod[Union[Message, bool]]): """Required if *chat_id* and *message_id* are not specified. Identifier of the inline message""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for a new `inline keyboard `_.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - prepare_parse_mode(bot, data["media"]) - files: Dict[str, InputFile] = {} - prepare_media_file(data=data, files=files) - - return Request(method="editMessageMedia", data=data, files=files) diff --git a/aiogram/methods/edit_message_reply_markup.py b/aiogram/methods/edit_message_reply_markup.py index 4b871d58..a828c9d8 100644 --- a/aiogram/methods/edit_message_reply_markup.py +++ b/aiogram/methods/edit_message_reply_markup.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import InlineKeyboardMarkup, Message -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class EditMessageReplyMarkup(TelegramMethod[Union[Message, bool]]): @@ -17,6 +14,7 @@ class EditMessageReplyMarkup(TelegramMethod[Union[Message, bool]]): """ __returning__ = Union[Message, bool] + __api_method__ = "editMessageReplyMarkup" chat_id: Optional[Union[int, str]] = None """Required if *inline_message_id* is not specified. Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -26,8 +24,3 @@ class EditMessageReplyMarkup(TelegramMethod[Union[Message, bool]]): """Required if *chat_id* and *message_id* are not specified. Identifier of the inline message""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for an `inline keyboard `_.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="editMessageReplyMarkup", data=data) diff --git a/aiogram/methods/edit_message_text.py b/aiogram/methods/edit_message_text.py index f47ef15a..79887c97 100644 --- a/aiogram/methods/edit_message_text.py +++ b/aiogram/methods/edit_message_text.py @@ -1,12 +1,10 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union -from ..types import UNSET, InlineKeyboardMarkup, Message, MessageEntity -from .base import Request, TelegramMethod, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types import UNSET_PARSE_MODE, InlineKeyboardMarkup, Message, MessageEntity +from ..types.base import UNSET_DISABLE_WEB_PAGE_PREVIEW +from .base import TelegramMethod class EditMessageText(TelegramMethod[Union[Message, bool]]): @@ -17,6 +15,7 @@ class EditMessageText(TelegramMethod[Union[Message, bool]]): """ __returning__ = Union[Message, bool] + __api_method__ = "editMessageText" text: str """New text of the message, 1-4096 characters after entities parsing""" @@ -26,20 +25,11 @@ class EditMessageText(TelegramMethod[Union[Message, bool]]): """Required if *inline_message_id* is not specified. Identifier of the message to edit""" inline_message_id: Optional[str] = None """Required if *chat_id* and *message_id* are not specified. Identifier of the inline message""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """Mode for parsing entities in the message text. See `formatting options `_ for more details.""" entities: Optional[List[MessageEntity]] = None """A JSON-serialized list of special entities that appear in message text, which can be specified instead of *parse_mode*""" - disable_web_page_preview: Optional[bool] = None + disable_web_page_preview: Optional[bool] = UNSET_DISABLE_WEB_PAGE_PREVIEW """Disables link previews for links in this message""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for an `inline keyboard `_.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - prepare_parse_mode( - bot, data, parse_mode_property="parse_mode", entities_property="entities" - ) - - return Request(method="editMessageText", data=data) diff --git a/aiogram/methods/export_chat_invite_link.py b/aiogram/methods/export_chat_invite_link.py index d4b72e34..ba4436ed 100644 --- a/aiogram/methods/export_chat_invite_link.py +++ b/aiogram/methods/export_chat_invite_link.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class ExportChatInviteLink(TelegramMethod[str]): @@ -18,11 +15,7 @@ class ExportChatInviteLink(TelegramMethod[str]): """ __returning__ = str + __api_method__ = "exportChatInviteLink" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="exportChatInviteLink", data=data) diff --git a/aiogram/methods/forward_message.py b/aiogram/methods/forward_message.py index c75aac76..45c084a0 100644 --- a/aiogram/methods/forward_message.py +++ b/aiogram/methods/forward_message.py @@ -1,12 +1,10 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import Message -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class ForwardMessage(TelegramMethod[Message]): @@ -17,6 +15,7 @@ class ForwardMessage(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "forwardMessage" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -28,10 +27,5 @@ class ForwardMessage(TelegramMethod[Message]): """Unique identifier for the target message thread (topic) of the forum; for forum supergroups only""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the forwarded message from forwarding and saving""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="forwardMessage", data=data) diff --git a/aiogram/methods/get_chat.py b/aiogram/methods/get_chat.py index 925e2638..a565529a 100644 --- a/aiogram/methods/get_chat.py +++ b/aiogram/methods/get_chat.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union from ..types import Chat -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetChat(TelegramMethod[Chat]): @@ -17,11 +14,7 @@ class GetChat(TelegramMethod[Chat]): """ __returning__ = Chat + __api_method__ = "getChat" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup or channel (in the format :code:`@channelusername`)""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getChat", data=data) diff --git a/aiogram/methods/get_chat_administrators.py b/aiogram/methods/get_chat_administrators.py index d760a93e..3e0cac3c 100644 --- a/aiogram/methods/get_chat_administrators.py +++ b/aiogram/methods/get_chat_administrators.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Union +from typing import TYPE_CHECKING, List, Union from ..types import ( ChatMemberAdministrator, @@ -10,10 +10,7 @@ from ..types import ( ChatMemberOwner, ChatMemberRestricted, ) -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetChatAdministrators( @@ -46,11 +43,7 @@ class GetChatAdministrators( ChatMemberBanned, ] ] + __api_method__ = "getChatAdministrators" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup or channel (in the format :code:`@channelusername`)""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getChatAdministrators", data=data) diff --git a/aiogram/methods/get_chat_member.py b/aiogram/methods/get_chat_member.py index ee531e1c..ab308024 100644 --- a/aiogram/methods/get_chat_member.py +++ b/aiogram/methods/get_chat_member.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union from ..types import ( ChatMemberAdministrator, @@ -10,10 +10,7 @@ from ..types import ( ChatMemberOwner, ChatMemberRestricted, ) -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetChatMember( @@ -42,13 +39,9 @@ class GetChatMember( ChatMemberLeft, ChatMemberBanned, ] + __api_method__ = "getChatMember" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup or channel (in the format :code:`@channelusername`)""" user_id: int """Unique identifier of the target user""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getChatMember", data=data) diff --git a/aiogram/methods/get_chat_member_count.py b/aiogram/methods/get_chat_member_count.py index 7b492998..c1b08e5b 100644 --- a/aiogram/methods/get_chat_member_count.py +++ b/aiogram/methods/get_chat_member_count.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetChatMemberCount(TelegramMethod[int]): @@ -16,11 +13,7 @@ class GetChatMemberCount(TelegramMethod[int]): """ __returning__ = int + __api_method__ = "getChatMemberCount" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup or channel (in the format :code:`@channelusername`)""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getChatMemberCount", data=data) diff --git a/aiogram/methods/get_chat_menu_button.py b/aiogram/methods/get_chat_menu_button.py index bdf07c38..6679d5df 100644 --- a/aiogram/methods/get_chat_menu_button.py +++ b/aiogram/methods/get_chat_menu_button.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import MenuButtonCommands, MenuButtonDefault, MenuButtonWebApp -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetChatMenuButton( @@ -19,11 +16,7 @@ class GetChatMenuButton( """ __returning__ = Union[MenuButtonDefault, MenuButtonWebApp, MenuButtonCommands] + __api_method__ = "getChatMenuButton" chat_id: Optional[int] = None """Unique identifier for the target private chat. If not specified, default bot's menu button will be returned""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getChatMenuButton", data=data) diff --git a/aiogram/methods/get_custom_emoji_stickers.py b/aiogram/methods/get_custom_emoji_stickers.py index bdc265e0..3522b539 100644 --- a/aiogram/methods/get_custom_emoji_stickers.py +++ b/aiogram/methods/get_custom_emoji_stickers.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List +from typing import TYPE_CHECKING, List from ..types import Sticker -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetCustomEmojiStickers(TelegramMethod[List[Sticker]]): @@ -17,11 +14,7 @@ class GetCustomEmojiStickers(TelegramMethod[List[Sticker]]): """ __returning__ = List[Sticker] + __api_method__ = "getCustomEmojiStickers" 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/aiogram/methods/get_file.py b/aiogram/methods/get_file.py index 9b006296..b84ff940 100644 --- a/aiogram/methods/get_file.py +++ b/aiogram/methods/get_file.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING from ..types import File -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetFile(TelegramMethod[File]): @@ -18,11 +15,7 @@ class GetFile(TelegramMethod[File]): """ __returning__ = File + __api_method__ = "getFile" file_id: str """File identifier to get information about""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getFile", data=data) diff --git a/aiogram/methods/get_forum_topic_icon_stickers.py b/aiogram/methods/get_forum_topic_icon_stickers.py index f00a8caa..31965661 100644 --- a/aiogram/methods/get_forum_topic_icon_stickers.py +++ b/aiogram/methods/get_forum_topic_icon_stickers.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List +from typing import TYPE_CHECKING, List from ..types import Sticker -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetForumTopicIconStickers(TelegramMethod[List[Sticker]]): @@ -17,8 +14,4 @@ class GetForumTopicIconStickers(TelegramMethod[List[Sticker]]): """ __returning__ = List[Sticker] - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getForumTopicIconStickers", data=data) + __api_method__ = "getForumTopicIconStickers" diff --git a/aiogram/methods/get_game_high_scores.py b/aiogram/methods/get_game_high_scores.py index 2ec6ded4..aff1c56a 100644 --- a/aiogram/methods/get_game_high_scores.py +++ b/aiogram/methods/get_game_high_scores.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional +from typing import TYPE_CHECKING, List, Optional from ..types import GameHighScore -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetGameHighScores(TelegramMethod[List[GameHighScore]]): @@ -19,6 +16,7 @@ class GetGameHighScores(TelegramMethod[List[GameHighScore]]): """ __returning__ = List[GameHighScore] + __api_method__ = "getGameHighScores" user_id: int """Target user id""" @@ -28,8 +26,3 @@ class GetGameHighScores(TelegramMethod[List[GameHighScore]]): """Required if *inline_message_id* is not specified. Identifier of the sent message""" inline_message_id: Optional[str] = None """Required if *chat_id* and *message_id* are not specified. Identifier of the inline message""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getGameHighScores", data=data) diff --git a/aiogram/methods/get_me.py b/aiogram/methods/get_me.py index 63f901a8..1a7f1fe1 100644 --- a/aiogram/methods/get_me.py +++ b/aiogram/methods/get_me.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING from ..types import User -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetMe(TelegramMethod[User]): @@ -17,8 +14,4 @@ class GetMe(TelegramMethod[User]): """ __returning__ = User - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getMe", data=data) + __api_method__ = "getMe" diff --git a/aiogram/methods/get_my_commands.py b/aiogram/methods/get_my_commands.py index ed3eae1a..d1e5c9c3 100644 --- a/aiogram/methods/get_my_commands.py +++ b/aiogram/methods/get_my_commands.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional +from typing import TYPE_CHECKING, List, Optional from ..types import BotCommand, BotCommandScope -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetMyCommands(TelegramMethod[List[BotCommand]]): @@ -17,13 +14,9 @@ class GetMyCommands(TelegramMethod[List[BotCommand]]): """ __returning__ = List[BotCommand] + __api_method__ = "getMyCommands" scope: Optional[BotCommandScope] = None """A JSON-serialized object, describing scope of users. Defaults to :class:`aiogram.types.bot_command_scope_default.BotCommandScopeDefault`.""" language_code: Optional[str] = None """A two-letter ISO 639-1 language code or an empty string""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getMyCommands", data=data) diff --git a/aiogram/methods/get_my_default_administrator_rights.py b/aiogram/methods/get_my_default_administrator_rights.py index 53a8e494..d20e7a15 100644 --- a/aiogram/methods/get_my_default_administrator_rights.py +++ b/aiogram/methods/get_my_default_administrator_rights.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional from ..types import ChatAdministratorRights -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetMyDefaultAdministratorRights(TelegramMethod[ChatAdministratorRights]): @@ -17,11 +14,7 @@ class GetMyDefaultAdministratorRights(TelegramMethod[ChatAdministratorRights]): """ __returning__ = ChatAdministratorRights + __api_method__ = "getMyDefaultAdministratorRights" for_channels: Optional[bool] = None """Pass :code:`True` to get default administrator rights of the bot in channels. Otherwise, default administrator rights of the bot for groups and supergroups will be returned.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getMyDefaultAdministratorRights", data=data) diff --git a/aiogram/methods/get_my_description.py b/aiogram/methods/get_my_description.py index 770e6263..3b0534ff 100644 --- a/aiogram/methods/get_my_description.py +++ b/aiogram/methods/get_my_description.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional from ..types import BotDescription -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetMyDescription(TelegramMethod[BotDescription]): @@ -17,11 +14,7 @@ class GetMyDescription(TelegramMethod[BotDescription]): """ __returning__ = BotDescription + __api_method__ = "getMyDescription" language_code: Optional[str] = None """A two-letter ISO 639-1 language code or an empty string""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getMyDescription", data=data) diff --git a/aiogram/methods/get_my_short_description.py b/aiogram/methods/get_my_short_description.py index a38d4ecc..81731142 100644 --- a/aiogram/methods/get_my_short_description.py +++ b/aiogram/methods/get_my_short_description.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional from ..types import BotShortDescription -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetMyShortDescription(TelegramMethod[BotShortDescription]): @@ -17,11 +14,7 @@ class GetMyShortDescription(TelegramMethod[BotShortDescription]): """ __returning__ = BotShortDescription + __api_method__ = "getMyShortDescription" language_code: Optional[str] = None """A two-letter ISO 639-1 language code or an empty string""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getMyShortDescription", data=data) diff --git a/aiogram/methods/get_sticker_set.py b/aiogram/methods/get_sticker_set.py index 35af44bf..87041172 100644 --- a/aiogram/methods/get_sticker_set.py +++ b/aiogram/methods/get_sticker_set.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING from ..types import StickerSet -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetStickerSet(TelegramMethod[StickerSet]): @@ -17,11 +14,7 @@ class GetStickerSet(TelegramMethod[StickerSet]): """ __returning__ = StickerSet + __api_method__ = "getStickerSet" name: str """Name of the sticker set""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getStickerSet", data=data) diff --git a/aiogram/methods/get_updates.py b/aiogram/methods/get_updates.py index 219a474a..8c60f051 100644 --- a/aiogram/methods/get_updates.py +++ b/aiogram/methods/get_updates.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional +from typing import TYPE_CHECKING, List, Optional from ..types import Update -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetUpdates(TelegramMethod[List[Update]]): @@ -23,6 +20,7 @@ class GetUpdates(TelegramMethod[List[Update]]): """ __returning__ = List[Update] + __api_method__ = "getUpdates" offset: Optional[int] = None """Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as :class:`aiogram.methods.get_updates.GetUpdates` is called with an *offset* higher than its *update_id*. The negative offset can be specified to retrieve updates starting from *-offset* update from the end of the updates queue. All previous updates will forgotten.""" @@ -32,8 +30,3 @@ class GetUpdates(TelegramMethod[List[Update]]): """Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only.""" allowed_updates: Optional[List[str]] = None """A JSON-serialized list of the update types you want your bot to receive. For example, specify ['message', 'edited_channel_post', 'callback_query'] to only receive updates of these types. See :class:`aiogram.types.update.Update` for a complete list of available update types. Specify an empty list to receive all update types except *chat_member* (default). If not specified, the previous setting will be used.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getUpdates", data=data) diff --git a/aiogram/methods/get_user_profile_photos.py b/aiogram/methods/get_user_profile_photos.py index 2bcc881a..47abc196 100644 --- a/aiogram/methods/get_user_profile_photos.py +++ b/aiogram/methods/get_user_profile_photos.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional from ..types import UserProfilePhotos -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetUserProfilePhotos(TelegramMethod[UserProfilePhotos]): @@ -17,6 +14,7 @@ class GetUserProfilePhotos(TelegramMethod[UserProfilePhotos]): """ __returning__ = UserProfilePhotos + __api_method__ = "getUserProfilePhotos" user_id: int """Unique identifier of the target user""" @@ -24,8 +22,3 @@ class GetUserProfilePhotos(TelegramMethod[UserProfilePhotos]): """Sequential number of the first photo to be returned. By default, all photos are returned.""" limit: Optional[int] = None """Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getUserProfilePhotos", data=data) diff --git a/aiogram/methods/get_webhook_info.py b/aiogram/methods/get_webhook_info.py index 6544cf83..5e4e194c 100644 --- a/aiogram/methods/get_webhook_info.py +++ b/aiogram/methods/get_webhook_info.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING from ..types import WebhookInfo -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class GetWebhookInfo(TelegramMethod[WebhookInfo]): @@ -17,8 +14,4 @@ class GetWebhookInfo(TelegramMethod[WebhookInfo]): """ __returning__ = WebhookInfo - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="getWebhookInfo", data=data) + __api_method__ = "getWebhookInfo" diff --git a/aiogram/methods/hide_general_forum_topic.py b/aiogram/methods/hide_general_forum_topic.py index 6e20a6bd..2587cf9e 100644 --- a/aiogram/methods/hide_general_forum_topic.py +++ b/aiogram/methods/hide_general_forum_topic.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class HideGeneralForumTopic(TelegramMethod[bool]): @@ -16,11 +13,7 @@ class HideGeneralForumTopic(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "hideGeneralForumTopic" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="hideGeneralForumTopic", data=data) diff --git a/aiogram/methods/leave_chat.py b/aiogram/methods/leave_chat.py index 748c25c6..5b2e15cf 100644 --- a/aiogram/methods/leave_chat.py +++ b/aiogram/methods/leave_chat.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class LeaveChat(TelegramMethod[bool]): @@ -16,11 +13,7 @@ class LeaveChat(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "leaveChat" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup or channel (in the format :code:`@channelusername`)""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="leaveChat", data=data) diff --git a/aiogram/methods/log_out.py b/aiogram/methods/log_out.py index 02c76ed2..3f3ea3de 100644 --- a/aiogram/methods/log_out.py +++ b/aiogram/methods/log_out.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class LogOut(TelegramMethod[bool]): @@ -16,8 +13,4 @@ class LogOut(TelegramMethod[bool]): """ __returning__ = bool - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="logOut", data=data) + __api_method__ = "logOut" diff --git a/aiogram/methods/pin_chat_message.py b/aiogram/methods/pin_chat_message.py index 57ec7fb9..d1641eea 100644 --- a/aiogram/methods/pin_chat_message.py +++ b/aiogram/methods/pin_chat_message.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class PinChatMessage(TelegramMethod[bool]): @@ -16,6 +13,7 @@ class PinChatMessage(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "pinChatMessage" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -23,8 +21,3 @@ class PinChatMessage(TelegramMethod[bool]): """Identifier of a message to pin""" disable_notification: Optional[bool] = None """Pass :code:`True` if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels and private chats.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="pinChatMessage", data=data) diff --git a/aiogram/methods/promote_chat_member.py b/aiogram/methods/promote_chat_member.py index 5069d951..d8f6096f 100644 --- a/aiogram/methods/promote_chat_member.py +++ b/aiogram/methods/promote_chat_member.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class PromoteChatMember(TelegramMethod[bool]): @@ -16,6 +13,7 @@ class PromoteChatMember(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "promoteChatMember" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -45,8 +43,3 @@ class PromoteChatMember(TelegramMethod[bool]): """Pass :code:`True` if the administrator can pin messages, supergroups only""" can_manage_topics: Optional[bool] = None """Pass :code:`True` if the user is allowed to create, rename, close, and reopen forum topics, supergroups only""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="promoteChatMember", data=data) diff --git a/aiogram/methods/reopen_forum_topic.py b/aiogram/methods/reopen_forum_topic.py index 1efa2366..efe1c31d 100644 --- a/aiogram/methods/reopen_forum_topic.py +++ b/aiogram/methods/reopen_forum_topic.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class ReopenForumTopic(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class ReopenForumTopic(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "reopenForumTopic" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" message_thread_id: int """Unique identifier for the target message thread of the forum topic""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="reopenForumTopic", data=data) diff --git a/aiogram/methods/reopen_general_forum_topic.py b/aiogram/methods/reopen_general_forum_topic.py index 1d27ca2d..381278a9 100644 --- a/aiogram/methods/reopen_general_forum_topic.py +++ b/aiogram/methods/reopen_general_forum_topic.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class ReopenGeneralForumTopic(TelegramMethod[bool]): @@ -16,11 +13,7 @@ class ReopenGeneralForumTopic(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "reopenGeneralForumTopic" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="reopenGeneralForumTopic", data=data) diff --git a/aiogram/methods/restrict_chat_member.py b/aiogram/methods/restrict_chat_member.py index 2a8b9fbe..efea2f97 100644 --- a/aiogram/methods/restrict_chat_member.py +++ b/aiogram/methods/restrict_chat_member.py @@ -1,13 +1,10 @@ from __future__ import annotations import datetime -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import ChatPermissions -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class RestrictChatMember(TelegramMethod[bool]): @@ -18,6 +15,7 @@ class RestrictChatMember(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "restrictChatMember" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" @@ -29,8 +27,3 @@ class RestrictChatMember(TelegramMethod[bool]): """Pass :code:`True` if chat permissions are set independently. Otherwise, the *can_send_other_messages* and *can_add_web_page_previews* permissions will imply the *can_send_messages*, *can_send_audios*, *can_send_documents*, *can_send_photos*, *can_send_videos*, *can_send_video_notes*, and *can_send_voice_notes* permissions; the *can_send_polls* permission will imply the *can_send_messages* permission.""" until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None """Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="restrictChatMember", data=data) diff --git a/aiogram/methods/revoke_chat_invite_link.py b/aiogram/methods/revoke_chat_invite_link.py index c644d8a4..ad31e77d 100644 --- a/aiogram/methods/revoke_chat_invite_link.py +++ b/aiogram/methods/revoke_chat_invite_link.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union from ..types import ChatInviteLink -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class RevokeChatInviteLink(TelegramMethod[ChatInviteLink]): @@ -17,13 +14,9 @@ class RevokeChatInviteLink(TelegramMethod[ChatInviteLink]): """ __returning__ = ChatInviteLink + __api_method__ = "revokeChatInviteLink" chat_id: Union[int, str] """Unique identifier of the target chat or username of the target channel (in the format :code:`@channelusername`)""" invite_link: str """The invite link to revoke""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="revokeChatInviteLink", data=data) diff --git a/aiogram/methods/send_animation.py b/aiogram/methods/send_animation.py index 7528d8be..14029d25 100644 --- a/aiogram/methods/send_animation.py +++ b/aiogram/methods/send_animation.py @@ -1,9 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from ..types import ( - UNSET, + UNSET_PARSE_MODE, ForceReply, InlineKeyboardMarkup, InputFile, @@ -12,10 +12,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendAnimation(TelegramMethod[Message]): @@ -26,6 +24,7 @@ class SendAnimation(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendAnimation" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -43,7 +42,7 @@ class SendAnimation(TelegramMethod[Message]): """Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass 'attach://' if the thumbnail was uploaded using multipart/form-data under . :ref:`More information on Sending Files » `""" caption: Optional[str] = None """Animation caption (may also be used when resending animation by *file_id*), 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """Mode for parsing entities in the animation caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """A JSON-serialized list of special entities that appear in the caption, which can be specified instead of *parse_mode*""" @@ -51,7 +50,7 @@ class SendAnimation(TelegramMethod[Message]): """Pass :code:`True` if the animation needs to be covered with a spoiler animation""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -61,16 +60,3 @@ class SendAnimation(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict(exclude={"animation", "thumb"}) - - prepare_parse_mode( - bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" - ) - - files: Dict[str, InputFile] = {} - prepare_file(data=data, files=files, name="animation", value=self.animation) - prepare_file(data=data, files=files, name="thumbnail", value=self.thumbnail) - - return Request(method="sendAnimation", data=data, files=files) diff --git a/aiogram/methods/send_audio.py b/aiogram/methods/send_audio.py index 6557a5c1..e0f4b900 100644 --- a/aiogram/methods/send_audio.py +++ b/aiogram/methods/send_audio.py @@ -1,9 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from ..types import ( - UNSET, + UNSET_PARSE_MODE, ForceReply, InlineKeyboardMarkup, InputFile, @@ -12,10 +12,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendAudio(TelegramMethod[Message]): @@ -27,6 +25,7 @@ class SendAudio(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendAudio" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -36,7 +35,7 @@ class SendAudio(TelegramMethod[Message]): """Unique identifier for the target message thread (topic) of the forum; for forum supergroups only""" caption: Optional[str] = None """Audio caption, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """Mode for parsing entities in the audio caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """A JSON-serialized list of special entities that appear in the caption, which can be specified instead of *parse_mode*""" @@ -50,7 +49,7 @@ class SendAudio(TelegramMethod[Message]): """Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass 'attach://' if the thumbnail was uploaded using multipart/form-data under . :ref:`More information on Sending Files » `""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -60,16 +59,3 @@ class SendAudio(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict(exclude={"audio", "thumb"}) - - prepare_parse_mode( - bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" - ) - - files: Dict[str, InputFile] = {} - prepare_file(data=data, files=files, name="audio", value=self.audio) - prepare_file(data=data, files=files, name="thumbnail", value=self.thumbnail) - - return Request(method="sendAudio", data=data, files=files) diff --git a/aiogram/methods/send_chat_action.py b/aiogram/methods/send_chat_action.py index 538300b2..d21dc68c 100644 --- a/aiogram/methods/send_chat_action.py +++ b/aiogram/methods/send_chat_action.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SendChatAction(TelegramMethod[bool]): @@ -20,6 +17,7 @@ class SendChatAction(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "sendChatAction" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -27,8 +25,3 @@ class SendChatAction(TelegramMethod[bool]): """Type of action to broadcast. Choose one, depending on what the user is about to receive: *typing* for `text messages `_, *upload_photo* for `photos `_, *record_video* or *upload_video* for `videos `_, *record_voice* or *upload_voice* for `voice notes `_, *upload_document* for `general files `_, *choose_sticker* for `stickers `_, *find_location* for `location data `_, *record_video_note* or *upload_video_note* for `video notes `_.""" message_thread_id: Optional[int] = None """Unique identifier for the target message thread; supergroups only""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="sendChatAction", data=data) diff --git a/aiogram/methods/send_contact.py b/aiogram/methods/send_contact.py index 41e1110b..35473338 100644 --- a/aiogram/methods/send_contact.py +++ b/aiogram/methods/send_contact.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import ( ForceReply, @@ -9,10 +9,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendContact(TelegramMethod[Message]): @@ -23,6 +21,7 @@ class SendContact(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendContact" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -38,7 +37,7 @@ class SendContact(TelegramMethod[Message]): """Additional data about the contact in the form of a `vCard `_, 0-2048 bytes""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -48,8 +47,3 @@ class SendContact(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="sendContact", data=data) diff --git a/aiogram/methods/send_dice.py b/aiogram/methods/send_dice.py index d898a742..9fa2ce70 100644 --- a/aiogram/methods/send_dice.py +++ b/aiogram/methods/send_dice.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import ( ForceReply, @@ -9,10 +9,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendDice(TelegramMethod[Message]): @@ -23,6 +21,7 @@ class SendDice(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendDice" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -32,7 +31,7 @@ class SendDice(TelegramMethod[Message]): """Emoji on which the dice throw animation is based. Currently, must be one of '🎲', '🎯', '🏀', '⚽', '🎳', or '🎰'. Dice can have values 1-6 for '🎲', '🎯' and '🎳', values 1-5 for '🏀' and '⚽', and values 1-64 for '🎰'. Defaults to '🎲'""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -42,8 +41,3 @@ class SendDice(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="sendDice", data=data) diff --git a/aiogram/methods/send_document.py b/aiogram/methods/send_document.py index 9b81b88f..5c83beb3 100644 --- a/aiogram/methods/send_document.py +++ b/aiogram/methods/send_document.py @@ -1,9 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from ..types import ( - UNSET, + UNSET_PARSE_MODE, ForceReply, InlineKeyboardMarkup, InputFile, @@ -12,10 +12,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendDocument(TelegramMethod[Message]): @@ -26,6 +24,7 @@ class SendDocument(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendDocument" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -37,7 +36,7 @@ class SendDocument(TelegramMethod[Message]): """Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass 'attach://' if the thumbnail was uploaded using multipart/form-data under . :ref:`More information on Sending Files » `""" caption: Optional[str] = None """Document caption (may also be used when resending documents by *file_id*), 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """Mode for parsing entities in the document caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """A JSON-serialized list of special entities that appear in the caption, which can be specified instead of *parse_mode*""" @@ -45,7 +44,7 @@ class SendDocument(TelegramMethod[Message]): """Disables automatic server-side content type detection for files uploaded using multipart/form-data""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -55,16 +54,3 @@ class SendDocument(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict(exclude={"document", "thumb"}) - - prepare_parse_mode( - bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" - ) - - files: Dict[str, InputFile] = {} - prepare_file(data=data, files=files, name="document", value=self.document) - prepare_file(data=data, files=files, name="thumbnail", value=self.thumbnail) - - return Request(method="sendDocument", data=data, files=files) diff --git a/aiogram/methods/send_game.py b/aiogram/methods/send_game.py index f6301562..ab55a459 100644 --- a/aiogram/methods/send_game.py +++ b/aiogram/methods/send_game.py @@ -1,12 +1,10 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional from ..types import InlineKeyboardMarkup, Message -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendGame(TelegramMethod[Message]): @@ -17,6 +15,7 @@ class SendGame(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendGame" chat_id: int """Unique identifier for the target chat""" @@ -26,7 +25,7 @@ class SendGame(TelegramMethod[Message]): """Unique identifier for the target message thread (topic) of the forum; for forum supergroups only""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -34,8 +33,3 @@ class SendGame(TelegramMethod[Message]): """Pass :code:`True` if the message should be sent even if the specified replied-to message is not found""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for an `inline keyboard `_. If empty, one 'Play game_title' button will be shown. If not empty, the first button must launch the game.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="sendGame", data=data) diff --git a/aiogram/methods/send_invoice.py b/aiogram/methods/send_invoice.py index 9f085fbd..d08002a9 100644 --- a/aiogram/methods/send_invoice.py +++ b/aiogram/methods/send_invoice.py @@ -1,12 +1,10 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from ..types import InlineKeyboardMarkup, LabeledPrice, Message -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendInvoice(TelegramMethod[Message]): @@ -17,6 +15,7 @@ class SendInvoice(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendInvoice" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -66,7 +65,7 @@ class SendInvoice(TelegramMethod[Message]): """Pass :code:`True` if the final price depends on the shipping method""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -74,8 +73,3 @@ class SendInvoice(TelegramMethod[Message]): """Pass :code:`True` if the message should be sent even if the specified replied-to message is not found""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for an `inline keyboard `_. If empty, one 'Pay :code:`total price`' button will be shown. If not empty, the first button must be a Pay button.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="sendInvoice", data=data) diff --git a/aiogram/methods/send_location.py b/aiogram/methods/send_location.py index 350157b8..845b4741 100644 --- a/aiogram/methods/send_location.py +++ b/aiogram/methods/send_location.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import ( ForceReply, @@ -9,10 +9,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendLocation(TelegramMethod[Message]): @@ -23,6 +21,7 @@ class SendLocation(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendLocation" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -42,7 +41,7 @@ class SendLocation(TelegramMethod[Message]): """For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -52,8 +51,3 @@ class SendLocation(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="sendLocation", data=data) diff --git a/aiogram/methods/send_media_group.py b/aiogram/methods/send_media_group.py index 7d97a665..fd8dbb25 100644 --- a/aiogram/methods/send_media_group.py +++ b/aiogram/methods/send_media_group.py @@ -1,19 +1,16 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from ..types import ( - InputFile, InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo, Message, ) -from .base import Request, TelegramMethod, prepare_input_media, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendMediaGroup(TelegramMethod[List[Message]]): @@ -24,6 +21,7 @@ class SendMediaGroup(TelegramMethod[List[Message]]): """ __returning__ = List[Message] + __api_method__ = "sendMediaGroup" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -33,18 +31,9 @@ class SendMediaGroup(TelegramMethod[List[Message]]): """Unique identifier for the target message thread (topic) of the forum; for forum supergroups only""" disable_notification: Optional[bool] = None """Sends messages `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent messages from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the messages are a reply, ID of the original message""" allow_sending_without_reply: Optional[bool] = None """Pass :code:`True` if the message should be sent even if the specified replied-to message is not found""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - prepare_parse_mode(bot, data["media"]) - - files: Dict[str, InputFile] = {} - prepare_input_media(data, files) - - return Request(method="sendMediaGroup", data=data, files=files) diff --git a/aiogram/methods/send_message.py b/aiogram/methods/send_message.py index a3c83bad..9b7dae7b 100644 --- a/aiogram/methods/send_message.py +++ b/aiogram/methods/send_message.py @@ -1,9 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from ..types import ( - UNSET, + UNSET_PARSE_MODE, ForceReply, InlineKeyboardMarkup, Message, @@ -11,10 +11,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_DISABLE_WEB_PAGE_PREVIEW, UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendMessage(TelegramMethod[Message]): @@ -25,6 +23,7 @@ class SendMessage(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendMessage" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -32,15 +31,15 @@ class SendMessage(TelegramMethod[Message]): """Text of the message to be sent, 1-4096 characters after entities parsing""" message_thread_id: Optional[int] = None """Unique identifier for the target message thread (topic) of the forum; for forum supergroups only""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """Mode for parsing entities in the message text. See `formatting options `_ for more details.""" entities: Optional[List[MessageEntity]] = None """A JSON-serialized list of special entities that appear in message text, which can be specified instead of *parse_mode*""" - disable_web_page_preview: Optional[bool] = None + disable_web_page_preview: Optional[bool] = UNSET_DISABLE_WEB_PAGE_PREVIEW """Disables link previews for links in this message""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -50,12 +49,3 @@ class SendMessage(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - prepare_parse_mode( - bot, data, parse_mode_property="parse_mode", entities_property="entities" - ) - - return Request(method="sendMessage", data=data) diff --git a/aiogram/methods/send_photo.py b/aiogram/methods/send_photo.py index 43a4c65a..236d8710 100644 --- a/aiogram/methods/send_photo.py +++ b/aiogram/methods/send_photo.py @@ -1,9 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from ..types import ( - UNSET, + UNSET_PARSE_MODE, ForceReply, InlineKeyboardMarkup, InputFile, @@ -12,10 +12,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendPhoto(TelegramMethod[Message]): @@ -26,6 +24,7 @@ class SendPhoto(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendPhoto" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -35,7 +34,7 @@ class SendPhoto(TelegramMethod[Message]): """Unique identifier for the target message thread (topic) of the forum; for forum supergroups only""" caption: Optional[str] = None """Photo caption (may also be used when resending photos by *file_id*), 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """Mode for parsing entities in the photo caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """A JSON-serialized list of special entities that appear in the caption, which can be specified instead of *parse_mode*""" @@ -43,7 +42,7 @@ class SendPhoto(TelegramMethod[Message]): """Pass :code:`True` if the photo needs to be covered with a spoiler animation""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -53,15 +52,3 @@ class SendPhoto(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict(exclude={"photo"}) - - prepare_parse_mode( - bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" - ) - - files: Dict[str, InputFile] = {} - prepare_file(data=data, files=files, name="photo", value=self.photo) - - return Request(method="sendPhoto", data=data, files=files) diff --git a/aiogram/methods/send_poll.py b/aiogram/methods/send_poll.py index be67fcda..fca3dc58 100644 --- a/aiogram/methods/send_poll.py +++ b/aiogram/methods/send_poll.py @@ -1,10 +1,10 @@ from __future__ import annotations import datetime -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from ..types import ( - UNSET, + UNSET_PARSE_MODE, ForceReply, InlineKeyboardMarkup, Message, @@ -12,10 +12,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendPoll(TelegramMethod[Message]): @@ -26,6 +24,7 @@ class SendPoll(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendPoll" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -45,7 +44,7 @@ class SendPoll(TelegramMethod[Message]): """0-based identifier of the correct answer option, required for polls in quiz mode""" explanation: Optional[str] = None """Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing""" - explanation_parse_mode: Optional[str] = UNSET + explanation_parse_mode: Optional[str] = UNSET_PARSE_MODE """Mode for parsing entities in the explanation. See `formatting options `_ for more details.""" explanation_entities: Optional[List[MessageEntity]] = None """A JSON-serialized list of special entities that appear in the poll explanation, which can be specified instead of *parse_mode*""" @@ -57,7 +56,7 @@ class SendPoll(TelegramMethod[Message]): """Pass :code:`True` if the poll needs to be immediately closed. This can be useful for poll preview.""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -67,15 +66,3 @@ class SendPoll(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - prepare_parse_mode( - bot, - data, - parse_mode_property="explanation_parse_mode", - entities_property="explanation_entities", - ) - - return Request(method="sendPoll", data=data) diff --git a/aiogram/methods/send_sticker.py b/aiogram/methods/send_sticker.py index e707cd2f..8429b105 100644 --- a/aiogram/methods/send_sticker.py +++ b/aiogram/methods/send_sticker.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import ( ForceReply, @@ -10,10 +10,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendSticker(TelegramMethod[Message]): @@ -24,6 +22,7 @@ class SendSticker(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendSticker" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -35,7 +34,7 @@ class SendSticker(TelegramMethod[Message]): """Emoji associated with the sticker; only for just uploaded stickers""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -45,11 +44,3 @@ class SendSticker(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict(exclude={"sticker"}) - - files: Dict[str, InputFile] = {} - prepare_file(data=data, files=files, name="sticker", value=self.sticker) - - return Request(method="sendSticker", data=data, files=files) diff --git a/aiogram/methods/send_venue.py b/aiogram/methods/send_venue.py index b9f3c464..d0859770 100644 --- a/aiogram/methods/send_venue.py +++ b/aiogram/methods/send_venue.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import ( ForceReply, @@ -9,10 +9,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendVenue(TelegramMethod[Message]): @@ -23,6 +21,7 @@ class SendVenue(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendVenue" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -46,7 +45,7 @@ class SendVenue(TelegramMethod[Message]): """Google Places type of the venue. (See `supported types `_.)""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -56,8 +55,3 @@ class SendVenue(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="sendVenue", data=data) diff --git a/aiogram/methods/send_video.py b/aiogram/methods/send_video.py index 8075b1fb..a894e335 100644 --- a/aiogram/methods/send_video.py +++ b/aiogram/methods/send_video.py @@ -1,9 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from ..types import ( - UNSET, + UNSET_PARSE_MODE, ForceReply, InlineKeyboardMarkup, InputFile, @@ -12,10 +12,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendVideo(TelegramMethod[Message]): @@ -26,6 +24,7 @@ class SendVideo(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendVideo" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -43,7 +42,7 @@ class SendVideo(TelegramMethod[Message]): """Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass 'attach://' if the thumbnail was uploaded using multipart/form-data under . :ref:`More information on Sending Files » `""" caption: Optional[str] = None """Video caption (may also be used when resending videos by *file_id*), 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """Mode for parsing entities in the video caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """A JSON-serialized list of special entities that appear in the caption, which can be specified instead of *parse_mode*""" @@ -53,7 +52,7 @@ class SendVideo(TelegramMethod[Message]): """Pass :code:`True` if the uploaded video is suitable for streaming""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -63,16 +62,3 @@ class SendVideo(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict(exclude={"video", "thumb"}) - - prepare_parse_mode( - bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" - ) - - files: Dict[str, InputFile] = {} - prepare_file(data=data, files=files, name="video", value=self.video) - prepare_file(data=data, files=files, name="thumbnail", value=self.thumbnail) - - return Request(method="sendVideo", data=data, files=files) diff --git a/aiogram/methods/send_video_note.py b/aiogram/methods/send_video_note.py index 3db3a142..761c91a2 100644 --- a/aiogram/methods/send_video_note.py +++ b/aiogram/methods/send_video_note.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import ( ForceReply, @@ -10,10 +10,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendVideoNote(TelegramMethod[Message]): @@ -24,6 +22,7 @@ class SendVideoNote(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendVideoNote" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -39,7 +38,7 @@ class SendVideoNote(TelegramMethod[Message]): """Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass 'attach://' if the thumbnail was uploaded using multipart/form-data under . :ref:`More information on Sending Files » `""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -49,12 +48,3 @@ class SendVideoNote(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict(exclude={"video_note", "thumb"}) - - files: Dict[str, InputFile] = {} - prepare_file(data=data, files=files, name="video_note", value=self.video_note) - prepare_file(data=data, files=files, name="thumbnail", value=self.thumbnail) - - return Request(method="sendVideoNote", data=data, files=files) diff --git a/aiogram/methods/send_voice.py b/aiogram/methods/send_voice.py index e9bc9a37..ae692ad6 100644 --- a/aiogram/methods/send_voice.py +++ b/aiogram/methods/send_voice.py @@ -1,9 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from ..types import ( - UNSET, + UNSET_PARSE_MODE, ForceReply, InlineKeyboardMarkup, InputFile, @@ -12,10 +12,8 @@ from ..types import ( ReplyKeyboardMarkup, ReplyKeyboardRemove, ) -from .base import Request, TelegramMethod, prepare_file, prepare_parse_mode - -if TYPE_CHECKING: - from ..client.bot import Bot +from ..types.base import UNSET_PROTECT_CONTENT +from .base import TelegramMethod class SendVoice(TelegramMethod[Message]): @@ -26,6 +24,7 @@ class SendVoice(TelegramMethod[Message]): """ __returning__ = Message + __api_method__ = "sendVoice" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -35,7 +34,7 @@ class SendVoice(TelegramMethod[Message]): """Unique identifier for the target message thread (topic) of the forum; for forum supergroups only""" caption: Optional[str] = None """Voice message caption, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """Mode for parsing entities in the voice message caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """A JSON-serialized list of special entities that appear in the caption, which can be specified instead of *parse_mode*""" @@ -43,7 +42,7 @@ class SendVoice(TelegramMethod[Message]): """Duration of the voice message in seconds""" disable_notification: Optional[bool] = None """Sends the message `silently `_. Users will receive a notification with no sound.""" - protect_content: Optional[bool] = None + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT """Protects the contents of the sent message from forwarding and saving""" reply_to_message_id: Optional[int] = None """If the message is a reply, ID of the original message""" @@ -53,15 +52,3 @@ class SendVoice(TelegramMethod[Message]): Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] ] = None """Additional interface options. A JSON-serialized object for an `inline keyboard `_, `custom reply keyboard `_, instructions to remove reply keyboard or to force a reply from the user.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict(exclude={"voice"}) - - prepare_parse_mode( - bot, data, parse_mode_property="parse_mode", entities_property="caption_entities" - ) - - files: Dict[str, InputFile] = {} - prepare_file(data=data, files=files, name="voice", value=self.voice) - - return Request(method="sendVoice", data=data, files=files) diff --git a/aiogram/methods/set_chat_administrator_custom_title.py b/aiogram/methods/set_chat_administrator_custom_title.py index 7522a237..edf79d8c 100644 --- a/aiogram/methods/set_chat_administrator_custom_title.py +++ b/aiogram/methods/set_chat_administrator_custom_title.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetChatAdministratorCustomTitle(TelegramMethod[bool]): @@ -16,6 +13,7 @@ class SetChatAdministratorCustomTitle(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setChatAdministratorCustomTitle" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" @@ -23,8 +21,3 @@ class SetChatAdministratorCustomTitle(TelegramMethod[bool]): """Unique identifier of the target user""" custom_title: str """New custom title for the administrator; 0-16 characters, emoji are not allowed""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setChatAdministratorCustomTitle", data=data) diff --git a/aiogram/methods/set_chat_description.py b/aiogram/methods/set_chat_description.py index a4014f79..05b51a69 100644 --- a/aiogram/methods/set_chat_description.py +++ b/aiogram/methods/set_chat_description.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetChatDescription(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class SetChatDescription(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setChatDescription" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" description: Optional[str] = None """New chat description, 0-255 characters""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setChatDescription", data=data) diff --git a/aiogram/methods/set_chat_menu_button.py b/aiogram/methods/set_chat_menu_button.py index 9a7caaf1..6eeb3a10 100644 --- a/aiogram/methods/set_chat_menu_button.py +++ b/aiogram/methods/set_chat_menu_button.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import MenuButtonCommands, MenuButtonDefault, MenuButtonWebApp -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetChatMenuButton(TelegramMethod[bool]): @@ -17,13 +14,9 @@ class SetChatMenuButton(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setChatMenuButton" chat_id: Optional[int] = None """Unique identifier for the target private chat. If not specified, default bot's menu button will be changed""" menu_button: Optional[Union[MenuButtonDefault, MenuButtonWebApp, MenuButtonCommands]] = None """A JSON-serialized object for the bot's new menu button. Defaults to :class:`aiogram.types.menu_button_default.MenuButtonDefault`""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setChatMenuButton", data=data) diff --git a/aiogram/methods/set_chat_permissions.py b/aiogram/methods/set_chat_permissions.py index c68b441d..af13ddb7 100644 --- a/aiogram/methods/set_chat_permissions.py +++ b/aiogram/methods/set_chat_permissions.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import ChatPermissions -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetChatPermissions(TelegramMethod[bool]): @@ -17,6 +14,7 @@ class SetChatPermissions(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setChatPermissions" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" @@ -24,8 +22,3 @@ class SetChatPermissions(TelegramMethod[bool]): """A JSON-serialized object for new default chat permissions""" use_independent_chat_permissions: Optional[bool] = None """Pass :code:`True` if chat permissions are set independently. Otherwise, the *can_send_other_messages* and *can_add_web_page_previews* permissions will imply the *can_send_messages*, *can_send_audios*, *can_send_documents*, *can_send_photos*, *can_send_videos*, *can_send_video_notes*, and *can_send_voice_notes* permissions; the *can_send_polls* permission will imply the *can_send_messages* permission.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setChatPermissions", data=data) diff --git a/aiogram/methods/set_chat_photo.py b/aiogram/methods/set_chat_photo.py index dc9aef57..ba7b8de3 100644 --- a/aiogram/methods/set_chat_photo.py +++ b/aiogram/methods/set_chat_photo.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union from ..types import InputFile -from .base import Request, TelegramMethod, prepare_file - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetChatPhoto(TelegramMethod[bool]): @@ -17,16 +14,9 @@ class SetChatPhoto(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setChatPhoto" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" photo: InputFile """New chat photo, uploaded using multipart/form-data""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict(exclude={"photo"}) - - files: Dict[str, InputFile] = {} - prepare_file(data=data, files=files, name="photo", value=self.photo) - - return Request(method="setChatPhoto", data=data, files=files) diff --git a/aiogram/methods/set_chat_sticker_set.py b/aiogram/methods/set_chat_sticker_set.py index 089083f6..a7f3d216 100644 --- a/aiogram/methods/set_chat_sticker_set.py +++ b/aiogram/methods/set_chat_sticker_set.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetChatStickerSet(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class SetChatStickerSet(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setChatStickerSet" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" sticker_set_name: str """Name of the sticker set to be set as the group sticker set""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setChatStickerSet", data=data) diff --git a/aiogram/methods/set_chat_title.py b/aiogram/methods/set_chat_title.py index edad33cc..07507d0f 100644 --- a/aiogram/methods/set_chat_title.py +++ b/aiogram/methods/set_chat_title.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetChatTitle(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class SetChatTitle(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setChatTitle" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" title: str """New chat title, 1-128 characters""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setChatTitle", data=data) diff --git a/aiogram/methods/set_custom_emoji_sticker_set_thumbnail.py b/aiogram/methods/set_custom_emoji_sticker_set_thumbnail.py index 35b047a2..10a4a267 100644 --- a/aiogram/methods/set_custom_emoji_sticker_set_thumbnail.py +++ b/aiogram/methods/set_custom_emoji_sticker_set_thumbnail.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetCustomEmojiStickerSetThumbnail(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class SetCustomEmojiStickerSetThumbnail(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setCustomEmojiStickerSetThumbnail" name: str """Sticker set name""" custom_emoji_id: Optional[str] = None """Custom emoji identifier of a sticker from the sticker set; pass an empty string to drop the thumbnail and use the first sticker as the thumbnail.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setCustomEmojiStickerSetThumbnail", data=data) diff --git a/aiogram/methods/set_game_score.py b/aiogram/methods/set_game_score.py index c3f8ce92..170988ec 100644 --- a/aiogram/methods/set_game_score.py +++ b/aiogram/methods/set_game_score.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import Message -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetGameScore(TelegramMethod[Union[Message, bool]]): @@ -17,6 +14,7 @@ class SetGameScore(TelegramMethod[Union[Message, bool]]): """ __returning__ = Union[Message, bool] + __api_method__ = "setGameScore" user_id: int """User identifier""" @@ -32,8 +30,3 @@ class SetGameScore(TelegramMethod[Union[Message, bool]]): """Required if *inline_message_id* is not specified. Identifier of the sent message""" inline_message_id: Optional[str] = None """Required if *chat_id* and *message_id* are not specified. Identifier of the inline message""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setGameScore", data=data) diff --git a/aiogram/methods/set_my_commands.py b/aiogram/methods/set_my_commands.py index 98e47aff..a62e7a84 100644 --- a/aiogram/methods/set_my_commands.py +++ b/aiogram/methods/set_my_commands.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional +from typing import TYPE_CHECKING, List, Optional from ..types import BotCommand, BotCommandScope -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetMyCommands(TelegramMethod[bool]): @@ -17,6 +14,7 @@ class SetMyCommands(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setMyCommands" commands: List[BotCommand] """A JSON-serialized list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified.""" @@ -24,8 +22,3 @@ class SetMyCommands(TelegramMethod[bool]): """A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to :class:`aiogram.types.bot_command_scope_default.BotCommandScopeDefault`.""" language_code: Optional[str] = None """A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setMyCommands", data=data) diff --git a/aiogram/methods/set_my_default_administrator_rights.py b/aiogram/methods/set_my_default_administrator_rights.py index f8177958..0b1468bc 100644 --- a/aiogram/methods/set_my_default_administrator_rights.py +++ b/aiogram/methods/set_my_default_administrator_rights.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional from ..types import ChatAdministratorRights -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetMyDefaultAdministratorRights(TelegramMethod[bool]): @@ -17,13 +14,9 @@ class SetMyDefaultAdministratorRights(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setMyDefaultAdministratorRights" rights: Optional[ChatAdministratorRights] = None """A JSON-serialized object describing new default administrator rights. If not specified, the default administrator rights will be cleared.""" for_channels: Optional[bool] = None """Pass :code:`True` to change the default administrator rights of the bot in channels. Otherwise, the default administrator rights of the bot for groups and supergroups will be changed.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setMyDefaultAdministratorRights", data=data) diff --git a/aiogram/methods/set_my_description.py b/aiogram/methods/set_my_description.py index a05440ef..2af2ed44 100644 --- a/aiogram/methods/set_my_description.py +++ b/aiogram/methods/set_my_description.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetMyDescription(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class SetMyDescription(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setMyDescription" description: Optional[str] = None """New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.""" language_code: Optional[str] = None """A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for whose language there is no dedicated description.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setMyDescription", data=data) diff --git a/aiogram/methods/set_my_short_description.py b/aiogram/methods/set_my_short_description.py index c759d1ed..19e5b254 100644 --- a/aiogram/methods/set_my_short_description.py +++ b/aiogram/methods/set_my_short_description.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetMyShortDescription(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class SetMyShortDescription(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setMyShortDescription" short_description: Optional[str] = None """New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language.""" language_code: Optional[str] = None """A two-letter ISO 639-1 language code. If empty, the short description will be applied to all users for whose language there is no dedicated short description.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setMyShortDescription", data=data) diff --git a/aiogram/methods/set_passport_data_errors.py b/aiogram/methods/set_passport_data_errors.py index 1f781b08..ae127d2b 100644 --- a/aiogram/methods/set_passport_data_errors.py +++ b/aiogram/methods/set_passport_data_errors.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List +from typing import TYPE_CHECKING, List from ..types import PassportElementError -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetPassportDataErrors(TelegramMethod[bool]): @@ -18,13 +15,9 @@ class SetPassportDataErrors(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setPassportDataErrors" user_id: int """User identifier""" errors: List[PassportElementError] """A JSON-serialized array describing the errors""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setPassportDataErrors", data=data) diff --git a/aiogram/methods/set_sticker_emoji_list.py b/aiogram/methods/set_sticker_emoji_list.py index d6ef31f2..f23033c7 100644 --- a/aiogram/methods/set_sticker_emoji_list.py +++ b/aiogram/methods/set_sticker_emoji_list.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List +from typing import TYPE_CHECKING, List -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetStickerEmojiList(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class SetStickerEmojiList(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setStickerEmojiList" sticker: str """File identifier of the sticker""" emoji_list: List[str] """A JSON-serialized list of 1-20 emoji associated with the sticker""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setStickerEmojiList", data=data) diff --git a/aiogram/methods/set_sticker_keywords.py b/aiogram/methods/set_sticker_keywords.py index 2fd5b1c4..0ebef118 100644 --- a/aiogram/methods/set_sticker_keywords.py +++ b/aiogram/methods/set_sticker_keywords.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional +from typing import TYPE_CHECKING, List, Optional -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetStickerKeywords(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class SetStickerKeywords(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setStickerKeywords" sticker: str """File identifier of the sticker""" keywords: Optional[List[str]] = None """A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setStickerKeywords", data=data) diff --git a/aiogram/methods/set_sticker_mask_position.py b/aiogram/methods/set_sticker_mask_position.py index 95aa8ca3..f3147f2d 100644 --- a/aiogram/methods/set_sticker_mask_position.py +++ b/aiogram/methods/set_sticker_mask_position.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Optional from ..types import MaskPosition -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetStickerMaskPosition(TelegramMethod[bool]): @@ -17,13 +14,9 @@ class SetStickerMaskPosition(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setStickerMaskPosition" sticker: str """File identifier of the sticker""" mask_position: Optional[MaskPosition] = None """A JSON-serialized object with the position where the mask should be placed on faces. Omit the parameter to remove the mask position.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setStickerMaskPosition", data=data) diff --git a/aiogram/methods/set_sticker_position_in_set.py b/aiogram/methods/set_sticker_position_in_set.py index c607c0d5..ed5792ae 100644 --- a/aiogram/methods/set_sticker_position_in_set.py +++ b/aiogram/methods/set_sticker_position_in_set.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetStickerPositionInSet(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class SetStickerPositionInSet(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setStickerPositionInSet" sticker: str """File identifier of the sticker""" position: int """New sticker position in the set, zero-based""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setStickerPositionInSet", data=data) diff --git a/aiogram/methods/set_sticker_set_thumbnail.py b/aiogram/methods/set_sticker_set_thumbnail.py index 829aa192..7da1c397 100644 --- a/aiogram/methods/set_sticker_set_thumbnail.py +++ b/aiogram/methods/set_sticker_set_thumbnail.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import InputFile -from .base import Request, TelegramMethod, prepare_file - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetStickerSetThumbnail(TelegramMethod[bool]): @@ -17,6 +14,7 @@ class SetStickerSetThumbnail(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setStickerSetThumbnail" name: str """Sticker set name""" @@ -24,11 +22,3 @@ class SetStickerSetThumbnail(TelegramMethod[bool]): """User identifier of the sticker set owner""" thumbnail: Optional[Union[InputFile, str]] = None """A **.WEBP** or **.PNG** image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a **.TGS** animation with a thumbnail up to 32 kilobytes in size (see `https://core.telegram.org/stickers#animated-sticker-requirements `_`https://core.telegram.org/stickers#animated-sticker-requirements `_ for animated sticker technical requirements), or a **WEBM** video with the thumbnail up to 32 kilobytes in size; see `https://core.telegram.org/stickers#video-sticker-requirements `_`https://core.telegram.org/stickers#video-sticker-requirements `_ for video sticker technical requirements. Pass a *file_id* as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. :ref:`More information on Sending Files » `. Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - files: Dict[str, InputFile] = {} - prepare_file("thumbnail", value=self.thumbnail, data=data, files=files) - - return Request(method="setStickerSetThumbnail", data=data) diff --git a/aiogram/methods/set_sticker_set_title.py b/aiogram/methods/set_sticker_set_title.py index e699c082..978432ff 100644 --- a/aiogram/methods/set_sticker_set_title.py +++ b/aiogram/methods/set_sticker_set_title.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetStickerSetTitle(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class SetStickerSetTitle(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setStickerSetTitle" name: str """Sticker set name""" title: str """Sticker set title, 1-64 characters""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="setStickerSetTitle", data=data) diff --git a/aiogram/methods/set_webhook.py b/aiogram/methods/set_webhook.py index 34c14aaf..6e63a75a 100644 --- a/aiogram/methods/set_webhook.py +++ b/aiogram/methods/set_webhook.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, List, Optional +from typing import TYPE_CHECKING, List, Optional from ..types import InputFile -from .base import Request, TelegramMethod, prepare_file - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class SetWebhook(TelegramMethod[bool]): @@ -27,6 +24,7 @@ class SetWebhook(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "setWebhook" url: str """HTTPS URL to send updates to. Use an empty string to remove webhook integration""" @@ -42,11 +40,3 @@ class SetWebhook(TelegramMethod[bool]): """Pass :code:`True` to drop all pending updates""" secret_token: Optional[str] = None """A secret token to be sent in a header 'X-Telegram-Bot-Api-Secret-Token' in every webhook request, 1-256 characters. Only characters :code:`A-Z`, :code:`a-z`, :code:`0-9`, :code:`_` and :code:`-` are allowed. The header is useful to ensure that the request comes from a webhook set by you.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict(exclude={"certificate"}) - - files: Dict[str, InputFile] = {} - prepare_file(data=data, files=files, name="certificate", value=self.certificate) - - return Request(method="setWebhook", data=data, files=files) diff --git a/aiogram/methods/stop_message_live_location.py b/aiogram/methods/stop_message_live_location.py index 50297930..8a16f586 100644 --- a/aiogram/methods/stop_message_live_location.py +++ b/aiogram/methods/stop_message_live_location.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import InlineKeyboardMarkup, Message -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class StopMessageLiveLocation(TelegramMethod[Union[Message, bool]]): @@ -17,6 +14,7 @@ class StopMessageLiveLocation(TelegramMethod[Union[Message, bool]]): """ __returning__ = Union[Message, bool] + __api_method__ = "stopMessageLiveLocation" chat_id: Optional[Union[int, str]] = None """Required if *inline_message_id* is not specified. Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -26,8 +24,3 @@ class StopMessageLiveLocation(TelegramMethod[Union[Message, bool]]): """Required if *chat_id* and *message_id* are not specified. Identifier of the inline message""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for a new `inline keyboard `_.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="stopMessageLiveLocation", data=data) diff --git a/aiogram/methods/stop_poll.py b/aiogram/methods/stop_poll.py index 92662285..19ef26ac 100644 --- a/aiogram/methods/stop_poll.py +++ b/aiogram/methods/stop_poll.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from ..types import InlineKeyboardMarkup, Poll -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class StopPoll(TelegramMethod[Poll]): @@ -17,6 +14,7 @@ class StopPoll(TelegramMethod[Poll]): """ __returning__ = Poll + __api_method__ = "stopPoll" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" @@ -24,8 +22,3 @@ class StopPoll(TelegramMethod[Poll]): """Identifier of the original message with the poll""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for a new message `inline keyboard `_.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="stopPoll", data=data) diff --git a/aiogram/methods/unban_chat_member.py b/aiogram/methods/unban_chat_member.py index 3fce083b..768eea22 100644 --- a/aiogram/methods/unban_chat_member.py +++ b/aiogram/methods/unban_chat_member.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class UnbanChatMember(TelegramMethod[bool]): @@ -16,6 +13,7 @@ class UnbanChatMember(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "unbanChatMember" chat_id: Union[int, str] """Unique identifier for the target group or username of the target supergroup or channel (in the format :code:`@channelusername`)""" @@ -23,8 +21,3 @@ class UnbanChatMember(TelegramMethod[bool]): """Unique identifier of the target user""" only_if_banned: Optional[bool] = None """Do nothing if the user is not banned""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="unbanChatMember", data=data) diff --git a/aiogram/methods/unban_chat_sender_chat.py b/aiogram/methods/unban_chat_sender_chat.py index 9da79e1f..fbd3f1d3 100644 --- a/aiogram/methods/unban_chat_sender_chat.py +++ b/aiogram/methods/unban_chat_sender_chat.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class UnbanChatSenderChat(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class UnbanChatSenderChat(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "unbanChatSenderChat" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" sender_chat_id: int """Unique identifier of the target sender chat""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="unbanChatSenderChat", data=data) diff --git a/aiogram/methods/unhide_general_forum_topic.py b/aiogram/methods/unhide_general_forum_topic.py index 2ee341aa..82524758 100644 --- a/aiogram/methods/unhide_general_forum_topic.py +++ b/aiogram/methods/unhide_general_forum_topic.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class UnhideGeneralForumTopic(TelegramMethod[bool]): @@ -16,11 +13,7 @@ class UnhideGeneralForumTopic(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "unhideGeneralForumTopic" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="unhideGeneralForumTopic", data=data) diff --git a/aiogram/methods/unpin_all_chat_messages.py b/aiogram/methods/unpin_all_chat_messages.py index 99a3a1f2..f8566e33 100644 --- a/aiogram/methods/unpin_all_chat_messages.py +++ b/aiogram/methods/unpin_all_chat_messages.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class UnpinAllChatMessages(TelegramMethod[bool]): @@ -16,11 +13,7 @@ class UnpinAllChatMessages(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "unpinAllChatMessages" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="unpinAllChatMessages", data=data) diff --git a/aiogram/methods/unpin_all_forum_topic_messages.py b/aiogram/methods/unpin_all_forum_topic_messages.py index 6a94c218..6b735e98 100644 --- a/aiogram/methods/unpin_all_forum_topic_messages.py +++ b/aiogram/methods/unpin_all_forum_topic_messages.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class UnpinAllForumTopicMessages(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class UnpinAllForumTopicMessages(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "unpinAllForumTopicMessages" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)""" message_thread_id: int """Unique identifier for the target message thread of the forum topic""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="unpinAllForumTopicMessages", data=data) diff --git a/aiogram/methods/unpin_chat_message.py b/aiogram/methods/unpin_chat_message.py index 098dba48..0d5d2b0a 100644 --- a/aiogram/methods/unpin_chat_message.py +++ b/aiogram/methods/unpin_chat_message.py @@ -1,11 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Optional, Union -from .base import Request, TelegramMethod - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class UnpinChatMessage(TelegramMethod[bool]): @@ -16,13 +13,9 @@ class UnpinChatMessage(TelegramMethod[bool]): """ __returning__ = bool + __api_method__ = "unpinChatMessage" chat_id: Union[int, str] """Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)""" message_id: Optional[int] = None """Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned.""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict() - - return Request(method="unpinChatMessage", data=data) diff --git a/aiogram/methods/upload_sticker_file.py b/aiogram/methods/upload_sticker_file.py index d0fcbc44..2194e35f 100644 --- a/aiogram/methods/upload_sticker_file.py +++ b/aiogram/methods/upload_sticker_file.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING from ..types import File, InputFile -from .base import Request, TelegramMethod, prepare_file - -if TYPE_CHECKING: - from ..client.bot import Bot +from .base import TelegramMethod class UploadStickerFile(TelegramMethod[File]): @@ -17,6 +14,7 @@ class UploadStickerFile(TelegramMethod[File]): """ __returning__ = File + __api_method__ = "uploadStickerFile" user_id: int """User identifier of sticker file owner""" @@ -24,11 +22,3 @@ class UploadStickerFile(TelegramMethod[File]): """A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. See `https://core.telegram.org/stickers `_`https://core.telegram.org/stickers `_ for technical requirements. :ref:`More information on Sending Files » `""" sticker_format: str """Format of the sticker, must be one of 'static', 'animated', 'video'""" - - def build_request(self, bot: Bot) -> Request: - data: Dict[str, Any] = self.dict(exclude={"sticker"}) - - files: Dict[str, InputFile] = {} - prepare_file(data=data, files=files, name="sticker", value=self.sticker) - - return Request(method="uploadStickerFile", data=data, files=files) diff --git a/aiogram/types/__init__.py b/aiogram/types/__init__.py index 3fc98953..85fd9338 100644 --- a/aiogram/types/__init__.py +++ b/aiogram/types/__init__.py @@ -2,7 +2,7 @@ from typing import Optional from .animation import Animation from .audio import Audio -from .base import UNSET, TelegramObject +from .base import UNSET_PARSE_MODE, TelegramObject from .bot_command import BotCommand from .bot_command_scope import BotCommandScope from .bot_command_scope_all_chat_administrators import ( @@ -295,7 +295,7 @@ __all__ = ( "StickerSet", "SuccessfulPayment", "TelegramObject", - "UNSET", + "UNSET_PARSE_MODE", "URLInputFile", "Update", "User", diff --git a/aiogram/types/base.py b/aiogram/types/base.py index 0b5d08ad..707e328c 100644 --- a/aiogram/types/base.py +++ b/aiogram/types/base.py @@ -23,6 +23,8 @@ class MutableTelegramObject(TelegramObject): allow_mutation = True -UNSET: Any = ( - sentinel.UNSET -) # special sentinel object which used in sutuation when None might be a useful value +# special sentinel object which used in situation when None might be a useful value +UNSET_PARSE_MODE: Any = sentinel.UNSET_PARSE_MODE +UNSET_DISABLE_WEB_PAGE_PREVIEW = sentinel.UNSET_DISABLE_WEB_PAGE_PREVIEW +UNSET_PROTECT_CONTENT = sentinel.UNSET_PROTECT_CONTENT +UNSET_TYPE = type(sentinel.DEFAULT) diff --git a/aiogram/types/inline_query_result_audio.py b/aiogram/types/inline_query_result_audio.py index d217d246..3b830fc8 100644 --- a/aiogram/types/inline_query_result_audio.py +++ b/aiogram/types/inline_query_result_audio.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -32,7 +32,7 @@ class InlineQueryResultAudio(InlineQueryResult): """Title""" caption: Optional[str] = None """*Optional*. Caption, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the audio caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/inline_query_result_cached_audio.py b/aiogram/types/inline_query_result_cached_audio.py index f630ee51..8358f723 100644 --- a/aiogram/types/inline_query_result_cached_audio.py +++ b/aiogram/types/inline_query_result_cached_audio.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -30,7 +30,7 @@ class InlineQueryResultCachedAudio(InlineQueryResult): """A valid file identifier for the audio file""" caption: Optional[str] = None """*Optional*. Caption, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the audio caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/inline_query_result_cached_document.py b/aiogram/types/inline_query_result_cached_document.py index 34ca1238..5513971f 100644 --- a/aiogram/types/inline_query_result_cached_document.py +++ b/aiogram/types/inline_query_result_cached_document.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -34,7 +34,7 @@ class InlineQueryResultCachedDocument(InlineQueryResult): """*Optional*. Short description of the result""" caption: Optional[str] = None """*Optional*. Caption of the document to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the document caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/inline_query_result_cached_gif.py b/aiogram/types/inline_query_result_cached_gif.py index 3bb77f44..7aa5c535 100644 --- a/aiogram/types/inline_query_result_cached_gif.py +++ b/aiogram/types/inline_query_result_cached_gif.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -31,7 +31,7 @@ class InlineQueryResultCachedGif(InlineQueryResult): """*Optional*. Title for the result""" caption: Optional[str] = None """*Optional*. Caption of the GIF file to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/inline_query_result_cached_mpeg4_gif.py b/aiogram/types/inline_query_result_cached_mpeg4_gif.py index 5175bc8c..ab7a2a9b 100644 --- a/aiogram/types/inline_query_result_cached_mpeg4_gif.py +++ b/aiogram/types/inline_query_result_cached_mpeg4_gif.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -31,7 +31,7 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult): """*Optional*. Title for the result""" caption: Optional[str] = None """*Optional*. Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/inline_query_result_cached_photo.py b/aiogram/types/inline_query_result_cached_photo.py index 09a9f5b0..fc892826 100644 --- a/aiogram/types/inline_query_result_cached_photo.py +++ b/aiogram/types/inline_query_result_cached_photo.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -33,7 +33,7 @@ class InlineQueryResultCachedPhoto(InlineQueryResult): """*Optional*. Short description of the result""" caption: Optional[str] = None """*Optional*. Caption of the photo to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the photo caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/inline_query_result_cached_video.py b/aiogram/types/inline_query_result_cached_video.py index 10720c80..acda3962 100644 --- a/aiogram/types/inline_query_result_cached_video.py +++ b/aiogram/types/inline_query_result_cached_video.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -33,7 +33,7 @@ class InlineQueryResultCachedVideo(InlineQueryResult): """*Optional*. Short description of the result""" caption: Optional[str] = None """*Optional*. Caption of the video to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the video caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/inline_query_result_cached_voice.py b/aiogram/types/inline_query_result_cached_voice.py index 23595edf..3f03b2fe 100644 --- a/aiogram/types/inline_query_result_cached_voice.py +++ b/aiogram/types/inline_query_result_cached_voice.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -32,7 +32,7 @@ class InlineQueryResultCachedVoice(InlineQueryResult): """Voice message title""" caption: Optional[str] = None """*Optional*. Caption, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the voice message caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/inline_query_result_document.py b/aiogram/types/inline_query_result_document.py index d1c577cf..7698e4c6 100644 --- a/aiogram/types/inline_query_result_document.py +++ b/aiogram/types/inline_query_result_document.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -34,7 +34,7 @@ class InlineQueryResultDocument(InlineQueryResult): """MIME type of the content of the file, either 'application/pdf' or 'application/zip'""" caption: Optional[str] = None """*Optional*. Caption of the document to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the document caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/inline_query_result_gif.py b/aiogram/types/inline_query_result_gif.py index ac4e0c05..b38cfa1a 100644 --- a/aiogram/types/inline_query_result_gif.py +++ b/aiogram/types/inline_query_result_gif.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -41,7 +41,7 @@ class InlineQueryResultGif(InlineQueryResult): """*Optional*. Title for the result""" caption: Optional[str] = None """*Optional*. Caption of the GIF file to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/inline_query_result_mpeg4_gif.py b/aiogram/types/inline_query_result_mpeg4_gif.py index 260ae839..44a61fee 100644 --- a/aiogram/types/inline_query_result_mpeg4_gif.py +++ b/aiogram/types/inline_query_result_mpeg4_gif.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -41,7 +41,7 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): """*Optional*. Title for the result""" caption: Optional[str] = None """*Optional*. Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/inline_query_result_photo.py b/aiogram/types/inline_query_result_photo.py index 6ef09fc3..6ed85276 100644 --- a/aiogram/types/inline_query_result_photo.py +++ b/aiogram/types/inline_query_result_photo.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -39,7 +39,7 @@ class InlineQueryResultPhoto(InlineQueryResult): """*Optional*. Short description of the result""" caption: Optional[str] = None """*Optional*. Caption of the photo to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the photo caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/inline_query_result_video.py b/aiogram/types/inline_query_result_video.py index f35c55cb..ba14d066 100644 --- a/aiogram/types/inline_query_result_video.py +++ b/aiogram/types/inline_query_result_video.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -37,7 +37,7 @@ class InlineQueryResultVideo(InlineQueryResult): """Title for the result""" caption: Optional[str] = None """*Optional*. Caption of the video to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the video caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/inline_query_result_voice.py b/aiogram/types/inline_query_result_voice.py index ea5230b2..7de1f6cf 100644 --- a/aiogram/types/inline_query_result_voice.py +++ b/aiogram/types/inline_query_result_voice.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import Field from ..enums import InlineQueryResultType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .inline_query_result import InlineQueryResult if TYPE_CHECKING: @@ -32,7 +32,7 @@ class InlineQueryResultVoice(InlineQueryResult): """Recording title""" caption: Optional[str] = None """*Optional*. Caption, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the voice message caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/input_media_animation.py b/aiogram/types/input_media_animation.py index 9b94f0c1..eabc4b5e 100644 --- a/aiogram/types/input_media_animation.py +++ b/aiogram/types/input_media_animation.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional, Union from pydantic import Field from ..enums import InputMediaType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .input_media import InputMedia if TYPE_CHECKING: @@ -28,7 +28,7 @@ class InputMediaAnimation(InputMedia): """*Optional*. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass 'attach://' if the thumbnail was uploaded using multipart/form-data under . :ref:`More information on Sending Files » `""" caption: Optional[str] = None """*Optional*. Caption of the animation to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the animation caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/input_media_audio.py b/aiogram/types/input_media_audio.py index 3d149dc8..8de62a6f 100644 --- a/aiogram/types/input_media_audio.py +++ b/aiogram/types/input_media_audio.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional, Union from pydantic import Field from ..enums import InputMediaType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .input_media import InputMedia if TYPE_CHECKING: @@ -28,7 +28,7 @@ class InputMediaAudio(InputMedia): """*Optional*. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass 'attach://' if the thumbnail was uploaded using multipart/form-data under . :ref:`More information on Sending Files » `""" caption: Optional[str] = None """*Optional*. Caption of the audio to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the audio caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/input_media_document.py b/aiogram/types/input_media_document.py index 6eb6acfa..9ef4d52f 100644 --- a/aiogram/types/input_media_document.py +++ b/aiogram/types/input_media_document.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional, Union from pydantic import Field from ..enums import InputMediaType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .input_media import InputMedia if TYPE_CHECKING: @@ -28,7 +28,7 @@ class InputMediaDocument(InputMedia): """*Optional*. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass 'attach://' if the thumbnail was uploaded using multipart/form-data under . :ref:`More information on Sending Files » `""" caption: Optional[str] = None """*Optional*. Caption of the document to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the document caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/input_media_photo.py b/aiogram/types/input_media_photo.py index 1b6f70dd..0f9500e8 100644 --- a/aiogram/types/input_media_photo.py +++ b/aiogram/types/input_media_photo.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional, Union from pydantic import Field from ..enums import InputMediaType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .input_media import InputMedia if TYPE_CHECKING: @@ -26,7 +26,7 @@ class InputMediaPhoto(InputMedia): """File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass 'attach://' to upload a new one using multipart/form-data under name. :ref:`More information on Sending Files » `""" caption: Optional[str] = None """*Optional*. Caption of the photo to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the photo caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/input_media_video.py b/aiogram/types/input_media_video.py index 21379d5f..89d4df91 100644 --- a/aiogram/types/input_media_video.py +++ b/aiogram/types/input_media_video.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, List, Optional, Union from pydantic import Field from ..enums import InputMediaType -from .base import UNSET +from .base import UNSET_PARSE_MODE from .input_media import InputMedia if TYPE_CHECKING: @@ -28,7 +28,7 @@ class InputMediaVideo(InputMedia): """*Optional*. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass 'attach://' if the thumbnail was uploaded using multipart/form-data under . :ref:`More information on Sending Files » `""" caption: Optional[str] = None """*Optional*. Caption of the video to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the video caption. See `formatting options `_ for more details.""" caption_entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in the caption, which can be specified instead of *parse_mode*""" diff --git a/aiogram/types/input_text_message_content.py b/aiogram/types/input_text_message_content.py index 2b502765..697696ce 100644 --- a/aiogram/types/input_text_message_content.py +++ b/aiogram/types/input_text_message_content.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, List, Optional -from .base import UNSET +from .base import UNSET_DISABLE_WEB_PAGE_PREVIEW, UNSET_PARSE_MODE from .input_message_content import InputMessageContent if TYPE_CHECKING: @@ -18,9 +18,9 @@ class InputTextMessageContent(InputMessageContent): message_text: str """Text of the message to be sent, 1-4096 characters""" - parse_mode: Optional[str] = UNSET + parse_mode: Optional[str] = UNSET_PARSE_MODE """*Optional*. Mode for parsing entities in the message text. See `formatting options `_ for more details.""" entities: Optional[List[MessageEntity]] = None """*Optional*. List of special entities that appear in message text, which can be specified instead of *parse_mode*""" - disable_web_page_preview: Optional[bool] = None + disable_web_page_preview: Optional[bool] = UNSET_DISABLE_WEB_PAGE_PREVIEW """*Optional*. Disables link previews for links in the sent message""" diff --git a/aiogram/types/message.py b/aiogram/types/message.py index bd18740a..c74ccb97 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -12,7 +12,12 @@ from aiogram.utils.text_decorations import ( ) from ..enums import ContentType -from .base import UNSET, TelegramObject +from .base import ( + UNSET_DISABLE_WEB_PAGE_PREVIEW, + UNSET_PARSE_MODE, + UNSET_PROTECT_CONTENT, + TelegramObject, +) if TYPE_CHECKING: from ..methods import ( @@ -350,11 +355,11 @@ class Message(TelegramObject): height: Optional[int] = None, thumbnail: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, has_spoiler: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -421,11 +426,11 @@ class Message(TelegramObject): height: Optional[int] = None, thumbnail: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, has_spoiler: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -489,14 +494,14 @@ class Message(TelegramObject): self, audio: Union[InputFile, str], caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, duration: Optional[int] = None, performer: Optional[str] = None, title: Optional[str] = None, thumbnail: Optional[Union[InputFile, str]] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -558,14 +563,14 @@ class Message(TelegramObject): self, audio: Union[InputFile, str], caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, duration: Optional[int] = None, performer: Optional[str] = None, title: Optional[str] = None, thumbnail: Optional[Union[InputFile, str]] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -631,7 +636,7 @@ class Message(TelegramObject): last_name: Optional[str] = None, vcard: Optional[str] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -687,7 +692,7 @@ class Message(TelegramObject): last_name: Optional[str] = None, vcard: Optional[str] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -742,11 +747,11 @@ class Message(TelegramObject): document: Union[InputFile, str], thumbnail: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, disable_content_type_detection: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -804,11 +809,11 @@ class Message(TelegramObject): document: Union[InputFile, str], thumbnail: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, disable_content_type_detection: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -866,7 +871,7 @@ class Message(TelegramObject): self, game_short_name: str, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, **kwargs: Any, @@ -911,7 +916,7 @@ class Message(TelegramObject): self, game_short_name: str, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, @@ -977,7 +982,7 @@ class Message(TelegramObject): send_email_to_provider: Optional[bool] = None, is_flexible: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, **kwargs: Any, @@ -1082,7 +1087,7 @@ class Message(TelegramObject): send_email_to_provider: Optional[bool] = None, is_flexible: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, @@ -1173,7 +1178,7 @@ class Message(TelegramObject): heading: Optional[int] = None, proximity_alert_radius: Optional[int] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -1235,7 +1240,7 @@ class Message(TelegramObject): heading: Optional[int] = None, proximity_alert_radius: Optional[int] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -1293,7 +1298,7 @@ class Message(TelegramObject): self, media: List[Union[InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo]], disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, **kwargs: Any, ) -> SendMediaGroup: @@ -1335,7 +1340,7 @@ class Message(TelegramObject): self, media: List[Union[InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo]], disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, **kwargs: Any, @@ -1377,11 +1382,11 @@ class Message(TelegramObject): def reply( self, text: str, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, entities: Optional[List[MessageEntity]] = None, - disable_web_page_preview: Optional[bool] = None, + disable_web_page_preview: Optional[bool] = UNSET_DISABLE_WEB_PAGE_PREVIEW, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -1433,11 +1438,11 @@ class Message(TelegramObject): def answer( self, text: str, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, entities: Optional[List[MessageEntity]] = None, - disable_web_page_preview: Optional[bool] = None, + disable_web_page_preview: Optional[bool] = UNSET_DISABLE_WEB_PAGE_PREVIEW, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -1491,11 +1496,11 @@ class Message(TelegramObject): self, photo: Union[InputFile, str], caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, has_spoiler: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -1550,11 +1555,11 @@ class Message(TelegramObject): self, photo: Union[InputFile, str], caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, has_spoiler: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -1615,13 +1620,13 @@ class Message(TelegramObject): allows_multiple_answers: Optional[bool] = None, correct_option_id: Optional[int] = None, explanation: Optional[str] = None, - explanation_parse_mode: Optional[str] = UNSET, + explanation_parse_mode: Optional[str] = UNSET_PARSE_MODE, explanation_entities: Optional[List[MessageEntity]] = None, open_period: Optional[int] = None, close_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None, is_closed: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -1695,13 +1700,13 @@ class Message(TelegramObject): allows_multiple_answers: Optional[bool] = None, correct_option_id: Optional[int] = None, explanation: Optional[str] = None, - explanation_parse_mode: Optional[str] = UNSET, + explanation_parse_mode: Optional[str] = UNSET_PARSE_MODE, explanation_entities: Optional[List[MessageEntity]] = None, open_period: Optional[int] = None, close_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None, is_closed: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -1771,7 +1776,7 @@ class Message(TelegramObject): self, emoji: Optional[str] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -1818,7 +1823,7 @@ class Message(TelegramObject): self, emoji: Optional[str] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -1867,7 +1872,7 @@ class Message(TelegramObject): sticker: Union[InputFile, str], emoji: Optional[str] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -1917,7 +1922,7 @@ class Message(TelegramObject): sticker: Union[InputFile, str], emoji: Optional[str] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -1974,7 +1979,7 @@ class Message(TelegramObject): google_place_id: Optional[str] = None, google_place_type: Optional[str] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -2042,7 +2047,7 @@ class Message(TelegramObject): google_place_id: Optional[str] = None, google_place_type: Optional[str] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2108,12 +2113,12 @@ class Message(TelegramObject): height: Optional[int] = None, thumbnail: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, has_spoiler: Optional[bool] = None, supports_streaming: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -2182,12 +2187,12 @@ class Message(TelegramObject): height: Optional[int] = None, thumbnail: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, has_spoiler: Optional[bool] = None, supports_streaming: Optional[bool] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2256,7 +2261,7 @@ class Message(TelegramObject): length: Optional[int] = None, thumbnail: Optional[Union[InputFile, str]] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -2312,7 +2317,7 @@ class Message(TelegramObject): length: Optional[int] = None, thumbnail: Optional[Union[InputFile, str]] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2366,11 +2371,11 @@ class Message(TelegramObject): self, voice: Union[InputFile, str], caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, duration: Optional[int] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] @@ -2425,11 +2430,11 @@ class Message(TelegramObject): self, voice: Union[InputFile, str], caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, duration: Optional[int] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2624,10 +2629,10 @@ class Message(TelegramObject): chat_id: Union[int, str], message_thread_id: Optional[int] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[ @@ -2683,9 +2688,9 @@ class Message(TelegramObject): self, text: str, inline_message_id: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, entities: Optional[List[MessageEntity]] = None, - disable_web_page_preview: Optional[bool] = None, + disable_web_page_preview: Optional[bool] = UNSET_DISABLE_WEB_PAGE_PREVIEW, reply_markup: Optional[InlineKeyboardMarkup] = None, **kwargs: Any, ) -> EditMessageText: @@ -2730,7 +2735,7 @@ class Message(TelegramObject): chat_id: Union[int, str], message_thread_id: Optional[int] = None, disable_notification: Optional[bool] = None, - protect_content: Optional[bool] = None, + protect_content: Optional[bool] = UNSET_PROTECT_CONTENT, **kwargs: Any, ) -> ForwardMessage: """ @@ -2926,7 +2931,7 @@ class Message(TelegramObject): self, inline_message_id: Optional[str] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = UNSET, + parse_mode: Optional[str] = UNSET_PARSE_MODE, caption_entities: Optional[List[MessageEntity]] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, **kwargs: Any, diff --git a/aiogram/webhook/aiohttp_server.py b/aiogram/webhook/aiohttp_server.py index c5e5f661..4406f1ff 100644 --- a/aiogram/webhook/aiohttp_server.py +++ b/aiogram/webhook/aiohttp_server.py @@ -10,8 +10,9 @@ from aiohttp.typedefs import Handler from aiohttp.web_middlewares import middleware from aiogram import Bot, Dispatcher, loggers -from aiogram.methods import Request, TelegramMethod -from aiogram.types import UNSET +from aiogram.methods import TelegramMethod +from aiogram.methods.base import TelegramType +from aiogram.types import InputFile from aiogram.webhook.security import IPFilter @@ -143,7 +144,9 @@ class BaseRequestHandler(ABC): ) return web.json_response({}, dumps=bot.session.json_dumps) - def _build_response_writer(self, bot: Bot, result: Optional[Request]) -> MultipartWriter: + def _build_response_writer( + self, bot: Bot, result: Optional[TelegramMethod[TelegramType]] + ) -> MultipartWriter: writer = MultipartWriter( "form-data", boundary=f"webhookBoundary{secrets.token_urlsafe(16)}", @@ -151,26 +154,29 @@ class BaseRequestHandler(ABC): if not result: return writer - payload = writer.append(result.method) + payload = writer.append(result.__api_method__) payload.set_content_disposition("form-data", name="method") - for key, value in result.data.items(): - if value is None or value is UNSET: + files: Dict[str, InputFile] = {} + for key, value in result.dict().items(): + value = bot.session.prepare_value(value, bot=bot, files=files) + if not value: continue - payload = writer.append(bot.session.prepare_value(value)) + payload = writer.append(value) payload.set_content_disposition("form-data", name=key) - if not result.files: - return writer - - for key, value in result.files.items(): + for key, value in files.items(): payload = writer.append(value) - payload.set_content_disposition("form-data", name=key, filename=value.filename) + payload.set_content_disposition( + "form-data", + name=key, + filename=value.filename or key, + ) return writer async def _handle_request(self, bot: Bot, request: web.Request) -> web.Response: - result = await self.dispatcher.feed_webhook_update( + result: Optional[TelegramMethod[Any]] = await self.dispatcher.feed_webhook_update( bot, await request.json(loads=bot.session.json_loads), **self.data, diff --git a/pyproject.toml b/pyproject.toml index 6f76173e..5a203c92 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -138,7 +138,7 @@ features = [ serve = "sphinx-autobuild --watch aiogram/ --watch CHANGELOG.rst --watch README.rst docs/ docs/_build/ {args}" [tool.hatch.envs.dev] -python = "3.10" +python = "3.11" features = [ "dev", "fast", @@ -148,7 +148,7 @@ features = [ "test", ] extra-dependencies = [ - "butcher @ git+https://github.com/aiogram/butcher.git@v0.1.12" + "butcher @ git+https://github.com/aiogram/butcher.git@v0.1.13" ] [tool.hatch.envs.test] diff --git a/tests/mocked_bot.py b/tests/mocked_bot.py index 25a9b38e..29c477a0 100644 --- a/tests/mocked_bot.py +++ b/tests/mocked_bot.py @@ -4,32 +4,35 @@ from typing import TYPE_CHECKING, AsyncGenerator, Deque, Optional, Type from aiogram import Bot from aiogram.client.session.base import BaseSession from aiogram.methods import TelegramMethod -from aiogram.methods.base import Request, Response, TelegramType -from aiogram.types import UNSET, ResponseParameters, User +from aiogram.methods.base import Response, TelegramType +from aiogram.types import UNSET_PARSE_MODE, ResponseParameters, User class MockedSession(BaseSession): def __init__(self): super(MockedSession, self).__init__() self.responses: Deque[Response[TelegramType]] = deque() - self.requests: Deque[Request] = deque() + self.requests: Deque[TelegramMethod[TelegramType]] = deque() self.closed = True def add_result(self, response: Response[TelegramType]) -> Response[TelegramType]: self.responses.append(response) return response - def get_request(self) -> Request: + def get_request(self) -> TelegramMethod[TelegramType]: return self.requests.pop() async def close(self): self.closed = True async def make_request( - self, bot: Bot, method: TelegramMethod[TelegramType], timeout: Optional[int] = UNSET + self, + bot: Bot, + method: TelegramMethod[TelegramType], + timeout: Optional[int] = UNSET_PARSE_MODE, ) -> TelegramType: self.closed = False - self.requests.append(method.build_request(bot)) + self.requests.append(method) response: Response[TelegramType] = self.responses.pop() self.check_response( method=method, status_code=response.error_code, content=response.json() @@ -86,5 +89,5 @@ class MockedBot(Bot): self.session.add_result(response) return response - def get_request(self) -> Request: + def get_request(self) -> TelegramMethod[TelegramType]: return self.session.get_request() diff --git a/tests/test_api/test_client/test_session/test_aiohttp_session.py b/tests/test_api/test_client/test_session/test_aiohttp_session.py index 651711cb..fd7cabfd 100644 --- a/tests/test_api/test_client/test_session/test_aiohttp_session.py +++ b/tests/test_api/test_client/test_session/test_aiohttp_session.py @@ -1,5 +1,5 @@ import asyncio -from typing import AsyncContextManager, AsyncGenerator +from typing import Any, AsyncContextManager, AsyncGenerator, Dict, List from unittest.mock import AsyncMock, patch import aiohttp_socks @@ -11,8 +11,8 @@ from aiogram import Bot from aiogram.client.session import aiohttp from aiogram.client.session.aiohttp import AiohttpSession from aiogram.exceptions import TelegramNetworkError -from aiogram.methods import Request, TelegramMethod -from aiogram.types import UNSET, InputFile +from aiogram.methods import TelegramMethod +from aiogram.types import UNSET_PARSE_MODE, InputFile from tests.mocked_bot import MockedBot @@ -103,44 +103,60 @@ class TestAiohttpSession: await session.close() mocked_close.assert_called_once() - def test_build_form_data_with_data_only(self): - request = Request( - method="method", - data={ - "str": "value", - "int": 42, - "bool": True, - "unset": UNSET, - "null": None, - "list": ["foo"], - "dict": {"bar": "baz"}, - }, - ) + def test_build_form_data_with_data_only(self, bot: MockedBot): + class TestMethod(TelegramMethod[bool]): + __api_method__ = "test" + __returning__ = bool + + str_: str + int_: int + bool_: bool + unset_: str = UNSET_PARSE_MODE + null_: None + list_: List[str] + dict_: Dict[str, Any] session = AiohttpSession() - form = session.build_form_data(request) + form = session.build_form_data( + bot, + TestMethod( + str_="value", + int_=42, + bool_=True, + unset_=UNSET_PARSE_MODE, + null_=None, + list_=["foo"], + dict_={"bar": "baz"}, + ), + ) fields = form._fields assert len(fields) == 5 assert all(isinstance(field[2], str) for field in fields) - assert "null" not in [item[0]["name"] for item in fields] + assert "null_" not in [item[0]["name"] for item in fields] - def test_build_form_data_with_files(self): - request = Request( - method="method", - data={"key": "value"}, - files={"document": BareInputFile(filename="file.txt")}, - ) + def test_build_form_data_with_files(self, bot: Bot): + class TestMethod(TelegramMethod[bool]): + __api_method__ = "test" + __returning__ = bool + + key: str + document: InputFile session = AiohttpSession() - form = session.build_form_data(request) + form = session.build_form_data( + bot, + TestMethod(key="value", document=BareInputFile(filename="file.txt")), + ) fields = form._fields - assert len(fields) == 2 + assert len(fields) == 3 assert fields[1][0]["name"] == "document" - assert fields[1][0]["filename"] == "file.txt" - assert isinstance(fields[1][2], BareInputFile) + assert fields[1][2].startswith("attach://") + assert fields[2][0]["name"] == fields[1][2][9:] + assert fields[2][0]["filename"] == "file.txt" + assert isinstance(fields[2][2], BareInputFile) async def test_make_request(self, bot: MockedBot, aresponses: ResponsesMockServer): aresponses.add( @@ -158,9 +174,7 @@ class TestAiohttpSession: class TestMethod(TelegramMethod[int]): __returning__ = int - - def build_request(self, bot: Bot) -> Request: - return Request(method="method", data={}) + __api_method__ = "method" call = TestMethod() diff --git a/tests/test_api/test_client/test_session/test_base_session.py b/tests/test_api/test_client/test_session/test_base_session.py index e46981f6..48d43cef 100644 --- a/tests/test_api/test_client/test_session/test_base_session.py +++ b/tests/test_api/test_client/test_session/test_base_session.py @@ -1,14 +1,15 @@ import datetime import json -from typing import AsyncContextManager, AsyncGenerator, Optional +from typing import Any, AsyncContextManager, AsyncGenerator, Optional from unittest.mock import AsyncMock, patch import pytest +from pytz import utc from aiogram import Bot from aiogram.client.session.base import BaseSession, TelegramType from aiogram.client.telegram import PRODUCTION, TelegramAPIServer -from aiogram.enums import ChatType, TopicIconColor +from aiogram.enums import ChatType, ParseMode, TopicIconColor from aiogram.exceptions import ( ClientDecodeError, RestartingTelegram, @@ -24,7 +25,8 @@ from aiogram.exceptions import ( TelegramUnauthorizedError, ) from aiogram.methods import DeleteMessage, GetMe, TelegramMethod -from aiogram.types import UNSET, User +from aiogram.types import UNSET_PARSE_MODE, User +from aiogram.types.base import UNSET_DISABLE_WEB_PAGE_PREVIEW, UNSET_PROTECT_CONTENT from tests.mocked_bot import MockedBot @@ -33,17 +35,21 @@ class CustomSession(BaseSession): pass async def make_request( - self, token: str, method: TelegramMethod[TelegramType], timeout: Optional[int] = UNSET + self, + token: str, + method: TelegramMethod[TelegramType], + timeout: Optional[int] = UNSET_PARSE_MODE, ) -> None: # type: ignore assert isinstance(token, str) assert isinstance(method, TelegramMethod) async def stream_content( - self, url: str, timeout: int, chunk_size: int + self, url: str, timeout: int, chunk_size: int, raise_for_status: bool ) -> AsyncGenerator[bytes, None]: # pragma: no cover assert isinstance(url, str) assert isinstance(timeout, int) assert isinstance(chunk_size, int) + assert isinstance(raise_for_status, bool) yield b"\f" * 10 @@ -79,58 +85,56 @@ class TestBaseSession: assert session.api == api assert "example.com" in session.api.base - def test_prepare_value(self): + @pytest.mark.parametrize( + "value,result", + [ + [None, None], + ["text", "text"], + [ChatType.PRIVATE, "private"], + [TopicIconColor.RED, "16478047"], + [42, "42"], + [True, "true"], + [["test"], '["test"]'], + [["test", ["test"]], '["test", ["test"]]'], + [[{"test": "pass", "spam": None}], '[{"test": "pass"}]'], + [{"test": "pass", "number": 42, "spam": None}, '{"test": "pass", "number": 42}'], + [{"foo": {"test": "pass", "spam": None}}, '{"foo": {"test": "pass"}}'], + [ + datetime.datetime( + year=2017, month=5, day=17, hour=4, minute=11, second=42, tzinfo=utc + ), + "1494994302", + ], + ], + ) + def test_prepare_value(self, value: Any, result: str, bot: MockedBot): session = CustomSession() - now = datetime.datetime.now() + assert session.prepare_value(value, bot=bot, files={}) == result - assert session.prepare_value("text") == "text" - assert session.prepare_value(["test"]) == '["test"]' - assert session.prepare_value({"test": "ok"}) == '{"test": "ok"}' - assert session.prepare_value(now) == str(round(now.timestamp())) - assert isinstance(session.prepare_value(datetime.timedelta(minutes=2)), str) - assert session.prepare_value(42) == "42" - assert session.prepare_value(ChatType.PRIVATE) == "private" - assert session.prepare_value(TopicIconColor.RED) == "16478047" - - def test_clean_json(self): + def test_prepare_value_timedelta(self, bot: MockedBot): session = CustomSession() - cleaned_dict = session.clean_json({"key": "value", "null": None}) - assert "key" in cleaned_dict - assert "null" not in cleaned_dict + value = session.prepare_value(datetime.timedelta(minutes=2), bot=bot, files={}) + assert isinstance(value, str) - cleaned_list = session.clean_json(["kaboom", 42, None]) - assert len(cleaned_list) == 2 - assert 42 in cleaned_list - assert None not in cleaned_list - assert cleaned_list[0] == "kaboom" - - def test_clean_json_with_nested_json(self): - session = CustomSession() - - cleaned = session.clean_json( - { - "key": "value", - "null": None, - "nested_list": ["kaboom", 42, None], - "nested_dict": {"key": "value", "null": None}, - } + def test_prepare_value_defaults_replace(self): + bot = MockedBot( + parse_mode=ParseMode.HTML, + protect_content=True, + disable_web_page_preview=True, ) + assert bot.session.prepare_value(UNSET_PARSE_MODE, bot=bot, files={}) == "HTML" + assert ( + bot.session.prepare_value(UNSET_DISABLE_WEB_PAGE_PREVIEW, bot=bot, files={}) == "true" + ) + assert bot.session.prepare_value(UNSET_PROTECT_CONTENT, bot=bot, files={}) == "true" - assert len(cleaned) == 3 - assert "null" not in cleaned - - assert isinstance(cleaned["nested_list"], list) - assert cleaned["nested_list"] == ["kaboom", 42] - - assert isinstance(cleaned["nested_dict"], dict) - assert cleaned["nested_dict"] == {"key": "value"} - - def test_clean_json_not_json(self): - session = CustomSession() - - assert session.clean_json(42) == 42 + def test_prepare_value_defaults_unset(self): + bot = MockedBot() + assert bot.session.prepare_value(UNSET_PARSE_MODE, bot=bot, files={}) is None + assert bot.session.prepare_value(UNSET_DISABLE_WEB_PAGE_PREVIEW, bot=bot, files={}) is None + assert bot.session.prepare_value(UNSET_PROTECT_CONTENT, bot=bot, files={}) is None @pytest.mark.parametrize( "status_code,content,error", @@ -210,7 +214,10 @@ class TestBaseSession: async def test_stream_content(self): session = CustomSession() stream = session.stream_content( - "https://www.python.org/static/img/python-logo.png", timeout=5, chunk_size=65536 + "https://www.python.org/static/img/python-logo.png", + timeout=5, + chunk_size=65536, + raise_for_status=True, ) assert isinstance(stream, AsyncGenerator) 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 94e9c3f1..8e617a74 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,21 +1,9 @@ -from aiogram.methods import AddStickerToSet, Request +from aiogram.methods import AddStickerToSet from aiogram.types import InputSticker from tests.mocked_bot import MockedBot class TestAddStickerToSet: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(AddStickerToSet, ok=True, result=True) - - response: bool = await AddStickerToSet( - user_id=42, - name="test stickers pack", - sticker=InputSticker(sticker="file id", emoji_list=[":)"]), - ) - request: Request = bot.get_request() - assert request.method == "addStickerToSet" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(AddStickerToSet, ok=True, result=True) @@ -24,6 +12,5 @@ class TestAddStickerToSet: name="test stickers pack", sticker=InputSticker(sticker="file id", emoji_list=[":)"]), ) - request: Request = bot.get_request() - assert request.method == "addStickerToSet" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_answer_callback_query.py b/tests/test_api/test_methods/test_answer_callback_query.py index 54f9e640..98e9df17 100644 --- a/tests/test_api/test_methods/test_answer_callback_query.py +++ b/tests/test_api/test_methods/test_answer_callback_query.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestAnswerCallbackQuery: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(AnswerCallbackQuery, ok=True, result=True) - - response: bool = await AnswerCallbackQuery(callback_query_id="cq id", text="OK") - request: Request = bot.get_request() - assert request.method == "answerCallbackQuery" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(AnswerCallbackQuery, ok=True, result=True) response: bool = await bot.answer_callback_query(callback_query_id="cq id", text="OK") - request: Request = bot.get_request() - assert request.method == "answerCallbackQuery" + request = bot.get_request() assert response == prepare_result.result 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 c3b35a2e..a0cec362 100644 --- a/tests/test_api/test_methods/test_answer_inline_query.py +++ b/tests/test_api/test_methods/test_answer_inline_query.py @@ -9,55 +9,11 @@ from tests.mocked_bot import MockedBot class TestAnswerInlineQuery: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(AnswerInlineQuery, ok=True, result=True) - - response: bool = await AnswerInlineQuery( - inline_query_id="query id", results=[InlineQueryResult()] - ) - request: Request = bot.get_request() - assert request.method == "answerInlineQuery" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(AnswerInlineQuery, ok=True, result=True) response: bool = await bot.answer_inline_query( inline_query_id="query id", results=[InlineQueryResult()] ) - request: Request = bot.get_request() - assert request.method == "answerInlineQuery" + request = bot.get_request() assert response == prepare_result.result - - def test_parse_mode(self, bot: MockedBot): - query = AnswerInlineQuery( - inline_query_id="query id", - 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 - - new_bot = Bot(token="42:TEST", parse_mode="HTML") - request = query.build_request(new_bot) - assert request.data["results"][0]["parse_mode"] == "HTML" - - def test_parse_mode_input_message_content(self, bot: MockedBot): - query = AnswerInlineQuery( - inline_query_id="query id", - results=[ - InlineQueryResultPhoto( - id="result id", - photo_url="photo", - thumbnail_url="thumb", - input_message_content=InputTextMessageContent(message_text="test"), - ) - ], - ) - request = query.build_request(bot) - assert request.data["results"][0]["input_message_content"]["parse_mode"] is None - - new_bot = Bot(token="42:TEST", parse_mode="HTML") - request = query.build_request(new_bot) - assert request.data["results"][0]["input_message_content"]["parse_mode"] == "HTML" diff --git a/tests/test_api/test_methods/test_answer_pre_checkout_query.py b/tests/test_api/test_methods/test_answer_pre_checkout_query.py index f15f5beb..b2a1f6c9 100644 --- a/tests/test_api/test_methods/test_answer_pre_checkout_query.py +++ b/tests/test_api/test_methods/test_answer_pre_checkout_query.py @@ -3,20 +3,11 @@ from tests.mocked_bot import MockedBot class TestAnswerPreCheckoutQuery: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(AnswerPreCheckoutQuery, ok=True, result=True) - - response: bool = await AnswerPreCheckoutQuery(pre_checkout_query_id="query id", ok=True) - request: Request = bot.get_request() - assert request.method == "answerPreCheckoutQuery" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(AnswerPreCheckoutQuery, ok=True, result=True) response: bool = await bot.answer_pre_checkout_query( pre_checkout_query_id="query id", ok=True ) - request: Request = bot.get_request() - assert request.method == "answerPreCheckoutQuery" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_answer_shipping_query.py b/tests/test_api/test_methods/test_answer_shipping_query.py index 8a2b5f89..d31f41f8 100644 --- a/tests/test_api/test_methods/test_answer_shipping_query.py +++ b/tests/test_api/test_methods/test_answer_shipping_query.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestAnswerShippingQuery: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(AnswerShippingQuery, ok=True, result=True) - - response: bool = await AnswerShippingQuery(shipping_query_id="query id", ok=True) - request: Request = bot.get_request() - assert request.method == "answerShippingQuery" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(AnswerShippingQuery, ok=True, result=True) response: bool = await bot.answer_shipping_query(shipping_query_id="query id", ok=True) - request: Request = bot.get_request() - assert request.method == "answerShippingQuery" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_answer_web_app_query.py b/tests/test_api/test_methods/test_answer_web_app_query.py index 713653f1..6948bead 100644 --- a/tests/test_api/test_methods/test_answer_web_app_query.py +++ b/tests/test_api/test_methods/test_answer_web_app_query.py @@ -4,18 +4,6 @@ from tests.mocked_bot import MockedBot class TestAnswerWebAppQuery: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(AnswerWebAppQuery, ok=True, result=SentWebAppMessage()) - - response: SentWebAppMessage = await AnswerWebAppQuery( - web_app_query_id="test", - result=InlineQueryResult(), - ) - request: Request = bot.get_request() - assert request.method == "answerWebAppQuery" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(AnswerWebAppQuery, ok=True, result=SentWebAppMessage()) @@ -23,7 +11,5 @@ class TestAnswerWebAppQuery: web_app_query_id="test", result=InlineQueryResult(), ) - request: Request = bot.get_request() - assert request.method == "answerWebAppQuery" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_approve_chat_join_request.py b/tests/test_api/test_methods/test_approve_chat_join_request.py index ea81c4ac..6b097702 100755 --- a/tests/test_api/test_methods/test_approve_chat_join_request.py +++ b/tests/test_api/test_methods/test_approve_chat_join_request.py @@ -3,17 +3,6 @@ from tests.mocked_bot import MockedBot class TestApproveChatJoinRequest: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(ApproveChatJoinRequest, ok=True, result=True) - - response: bool = await ApproveChatJoinRequest( - chat_id=-42, - user_id=42, - ) - request: Request = bot.get_request() - assert request.method == "approveChatJoinRequest" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(ApproveChatJoinRequest, ok=True, result=None) @@ -21,6 +10,5 @@ class TestApproveChatJoinRequest: chat_id=-42, user_id=42, ) - request: Request = bot.get_request() - assert request.method == "approveChatJoinRequest" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_ban_chat_member.py b/tests/test_api/test_methods/test_ban_chat_member.py index 10464737..98ca951e 100644 --- a/tests/test_api/test_methods/test_ban_chat_member.py +++ b/tests/test_api/test_methods/test_ban_chat_member.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestKickChatMember: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(BanChatMember, ok=True, result=True) - - response: bool = await BanChatMember(chat_id=-42, user_id=42) - request: Request = bot.get_request() - assert request.method == "banChatMember" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(BanChatMember, ok=True, result=True) response: bool = await bot.ban_chat_member(chat_id=-42, user_id=42) - request: Request = bot.get_request() - assert request.method == "banChatMember" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_ban_chat_sender_chat.py b/tests/test_api/test_methods/test_ban_chat_sender_chat.py index b93f27a5..6811c975 100755 --- a/tests/test_api/test_methods/test_ban_chat_sender_chat.py +++ b/tests/test_api/test_methods/test_ban_chat_sender_chat.py @@ -3,18 +3,6 @@ from tests.mocked_bot import MockedBot class TestBanChatSenderChat: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(BanChatSenderChat, ok=True, result=True) - - response: bool = await BanChatSenderChat( - chat_id=-42, - sender_chat_id=-1337, - ) - request: Request = bot.get_request() - assert request.method == "banChatSenderChat" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(BanChatSenderChat, ok=True, result=True) @@ -22,7 +10,5 @@ class TestBanChatSenderChat: chat_id=-42, sender_chat_id=-1337, ) - request: Request = bot.get_request() - assert request.method == "banChatSenderChat" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_base.py b/tests/test_api/test_methods/test_base.py index 38306db1..f2351d40 100644 --- a/tests/test_api/test_methods/test_base.py +++ b/tests/test_api/test_methods/test_base.py @@ -1,61 +1,27 @@ -from typing import Dict, Optional +from unittest.mock import sentinel import pytest -from aiogram import Bot -from aiogram.methods.base import prepare_parse_mode +from aiogram.methods import GetMe, TelegramMethod +from aiogram.types import User from tests.mocked_bot import MockedBot -class TestPrepareFile: - # TODO: Add tests - pass - - -class TestPrepareInputMedia: - # TODO: Add tests - pass - - -class TestPrepareMediaFile: - # TODO: Add tests - pass - - -class TestPrepareParseMode: +class TestTelegramMethodRemoveUnset: @pytest.mark.parametrize( - "parse_mode,data,result", + "values,names", [ - [None, {}, None], - ["HTML", {}, "HTML"], - ["Markdown", {}, "Markdown"], - [None, {"parse_mode": "HTML"}, "HTML"], - ["HTML", {"parse_mode": "HTML"}, "HTML"], - ["Markdown", {"parse_mode": "HTML"}, "HTML"], + [{}, set()], + [{"foo": "bar"}, {"foo"}], + [{"foo": "bar", "baz": sentinel.DEFAULT}, {"foo"}], ], ) - async def test_default_parse_mode( - self, bot: MockedBot, parse_mode: str, data: Dict[str, str], result: Optional[str] - ): - async with Bot(token="42:TEST", parse_mode=parse_mode).context() as bot: - assert bot.parse_mode == parse_mode - prepare_parse_mode(bot, data) - assert data.get("parse_mode") == result + def test_remove_unset(self, values, names): + validated = TelegramMethod.remove_unset(values) + assert set(validated.keys()) == names - async def test_list(self): - data = [{}] * 2 - data.append({"parse_mode": "HTML"}) - bot = Bot(token="42:TEST", parse_mode="Markdown") - prepare_parse_mode(bot, data) - assert isinstance(data, list) - assert len(data) == 3 - assert all("parse_mode" in item for item in data) - assert data[0]["parse_mode"] == "Markdown" - assert data[1]["parse_mode"] == "Markdown" - assert data[2]["parse_mode"] == "HTML" - - def test_bot_not_in_context(self, bot: MockedBot): - data = {} - prepare_parse_mode(bot, data) - assert data["parse_mode"] is None +class TestTelegramMethodCall: + async def test_async_emit(self, bot: MockedBot): + bot.add_result_for(GetMe, ok=True, result=User(id=42, is_bot=True, first_name="Test")) + assert isinstance(await GetMe(), User) diff --git a/tests/test_api/test_methods/test_close.py b/tests/test_api/test_methods/test_close.py index f8f8956b..e13223fa 100644 --- a/tests/test_api/test_methods/test_close.py +++ b/tests/test_api/test_methods/test_close.py @@ -3,20 +3,9 @@ from tests.mocked_bot import MockedBot class TestClose: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(Close, ok=True, result=True) - - response: bool = await Close() - request: Request = bot.get_request() - assert request.method == "close" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(Close, ok=True, result=True) response: bool = await bot.close() - request: Request = bot.get_request() - assert request.method == "close" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_close_forum_topic.py b/tests/test_api/test_methods/test_close_forum_topic.py index 4857e7a4..ff45c6ac 100644 --- a/tests/test_api/test_methods/test_close_forum_topic.py +++ b/tests/test_api/test_methods/test_close_forum_topic.py @@ -3,18 +3,6 @@ from tests.mocked_bot import MockedBot class TestCloseForumTopic: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(CloseForumTopic, ok=True, result=True) - - response: bool = await CloseForumTopic( - chat_id=42, - message_thread_id=42, - ) - request: Request = bot.get_request() - assert request.method == "closeForumTopic" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(CloseForumTopic, ok=True, result=True) @@ -22,7 +10,5 @@ class TestCloseForumTopic: chat_id=42, message_thread_id=42, ) - request: Request = bot.get_request() - assert request.method == "closeForumTopic" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_close_general_forum_topic.py b/tests/test_api/test_methods/test_close_general_forum_topic.py index a62ce146..b0a022ec 100644 --- a/tests/test_api/test_methods/test_close_general_forum_topic.py +++ b/tests/test_api/test_methods/test_close_general_forum_topic.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestCloseGeneralForumTopic: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(CloseGeneralForumTopic, ok=True, result=True) - - response: bool = await bot(CloseGeneralForumTopic(chat_id=42)) - request: Request = bot.get_request() - assert request.method == "closeGeneralForumTopic" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(CloseGeneralForumTopic, ok=True, result=True) response: bool = await bot.close_general_forum_topic(chat_id=42) - request: Request = bot.get_request() - assert request.method == "closeGeneralForumTopic" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_copy_message.py b/tests/test_api/test_methods/test_copy_message.py index 38419c6b..bff6004b 100644 --- a/tests/test_api/test_methods/test_copy_message.py +++ b/tests/test_api/test_methods/test_copy_message.py @@ -4,19 +4,6 @@ from tests.mocked_bot import MockedBot class TestCopyMessage: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(CopyMessage, ok=True, result=MessageId(message_id=42)) - - response: MessageId = await CopyMessage( - chat_id=42, - from_chat_id=42, - message_id=42, - ) - request: Request = bot.get_request() - assert request.method == "copyMessage" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(CopyMessage, ok=True, result=MessageId(message_id=42)) @@ -25,7 +12,5 @@ class TestCopyMessage: from_chat_id=42, message_id=42, ) - request: Request = bot.get_request() - assert request.method == "copyMessage" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_create_chat_invite_link.py b/tests/test_api/test_methods/test_create_chat_invite_link.py index cfdca233..87a31be8 100644 --- a/tests/test_api/test_methods/test_create_chat_invite_link.py +++ b/tests/test_api/test_methods/test_create_chat_invite_link.py @@ -4,27 +4,6 @@ from tests.mocked_bot import MockedBot class TestCreateChatInviteLink: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - CreateChatInviteLink, - ok=True, - result=ChatInviteLink( - invite_link="https://t.me/username", - creator=User(id=42, is_bot=False, first_name="User"), - is_primary=False, - is_revoked=False, - creates_join_request=False, - ), - ) - - response: ChatInviteLink = await CreateChatInviteLink( - chat_id=-42, - ) - request: Request = bot.get_request() - assert request.method == "createChatInviteLink" - # assert request.data == {"chat_id": -42} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( CreateChatInviteLink, @@ -41,7 +20,5 @@ class TestCreateChatInviteLink: response: ChatInviteLink = await bot.create_chat_invite_link( chat_id=-42, ) - request: Request = bot.get_request() - assert request.method == "createChatInviteLink" - # assert request.data == {"chat_id": -42} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_create_forum_topic.py b/tests/test_api/test_methods/test_create_forum_topic.py index 84eaf02e..071945ca 100644 --- a/tests/test_api/test_methods/test_create_forum_topic.py +++ b/tests/test_api/test_methods/test_create_forum_topic.py @@ -4,22 +4,6 @@ from tests.mocked_bot import MockedBot class TestCreateForumTopic: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - CreateForumTopic, - ok=True, - result=ForumTopic(message_thread_id=42, name="test", icon_color=0xFFD67E), - ) - - response: ForumTopic = await CreateForumTopic( - chat_id=42, - name="test", - ) - request: Request = bot.get_request() - assert request.method == "createForumTopic" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( CreateForumTopic, @@ -31,7 +15,5 @@ class TestCreateForumTopic: chat_id=42, name="test", ) - request: Request = bot.get_request() - assert request.method == "createForumTopic" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_create_invoice_link.py b/tests/test_api/test_methods/test_create_invoice_link.py index 7909fac9..75a46326 100644 --- a/tests/test_api/test_methods/test_create_invoice_link.py +++ b/tests/test_api/test_methods/test_create_invoice_link.py @@ -4,23 +4,6 @@ from tests.mocked_bot import MockedBot class TestCreateInvoiceLink: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - CreateInvoiceLink, ok=True, result="https://t.me/invoice/example" - ) - - response: str = await CreateInvoiceLink( - title="test", - description="test", - payload="test", - provider_token="test", - currency="BTC", - prices=[LabeledPrice(label="Test", amount=1)], - ) - request: Request = bot.get_request() - assert request.method == "createInvoiceLink" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( CreateInvoiceLink, ok=True, result="https://t.me/invoice/example" @@ -34,6 +17,5 @@ class TestCreateInvoiceLink: currency="BTC", prices=[LabeledPrice(label="Test", amount=1)], ) - request: Request = bot.get_request() - assert request.method == "createInvoiceLink" + request = bot.get_request() assert response == prepare_result.result 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 ba44266e..7aef1fc8 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 @@ -5,23 +5,6 @@ from tests.mocked_bot import MockedBot class TestCreateNewStickerSet: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(CreateNewStickerSet, ok=True, result=True) - - response: bool = await CreateNewStickerSet( - 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" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(CreateNewStickerSet, ok=True, result=True) @@ -35,6 +18,5 @@ class TestCreateNewStickerSet: ], sticker_format=StickerFormat.STATIC, ) - request: Request = bot.get_request() - assert request.method == "createNewStickerSet" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_decline_chat_join_request.py b/tests/test_api/test_methods/test_decline_chat_join_request.py index 549f43d1..f85c4375 100755 --- a/tests/test_api/test_methods/test_decline_chat_join_request.py +++ b/tests/test_api/test_methods/test_decline_chat_join_request.py @@ -3,17 +3,6 @@ from tests.mocked_bot import MockedBot class TestDeclineChatJoinRequest: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(DeclineChatJoinRequest, ok=True, result=True) - - response: bool = await DeclineChatJoinRequest( - chat_id=-42, - user_id=42, - ) - request: Request = bot.get_request() - assert request.method == "declineChatJoinRequest" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(DeclineChatJoinRequest, ok=True, result=True) @@ -21,6 +10,5 @@ class TestDeclineChatJoinRequest: chat_id=-42, user_id=42, ) - request: Request = bot.get_request() - assert request.method == "declineChatJoinRequest" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_delete_chat_photo.py b/tests/test_api/test_methods/test_delete_chat_photo.py index 9faaa8bf..df8c5eef 100644 --- a/tests/test_api/test_methods/test_delete_chat_photo.py +++ b/tests/test_api/test_methods/test_delete_chat_photo.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestDeleteChatPhoto: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(DeleteChatPhoto, ok=True, result=True) - - response: bool = await DeleteChatPhoto(chat_id=42) - request: Request = bot.get_request() - assert request.method == "deleteChatPhoto" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(DeleteChatPhoto, ok=True, result=True) response: bool = await bot.delete_chat_photo(chat_id=42) - request: Request = bot.get_request() - assert request.method == "deleteChatPhoto" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_delete_chat_sticker_set.py b/tests/test_api/test_methods/test_delete_chat_sticker_set.py index ae6af449..c8452d75 100644 --- a/tests/test_api/test_methods/test_delete_chat_sticker_set.py +++ b/tests/test_api/test_methods/test_delete_chat_sticker_set.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestDeleteChatStickerSet: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(DeleteChatStickerSet, ok=True, result=True) - - response: bool = await DeleteChatStickerSet(chat_id=42) - request: Request = bot.get_request() - assert request.method == "deleteChatStickerSet" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(DeleteChatStickerSet, ok=True, result=True) response: bool = await bot.delete_chat_sticker_set(chat_id=42) - request: Request = bot.get_request() - assert request.method == "deleteChatStickerSet" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_delete_forum_topic.py b/tests/test_api/test_methods/test_delete_forum_topic.py index e0ad6bfd..63cd629e 100644 --- a/tests/test_api/test_methods/test_delete_forum_topic.py +++ b/tests/test_api/test_methods/test_delete_forum_topic.py @@ -3,18 +3,6 @@ from tests.mocked_bot import MockedBot class TestDeleteForumTopic: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(DeleteForumTopic, ok=True, result=True) - - response: bool = await DeleteForumTopic( - chat_id=42, - message_thread_id=42, - ) - request: Request = bot.get_request() - assert request.method == "deleteForumTopic" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(DeleteForumTopic, ok=True, result=True) @@ -22,7 +10,5 @@ class TestDeleteForumTopic: chat_id=42, message_thread_id=42, ) - request: Request = bot.get_request() - assert request.method == "deleteForumTopic" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_delete_message.py b/tests/test_api/test_methods/test_delete_message.py index 097496a2..de8b44e4 100644 --- a/tests/test_api/test_methods/test_delete_message.py +++ b/tests/test_api/test_methods/test_delete_message.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestDeleteMessage: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(DeleteMessage, ok=True, result=True) - - response: bool = await DeleteMessage(chat_id=42, message_id=42) - request: Request = bot.get_request() - assert request.method == "deleteMessage" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(DeleteMessage, ok=True, result=True) response: bool = await bot.delete_message(chat_id=42, message_id=42) - request: Request = bot.get_request() - assert request.method == "deleteMessage" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_delete_my_commands.py b/tests/test_api/test_methods/test_delete_my_commands.py index c4902ec4..86e4c47e 100644 --- a/tests/test_api/test_methods/test_delete_my_commands.py +++ b/tests/test_api/test_methods/test_delete_my_commands.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestKickChatMember: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(DeleteMyCommands, ok=True, result=True) - - response: bool = await DeleteMyCommands() - request: Request = bot.get_request() - assert request.method == "deleteMyCommands" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(DeleteMyCommands, ok=True, result=True) response: bool = await bot.delete_my_commands() - request: Request = bot.get_request() - assert request.method == "deleteMyCommands" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_delete_sticker_from_set.py b/tests/test_api/test_methods/test_delete_sticker_from_set.py index bc2a8e79..b8e25153 100644 --- a/tests/test_api/test_methods/test_delete_sticker_from_set.py +++ b/tests/test_api/test_methods/test_delete_sticker_from_set.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestDeleteStickerFromSet: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(DeleteStickerFromSet, ok=True, result=True) - - response: bool = await DeleteStickerFromSet(sticker="sticker id") - request: Request = bot.get_request() - assert request.method == "deleteStickerFromSet" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(DeleteStickerFromSet, ok=True, result=True) response: bool = await bot.delete_sticker_from_set(sticker="sticker id") - request: Request = bot.get_request() - assert request.method == "deleteStickerFromSet" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_delete_sticker_set.py b/tests/test_api/test_methods/test_delete_sticker_set.py index 4ab6a1a0..b0f6391c 100644 --- a/tests/test_api/test_methods/test_delete_sticker_set.py +++ b/tests/test_api/test_methods/test_delete_sticker_set.py @@ -3,18 +3,9 @@ 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" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_delete_webhook.py b/tests/test_api/test_methods/test_delete_webhook.py index 76591a8a..3f755d73 100644 --- a/tests/test_api/test_methods/test_delete_webhook.py +++ b/tests/test_api/test_methods/test_delete_webhook.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestDeleteWebhook: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(DeleteWebhook, ok=True, result=True) - - response: bool = await DeleteWebhook() - request: Request = bot.get_request() - assert request.method == "deleteWebhook" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(DeleteWebhook, ok=True, result=True) response: bool = await bot.delete_webhook() - request: Request = bot.get_request() - assert request.method == "deleteWebhook" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_edit_chat_invite_link.py b/tests/test_api/test_methods/test_edit_chat_invite_link.py index ab71c3ae..7bceffcd 100644 --- a/tests/test_api/test_methods/test_edit_chat_invite_link.py +++ b/tests/test_api/test_methods/test_edit_chat_invite_link.py @@ -4,26 +4,6 @@ from tests.mocked_bot import MockedBot class TestEditChatInviteLink: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - EditChatInviteLink, - ok=True, - result=ChatInviteLink( - invite_link="https://t.me/username2", - creator=User(id=42, is_bot=False, first_name="User"), - is_primary=False, - is_revoked=False, - creates_join_request=False, - ), - ) - - response: ChatInviteLink = await EditChatInviteLink( - chat_id=-42, invite_link="https://t.me/username", member_limit=1 - ) - request: Request = bot.get_request() - assert request.method == "editChatInviteLink" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( EditChatInviteLink, @@ -40,6 +20,5 @@ class TestEditChatInviteLink: response: ChatInviteLink = await bot.edit_chat_invite_link( chat_id=-42, invite_link="https://t.me/username", member_limit=1 ) - request: Request = bot.get_request() - assert request.method == "editChatInviteLink" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_edit_forum_topic.py b/tests/test_api/test_methods/test_edit_forum_topic.py index 98e30166..2dbb06f9 100644 --- a/tests/test_api/test_methods/test_edit_forum_topic.py +++ b/tests/test_api/test_methods/test_edit_forum_topic.py @@ -3,21 +3,6 @@ from tests.mocked_bot import MockedBot class TestEditForumTopic: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(EditForumTopic, ok=True, result=True) - - response: bool = await EditForumTopic( - chat_id=42, - message_thread_id=42, - name="test", - icon_color=0xFFD67E, - icon_custom_emoji_id="0", - ) - request: Request = bot.get_request() - assert request.method == "editForumTopic" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(EditForumTopic, ok=True, result=True) @@ -27,7 +12,5 @@ class TestEditForumTopic: name="test", icon_custom_emoji_id="0", ) - request: Request = bot.get_request() - assert request.method == "editForumTopic" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_edit_general_forum_topic.py b/tests/test_api/test_methods/test_edit_general_forum_topic.py index 01bff1d6..cc3fc14f 100644 --- a/tests/test_api/test_methods/test_edit_general_forum_topic.py +++ b/tests/test_api/test_methods/test_edit_general_forum_topic.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestCloseGeneralForumTopic: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(EditGeneralForumTopic, ok=True, result=True) - - response: bool = await bot(EditGeneralForumTopic(chat_id=42, name="Test")) - request: Request = bot.get_request() - assert request.method == "editGeneralForumTopic" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(EditGeneralForumTopic, ok=True, result=True) response: bool = await bot.edit_general_forum_topic(chat_id=42, name="Test") - request: Request = bot.get_request() - assert request.method == "editGeneralForumTopic" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_edit_message_caption.py b/tests/test_api/test_methods/test_edit_message_caption.py index 71a7784e..55ab5d6f 100644 --- a/tests/test_api/test_methods/test_edit_message_caption.py +++ b/tests/test_api/test_methods/test_edit_message_caption.py @@ -7,23 +7,6 @@ from tests.mocked_bot import MockedBot class TestEditMessageCaption: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - EditMessageCaption, - ok=True, - result=Message( - message_id=42, - date=datetime.datetime.now(), - text="text", - chat=Chat(id=42, type="private"), - ), - ) - - response: Union[Message, bool] = await EditMessageCaption() - request: Request = bot.get_request() - assert request.method == "editMessageCaption" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( EditMessageCaption, @@ -37,6 +20,5 @@ class TestEditMessageCaption: ) response: Union[Message, bool] = await bot.edit_message_caption() - request: Request = bot.get_request() - assert request.method == "editMessageCaption" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_edit_message_live_location.py b/tests/test_api/test_methods/test_edit_message_live_location.py index 7a2c2f7d..b9aee11a 100644 --- a/tests/test_api/test_methods/test_edit_message_live_location.py +++ b/tests/test_api/test_methods/test_edit_message_live_location.py @@ -6,22 +6,11 @@ from tests.mocked_bot import MockedBot class TestEditMessageLiveLocation: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(EditMessageLiveLocation, ok=True, result=True) - - response: Union[Message, bool] = await EditMessageLiveLocation( - latitude=3.141592, longitude=3.141592 - ) - request: Request = bot.get_request() - assert request.method == "editMessageLiveLocation" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(EditMessageLiveLocation, ok=True, result=True) response: Union[Message, bool] = await bot.edit_message_live_location( latitude=3.141592, longitude=3.141592 ) - request: Request = bot.get_request() - assert request.method == "editMessageLiveLocation" + request = bot.get_request() assert response == prepare_result.result 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 15594aff..57e74d45 100644 --- a/tests/test_api/test_methods/test_edit_message_media.py +++ b/tests/test_api/test_methods/test_edit_message_media.py @@ -6,22 +6,11 @@ from tests.mocked_bot import MockedBot 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=InputMediaPhoto(media=BufferedInputFile(b"", "photo.png")) - ) - request: Request = bot.get_request() - assert request.method == "editMessageMedia" - assert response == prepare_result.result - 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=InputMediaPhoto(media=BufferedInputFile(b"", "photo.png")) ) - request: Request = bot.get_request() - assert request.method == "editMessageMedia" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_edit_message_reply_markup.py b/tests/test_api/test_methods/test_edit_message_reply_markup.py index 38baa76f..1f5d94be 100644 --- a/tests/test_api/test_methods/test_edit_message_reply_markup.py +++ b/tests/test_api/test_methods/test_edit_message_reply_markup.py @@ -6,22 +6,6 @@ from tests.mocked_bot import MockedBot class TestEditMessageReplyMarkup: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(EditMessageReplyMarkup, ok=True, result=True) - - response: Union[Message, bool] = await EditMessageReplyMarkup( - chat_id=42, - inline_message_id="inline message id", - reply_markup=InlineKeyboardMarkup( - inline_keyboard=[ - [InlineKeyboardButton(text="button", callback_data="placeholder")] - ] - ), - ) - request: Request = bot.get_request() - assert request.method == "editMessageReplyMarkup" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(EditMessageReplyMarkup, ok=True, result=True) @@ -34,6 +18,5 @@ class TestEditMessageReplyMarkup: ] ), ) - request: Request = bot.get_request() - assert request.method == "editMessageReplyMarkup" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_edit_message_text.py b/tests/test_api/test_methods/test_edit_message_text.py index 1cdfcfe0..c9e203a8 100644 --- a/tests/test_api/test_methods/test_edit_message_text.py +++ b/tests/test_api/test_methods/test_edit_message_text.py @@ -6,22 +6,11 @@ from tests.mocked_bot import MockedBot class TestEditMessageText: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(EditMessageText, ok=True, result=True) - - response: Union[Message, bool] = await EditMessageText( - chat_id=42, inline_message_id="inline message id", text="text" - ) - request: Request = bot.get_request() - assert request.method == "editMessageText" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(EditMessageText, ok=True, result=True) response: Union[Message, bool] = await bot.edit_message_text( chat_id=42, inline_message_id="inline message id", text="text" ) - request: Request = bot.get_request() - assert request.method == "editMessageText" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_export_chat_invite_link.py b/tests/test_api/test_methods/test_export_chat_invite_link.py index 7e3901a0..ba85def7 100644 --- a/tests/test_api/test_methods/test_export_chat_invite_link.py +++ b/tests/test_api/test_methods/test_export_chat_invite_link.py @@ -3,22 +3,11 @@ from tests.mocked_bot import MockedBot class TestExportChatInviteLink: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - ExportChatInviteLink, ok=True, result="http://example.com" - ) - - response: str = await ExportChatInviteLink(chat_id=42) - request: Request = bot.get_request() - assert request.method == "exportChatInviteLink" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( ExportChatInviteLink, ok=True, result="http://example.com" ) response: str = await bot.export_chat_invite_link(chat_id=42) - request: Request = bot.get_request() - assert request.method == "exportChatInviteLink" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_forward_message.py b/tests/test_api/test_methods/test_forward_message.py index 955b6456..f04ec0f0 100644 --- a/tests/test_api/test_methods/test_forward_message.py +++ b/tests/test_api/test_methods/test_forward_message.py @@ -6,24 +6,6 @@ from tests.mocked_bot import MockedBot class TestForwardMessage: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - ForwardMessage, - ok=True, - result=Message( - message_id=42, - date=datetime.datetime.now(), - chat=Chat(id=42, title="chat", type="private"), - text="text", - ), - ) - - response: Message = await ForwardMessage(chat_id=42, from_chat_id=42, message_id=42) - request: Request = bot.get_request() - assert request.method == "forwardMessage" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( ForwardMessage, @@ -37,7 +19,5 @@ class TestForwardMessage: ) response: Message = await bot.forward_message(chat_id=42, from_chat_id=42, message_id=42) - request: Request = bot.get_request() - assert request.method == "forwardMessage" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_chat.py b/tests/test_api/test_methods/test_get_chat.py index c5d4bfcd..902b03b3 100644 --- a/tests/test_api/test_methods/test_get_chat.py +++ b/tests/test_api/test_methods/test_get_chat.py @@ -4,22 +4,11 @@ from tests.mocked_bot import MockedBot class TestGetChat: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - GetChat, ok=True, result=Chat(id=-42, type="channel", title="chat") - ) - - response: Chat = await GetChat(chat_id=-42) - request: Request = bot.get_request() - assert request.method == "getChat" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( GetChat, ok=True, result=Chat(id=-42, type="channel", title="chat") ) response: Chat = await bot.get_chat(chat_id=-42) - request: Request = bot.get_request() - assert request.method == "getChat" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_chat_administrators.py b/tests/test_api/test_methods/test_get_chat_administrators.py index 945b2e02..d8d57fc5 100644 --- a/tests/test_api/test_methods/test_get_chat_administrators.py +++ b/tests/test_api/test_methods/test_get_chat_administrators.py @@ -6,22 +6,6 @@ from tests.mocked_bot import MockedBot class TestGetChatAdministrators: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - GetChatAdministrators, - ok=True, - result=[ - ChatMemberOwner( - user=User(id=42, is_bot=False, first_name="User"), is_anonymous=False - ) - ], - ) - - response: List[ChatMember] = await GetChatAdministrators(chat_id=-42) - request: Request = bot.get_request() - assert request.method == "getChatAdministrators" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( GetChatAdministrators, @@ -33,6 +17,5 @@ class TestGetChatAdministrators: ], ) response: List[ChatMember] = await bot.get_chat_administrators(chat_id=-42) - request: Request = bot.get_request() - assert request.method == "getChatAdministrators" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_chat_member.py b/tests/test_api/test_methods/test_get_chat_member.py index e2fd2a75..f59a491b 100644 --- a/tests/test_api/test_methods/test_get_chat_member.py +++ b/tests/test_api/test_methods/test_get_chat_member.py @@ -4,20 +4,6 @@ from tests.mocked_bot import MockedBot class TestGetChatMember: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - GetChatMember, - ok=True, - result=ChatMemberOwner( - user=User(id=42, is_bot=False, first_name="User"), is_anonymous=False - ), - ) - - response: ChatMember = await GetChatMember(chat_id=-42, user_id=42) - request: Request = bot.get_request() - assert request.method == "getChatMember" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( GetChatMember, @@ -26,8 +12,6 @@ class TestGetChatMember: user=User(id=42, is_bot=False, first_name="User"), is_anonymous=False ), ) - - response: ChatMember = await bot.get_chat_member(chat_id=-42, user_id=42) - request: Request = bot.get_request() - assert request.method == "getChatMember" + response = await bot.get_chat_member(chat_id=-42, user_id=42) + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_chat_member_count.py b/tests/test_api/test_methods/test_get_chat_member_count.py index 91a7c514..e1aea1ff 100644 --- a/tests/test_api/test_methods/test_get_chat_member_count.py +++ b/tests/test_api/test_methods/test_get_chat_member_count.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestGetChatMembersCount: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(GetChatMemberCount, ok=True, result=42) - - response: int = await GetChatMemberCount(chat_id=-42) - request: Request = bot.get_request() - assert request.method == "getChatMemberCount" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(GetChatMemberCount, ok=True, result=42) response: int = await bot.get_chat_member_count(chat_id=-42) - request: Request = bot.get_request() - assert request.method == "getChatMemberCount" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_chat_menu_button.py b/tests/test_api/test_methods/test_get_chat_menu_button.py index 89181d3f..63a29eec 100644 --- a/tests/test_api/test_methods/test_get_chat_menu_button.py +++ b/tests/test_api/test_methods/test_get_chat_menu_button.py @@ -4,20 +4,9 @@ from tests.mocked_bot import MockedBot class TestGetChatMenuButton: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(GetChatMenuButton, ok=True, result=MenuButtonDefault()) - - response: MenuButton = await GetChatMenuButton() - request: Request = bot.get_request() - assert request.method == "getChatMenuButton" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(GetChatMenuButton, ok=True, result=MenuButtonDefault()) response: MenuButton = await bot.get_chat_menu_button() - request: Request = bot.get_request() - assert request.method == "getChatMenuButton" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result 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 fd3ea8ff..6db0f8f4 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 @@ -6,32 +6,6 @@ from tests.mocked_bot import MockedBot class TestGetCustomEmojiStickers: - async def test_method(self, bot: MockedBot): - 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=["1"], - ) - request: Request = bot.get_request() - assert request.method == "getCustomEmojiStickers" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( GetCustomEmojiStickers, @@ -53,7 +27,5 @@ class TestGetCustomEmojiStickers: response: List[Sticker] = await bot.get_custom_emoji_stickers( custom_emoji_ids=["1", "2"], ) - request: Request = bot.get_request() - assert request.method == "getCustomEmojiStickers" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_file.py b/tests/test_api/test_methods/test_get_file.py index eb95cd20..9c54ac38 100644 --- a/tests/test_api/test_methods/test_get_file.py +++ b/tests/test_api/test_methods/test_get_file.py @@ -4,22 +4,11 @@ from tests.mocked_bot import MockedBot class TestGetFile: - async def test_method(self, bot: MockedBot): - 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() - assert request.method == "getFile" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): 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() - assert request.method == "getFile" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_forum_topic_icon_stickers.py b/tests/test_api/test_methods/test_get_forum_topic_icon_stickers.py index c9a1455a..ab280abc 100644 --- a/tests/test_api/test_methods/test_get_forum_topic_icon_stickers.py +++ b/tests/test_api/test_methods/test_get_forum_topic_icon_stickers.py @@ -6,20 +6,9 @@ from tests.mocked_bot import MockedBot class TestGetForumTopicIconStickers: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(GetForumTopicIconStickers, ok=True, result=[]) - - response: List[Sticker] = await GetForumTopicIconStickers() - request: Request = bot.get_request() - assert request.method == "getForumTopicIconStickers" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(GetForumTopicIconStickers, ok=True, result=[]) response: List[Sticker] = await bot.get_forum_topic_icon_stickers() - request: Request = bot.get_request() - assert request.method == "getForumTopicIconStickers" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_game_high_scores.py b/tests/test_api/test_methods/test_get_game_high_scores.py index fe84d21d..9dfaf5f4 100644 --- a/tests/test_api/test_methods/test_get_game_high_scores.py +++ b/tests/test_api/test_methods/test_get_game_high_scores.py @@ -6,22 +6,6 @@ from tests.mocked_bot import MockedBot class TestGetGameHighScores: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - GetGameHighScores, - ok=True, - result=[ - GameHighScore( - position=1, user=User(id=42, is_bot=False, first_name="User"), score=42 - ) - ], - ) - - response: List[GameHighScore] = await GetGameHighScores(user_id=42) - request: Request = bot.get_request() - assert request.method == "getGameHighScores" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( GetGameHighScores, @@ -34,6 +18,5 @@ class TestGetGameHighScores: ) response: List[GameHighScore] = await bot.get_game_high_scores(user_id=42) - request: Request = bot.get_request() - assert request.method == "getGameHighScores" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_me.py b/tests/test_api/test_methods/test_get_me.py index 70f274ec..e84ccd1e 100644 --- a/tests/test_api/test_methods/test_get_me.py +++ b/tests/test_api/test_methods/test_get_me.py @@ -4,25 +4,12 @@ from tests.mocked_bot import MockedBot class TestGetMe: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - GetMe, ok=True, result=User(id=42, is_bot=False, first_name="User") - ) - - response: User = await GetMe() - request: Request = bot.get_request() - assert request.method == "getMe" - assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( GetMe, ok=True, result=User(id=42, is_bot=False, first_name="User") ) response: User = await bot.get_me() - request: Request = bot.get_request() - assert request.method == "getMe" - assert request.data == {} + request = bot.get_request() assert response == prepare_result.result async def test_me_property(self, bot: MockedBot): diff --git a/tests/test_api/test_methods/test_get_my_commands.py b/tests/test_api/test_methods/test_get_my_commands.py index c627ff11..41a7a7d0 100644 --- a/tests/test_api/test_methods/test_get_my_commands.py +++ b/tests/test_api/test_methods/test_get_my_commands.py @@ -6,18 +6,9 @@ from tests.mocked_bot import MockedBot class TestGetMyCommands: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(GetMyCommands, ok=True, result=None) - - response: List[BotCommand] = await GetMyCommands() - request: Request = bot.get_request() - assert request.method == "getMyCommands" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(GetMyCommands, ok=True, result=None) response: List[BotCommand] = await bot.get_my_commands() - request: Request = bot.get_request() - assert request.method == "getMyCommands" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_my_default_administrator_rights.py b/tests/test_api/test_methods/test_get_my_default_administrator_rights.py index 7e843686..bd18199c 100644 --- a/tests/test_api/test_methods/test_get_my_default_administrator_rights.py +++ b/tests/test_api/test_methods/test_get_my_default_administrator_rights.py @@ -4,28 +4,6 @@ from tests.mocked_bot import MockedBot class TestGetMyDefaultAdministratorRights: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - GetMyDefaultAdministratorRights, - ok=True, - result=ChatAdministratorRights( - is_anonymous=False, - can_manage_chat=False, - can_delete_messages=False, - can_manage_video_chats=False, - can_restrict_members=False, - can_promote_members=False, - can_change_info=False, - can_invite_users=False, - ), - ) - - response: ChatAdministratorRights = await GetMyDefaultAdministratorRights() - request: Request = bot.get_request() - assert request.method == "getMyDefaultAdministratorRights" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( GetMyDefaultAdministratorRights, @@ -43,7 +21,5 @@ class TestGetMyDefaultAdministratorRights: ) response: ChatAdministratorRights = await bot.get_my_default_administrator_rights() - request: Request = bot.get_request() - assert request.method == "getMyDefaultAdministratorRights" - # assert request.data == {} + request = bot.get_request() 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 index 8a861ecb..32277b43 100644 --- a/tests/test_api/test_methods/test_get_my_description.py +++ b/tests/test_api/test_methods/test_get_my_description.py @@ -4,22 +4,11 @@ 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" + request = bot.get_request() 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 index 5d362fdb..3b78be89 100644 --- a/tests/test_api/test_methods/test_get_my_short_description.py +++ b/tests/test_api/test_methods/test_get_my_short_description.py @@ -4,22 +4,11 @@ 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" + request = bot.get_request() assert response == prepare_result.result 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 d8e7ca45..dd15e795 100644 --- a/tests/test_api/test_methods/test_get_sticker_set.py +++ b/tests/test_api/test_methods/test_get_sticker_set.py @@ -4,35 +4,6 @@ from tests.mocked_bot import MockedBot class TestGetStickerSet: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - GetStickerSet, - ok=True, - result=StickerSet( - name="test", - title="test", - is_animated=False, - is_video=False, - stickers=[ - Sticker( - file_id="file if", - width=42, - height=42, - is_animated=False, - is_video=False, - file_unique_id="file id", - type="regular", - ) - ], - sticker_type="regular", - ), - ) - - response: StickerSet = await GetStickerSet(name="test") - request: Request = bot.get_request() - assert request.method == "getStickerSet" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( GetStickerSet, @@ -58,6 +29,5 @@ class TestGetStickerSet: ) response: StickerSet = await bot.get_sticker_set(name="test") - request: Request = bot.get_request() - assert request.method == "getStickerSet" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_updates.py b/tests/test_api/test_methods/test_get_updates.py index b4cd11b9..ad86ceed 100644 --- a/tests/test_api/test_methods/test_get_updates.py +++ b/tests/test_api/test_methods/test_get_updates.py @@ -6,18 +6,9 @@ from tests.mocked_bot import MockedBot class TestGetUpdates: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(GetUpdates, ok=True, result=[Update(update_id=42)]) - - response: List[Update] = await GetUpdates() - request: Request = bot.get_request() - assert request.method == "getUpdates" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(GetUpdates, ok=True, result=[Update(update_id=42)]) response: List[Update] = await bot.get_updates() - request: Request = bot.get_request() - assert request.method == "getUpdates" + request = bot.get_request() 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 cbfd0dbc..ed5329cc 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 @@ -4,23 +4,6 @@ from tests.mocked_bot import MockedBot class TestGetUserProfilePhotos: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - GetUserProfilePhotos, - ok=True, - result=UserProfilePhotos( - total_count=1, - photos=[ - [PhotoSize(file_id="file_id", width=42, height=42, file_unique_id="file id")] - ], - ), - ) - - response: UserProfilePhotos = await GetUserProfilePhotos(user_id=42) - request: Request = bot.get_request() - assert request.method == "getUserProfilePhotos" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( GetUserProfilePhotos, @@ -34,6 +17,5 @@ class TestGetUserProfilePhotos: ) response: UserProfilePhotos = await bot.get_user_profile_photos(user_id=42) - request: Request = bot.get_request() - assert request.method == "getUserProfilePhotos" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_get_webhook_info.py b/tests/test_api/test_methods/test_get_webhook_info.py index 06d11dbc..d6723411 100644 --- a/tests/test_api/test_methods/test_get_webhook_info.py +++ b/tests/test_api/test_methods/test_get_webhook_info.py @@ -4,20 +4,6 @@ from tests.mocked_bot import MockedBot class TestGetWebhookInfo: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - GetWebhookInfo, - ok=True, - result=WebhookInfo( - url="https://example.com", has_custom_certificate=False, pending_update_count=0 - ), - ) - - response: WebhookInfo = await GetWebhookInfo() - request: Request = bot.get_request() - assert request.method == "getWebhookInfo" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( GetWebhookInfo, @@ -28,6 +14,5 @@ class TestGetWebhookInfo: ) response: WebhookInfo = await bot.get_webhook_info() - request: Request = bot.get_request() - assert request.method == "getWebhookInfo" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_hide_general_forum_topic.py b/tests/test_api/test_methods/test_hide_general_forum_topic.py index 51e6684b..d142ae5e 100644 --- a/tests/test_api/test_methods/test_hide_general_forum_topic.py +++ b/tests/test_api/test_methods/test_hide_general_forum_topic.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestHideGeneralForumTopic: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(HideGeneralForumTopic, ok=True, result=True) - - response: bool = await bot(HideGeneralForumTopic(chat_id=42)) - request: Request = bot.get_request() - assert request.method == "hideGeneralForumTopic" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(HideGeneralForumTopic, ok=True, result=True) response: bool = await bot.hide_general_forum_topic(chat_id=42) - request: Request = bot.get_request() - assert request.method == "hideGeneralForumTopic" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_leave_chat.py b/tests/test_api/test_methods/test_leave_chat.py index db771a7d..e65902ca 100644 --- a/tests/test_api/test_methods/test_leave_chat.py +++ b/tests/test_api/test_methods/test_leave_chat.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestLeaveChat: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(LeaveChat, ok=True, result=True) - - response: bool = await LeaveChat(chat_id=-42) - request: Request = bot.get_request() - assert request.method == "leaveChat" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(LeaveChat, ok=True, result=True) response: bool = await bot.leave_chat(chat_id=-42) - request: Request = bot.get_request() - assert request.method == "leaveChat" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_log_out.py b/tests/test_api/test_methods/test_log_out.py index fd09d116..bb066579 100644 --- a/tests/test_api/test_methods/test_log_out.py +++ b/tests/test_api/test_methods/test_log_out.py @@ -3,20 +3,9 @@ from tests.mocked_bot import MockedBot class TestLogOut: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(LogOut, ok=True, result=True) - - response: bool = await LogOut() - request: Request = bot.get_request() - assert request.method == "logOut" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(LogOut, ok=True, result=True) response: bool = await bot.log_out() - request: Request = bot.get_request() - assert request.method == "logOut" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_pin_chat_message.py b/tests/test_api/test_methods/test_pin_chat_message.py index f74cd4cd..5f8a0eba 100644 --- a/tests/test_api/test_methods/test_pin_chat_message.py +++ b/tests/test_api/test_methods/test_pin_chat_message.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestPinChatMessage: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(PinChatMessage, ok=True, result=True) - - response: bool = await PinChatMessage(chat_id=-42, message_id=42) - request: Request = bot.get_request() - assert request.method == "pinChatMessage" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(PinChatMessage, ok=True, result=True) response: bool = await bot.pin_chat_message(chat_id=-42, message_id=42) - request: Request = bot.get_request() - assert request.method == "pinChatMessage" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_promote_chat_member.py b/tests/test_api/test_methods/test_promote_chat_member.py index 6721eb1f..8fa4a08f 100644 --- a/tests/test_api/test_methods/test_promote_chat_member.py +++ b/tests/test_api/test_methods/test_promote_chat_member.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestPromoteChatMember: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(PromoteChatMember, ok=True, result=True) - - response: bool = await PromoteChatMember(chat_id=-42, user_id=42) - request: Request = bot.get_request() - assert request.method == "promoteChatMember" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(PromoteChatMember, ok=True, result=True) response: bool = await bot.promote_chat_member(chat_id=-42, user_id=42) - request: Request = bot.get_request() - assert request.method == "promoteChatMember" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_reopen_forum_topic.py b/tests/test_api/test_methods/test_reopen_forum_topic.py index 2c4a33b2..ff4c9b66 100644 --- a/tests/test_api/test_methods/test_reopen_forum_topic.py +++ b/tests/test_api/test_methods/test_reopen_forum_topic.py @@ -3,18 +3,6 @@ from tests.mocked_bot import MockedBot class TestReopenForumTopic: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(ReopenForumTopic, ok=True, result=None) - - response: bool = await ReopenForumTopic( - chat_id=42, - message_thread_id=42, - ) - request: Request = bot.get_request() - assert request.method == "reopenForumTopic" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(ReopenForumTopic, ok=True, result=None) @@ -22,7 +10,5 @@ class TestReopenForumTopic: chat_id=42, message_thread_id=42, ) - request: Request = bot.get_request() - assert request.method == "reopenForumTopic" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_reopen_general_forum_topic.py b/tests/test_api/test_methods/test_reopen_general_forum_topic.py index af1abf55..6eceb7d7 100644 --- a/tests/test_api/test_methods/test_reopen_general_forum_topic.py +++ b/tests/test_api/test_methods/test_reopen_general_forum_topic.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestReopenGeneralForumTopic: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(ReopenGeneralForumTopic, ok=True, result=True) - - response: bool = await bot(ReopenGeneralForumTopic(chat_id=42)) - request: Request = bot.get_request() - assert request.method == "reopenGeneralForumTopic" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(ReopenGeneralForumTopic, ok=True, result=True) response: bool = await bot.reopen_general_forum_topic(chat_id=42) - request: Request = bot.get_request() - assert request.method == "reopenGeneralForumTopic" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_restrict_chat_member.py b/tests/test_api/test_methods/test_restrict_chat_member.py index ca9ee4c8..716fa23d 100644 --- a/tests/test_api/test_methods/test_restrict_chat_member.py +++ b/tests/test_api/test_methods/test_restrict_chat_member.py @@ -4,22 +4,11 @@ from tests.mocked_bot import MockedBot class TestRestrictChatMember: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(RestrictChatMember, ok=True, result=True) - - response: bool = await RestrictChatMember( - chat_id=-42, user_id=42, permissions=ChatPermissions() - ) - request: Request = bot.get_request() - assert request.method == "restrictChatMember" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(RestrictChatMember, ok=True, result=True) response: bool = await bot.restrict_chat_member( chat_id=-42, user_id=42, permissions=ChatPermissions() ) - request: Request = bot.get_request() - assert request.method == "restrictChatMember" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_revoke_chat_invite_link.py b/tests/test_api/test_methods/test_revoke_chat_invite_link.py index 84ca46b5..9d8c26b3 100644 --- a/tests/test_api/test_methods/test_revoke_chat_invite_link.py +++ b/tests/test_api/test_methods/test_revoke_chat_invite_link.py @@ -4,27 +4,6 @@ from tests.mocked_bot import MockedBot class TestRevokeChatInviteLink: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - RevokeChatInviteLink, - ok=True, - result=ChatInviteLink( - invite_link="https://t.me/username", - creator=User(id=42, is_bot=False, first_name="User"), - is_primary=False, - is_revoked=True, - creates_join_request=False, - ), - ) - - response: ChatInviteLink = await RevokeChatInviteLink( - chat_id=-42, - invite_link="https://t.me/username", - ) - request: Request = bot.get_request() - assert request.method == "revokeChatInviteLink" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( RevokeChatInviteLink, @@ -42,6 +21,5 @@ class TestRevokeChatInviteLink: chat_id=-42, invite_link="https://t.me/username", ) - request: Request = bot.get_request() - assert request.method == "revokeChatInviteLink" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_animation.py b/tests/test_api/test_methods/test_send_animation.py index 5ec7f52a..b9f5508f 100644 --- a/tests/test_api/test_methods/test_send_animation.py +++ b/tests/test_api/test_methods/test_send_animation.py @@ -6,25 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendAnimation: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - SendAnimation, - ok=True, - result=Message( - message_id=42, - date=datetime.datetime.now(), - animation=Animation( - file_id="file id", width=42, height=42, duration=0, file_unique_id="file id" - ), - chat=Chat(id=42, type="private"), - ), - ) - - response: Message = await SendAnimation(chat_id=42, animation="file id") - request: Request = bot.get_request() - assert request.method == "sendAnimation" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendAnimation, @@ -40,6 +21,5 @@ class TestSendAnimation: ) response: Message = await bot.send_animation(chat_id=42, animation="file id") - request: Request = bot.get_request() - assert request.method == "sendAnimation" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_audio.py b/tests/test_api/test_methods/test_send_audio.py index 95621f10..b5b2a32b 100644 --- a/tests/test_api/test_methods/test_send_audio.py +++ b/tests/test_api/test_methods/test_send_audio.py @@ -6,23 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendAudio: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - SendAudio, - ok=True, - result=Message( - message_id=42, - date=datetime.datetime.now(), - audio=Audio(file_id="file id", duration=42, file_unique_id="file id"), - chat=Chat(id=42, type="private"), - ), - ) - - response: Message = await SendAudio(chat_id=42, audio="file id") - request: Request = bot.get_request() - assert request.method == "sendAudio" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendAudio, @@ -36,6 +19,5 @@ class TestSendAudio: ) response: Message = await bot.send_audio(chat_id=42, audio="file id") - request: Request = bot.get_request() - assert request.method == "sendAudio" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_chat_action.py b/tests/test_api/test_methods/test_send_chat_action.py index a37568fe..3c2d8ecb 100644 --- a/tests/test_api/test_methods/test_send_chat_action.py +++ b/tests/test_api/test_methods/test_send_chat_action.py @@ -4,27 +4,9 @@ from tests.mocked_bot import MockedBot class TestSendChatAction: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendChatAction, ok=True, result=True) - - response: bool = await SendChatAction(chat_id=42, action="typing") - request: Request = bot.get_request() - assert request.method == "sendChatAction" - assert response == prepare_result.result - - async def test_bot_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendChatAction, ok=True, result=True) - - response: bool = await bot.send_chat_action(chat_id=42, action="typing") - request: Request = bot.get_request() - assert request.method == "sendChatAction" - assert response == prepare_result.result - async def test_chat_action_class(self, bot: MockedBot): prepare_result = bot.add_result_for(SendChatAction, ok=True, result=True) response: bool = await bot.send_chat_action(chat_id=42, action=ChatAction.TYPING) - request: Request = bot.get_request() - assert request.method == "sendChatAction" - assert request.data["action"] == "typing" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_contact.py b/tests/test_api/test_methods/test_send_contact.py index 97f6981c..83c6f3ae 100644 --- a/tests/test_api/test_methods/test_send_contact.py +++ b/tests/test_api/test_methods/test_send_contact.py @@ -6,23 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendContact: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - SendContact, - ok=True, - result=Message( - message_id=42, - date=datetime.datetime.now(), - contact=Contact(phone_number="911", first_name="911"), - chat=Chat(id=42, type="private"), - ), - ) - - response: Message = await SendContact(chat_id=42, phone_number="911", first_name="911") - request: Request = bot.get_request() - assert request.method == "sendContact" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendContact, @@ -38,6 +21,5 @@ class TestSendContact: response: Message = await bot.send_contact( chat_id=42, phone_number="911", first_name="911" ) - request: Request = bot.get_request() - assert request.method == "sendContact" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_dice.py b/tests/test_api/test_methods/test_send_dice.py index 3dea06c4..35196ee6 100644 --- a/tests/test_api/test_methods/test_send_dice.py +++ b/tests/test_api/test_methods/test_send_dice.py @@ -4,18 +4,9 @@ from tests.mocked_bot import MockedBot class TestSendDice: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SendDice, ok=True, result=None) - - response: Message = await SendDice(chat_id=42) - request: Request = bot.get_request() - assert request.method == "sendDice" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(SendDice, ok=True, result=None) response: Message = await bot.send_dice(chat_id=42) - request: Request = bot.get_request() - assert request.method == "sendDice" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_document.py b/tests/test_api/test_methods/test_send_document.py index cf758815..54c0d712 100644 --- a/tests/test_api/test_methods/test_send_document.py +++ b/tests/test_api/test_methods/test_send_document.py @@ -6,23 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendDocument: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - SendDocument, - ok=True, - result=Message( - message_id=42, - date=datetime.datetime.now(), - document=Document(file_id="file id", file_unique_id="file id"), - chat=Chat(id=42, type="private"), - ), - ) - - response: Message = await SendDocument(chat_id=42, document="file id") - request: Request = bot.get_request() - assert request.method == "sendDocument" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendDocument, @@ -36,6 +19,5 @@ class TestSendDocument: ) response: Message = await bot.send_document(chat_id=42, document="file id") - request: Request = bot.get_request() - assert request.method == "sendDocument" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_game.py b/tests/test_api/test_methods/test_send_game.py index 57ab645f..a0d1bb84 100644 --- a/tests/test_api/test_methods/test_send_game.py +++ b/tests/test_api/test_methods/test_send_game.py @@ -6,29 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendGame: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - SendGame, - ok=True, - result=Message( - message_id=42, - date=datetime.datetime.now(), - game=Game( - title="title", - description="description", - photo=[ - PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id") - ], - ), - chat=Chat(id=42, type="private"), - ), - ) - - response: Message = await SendGame(chat_id=42, game_short_name="game") - request: Request = bot.get_request() - assert request.method == "sendGame" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendGame, @@ -48,6 +25,5 @@ class TestSendGame: ) response: Message = await bot.send_game(chat_id=42, game_short_name="game") - request: Request = bot.get_request() - assert request.method == "sendGame" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_invoice.py b/tests/test_api/test_methods/test_send_invoice.py index e88d9acf..650c4a19 100644 --- a/tests/test_api/test_methods/test_send_invoice.py +++ b/tests/test_api/test_methods/test_send_invoice.py @@ -6,38 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendInvoice: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - SendInvoice, - ok=True, - result=Message( - message_id=42, - date=datetime.datetime.now(), - invoice=Invoice( - title="test", - description="test", - start_parameter="brilliant", - currency="BTC", - total_amount=1, - ), - chat=Chat(id=42, type="private"), - ), - ) - - response: Message = await SendInvoice( - chat_id=42, - title="test", - description="test", - payload="payload", - provider_token="TEST:token", - start_parameter="brilliant", - currency="BTC", - prices=[LabeledPrice(amount=1, label="test")], - ) - request: Request = bot.get_request() - assert request.method == "sendInvoice" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendInvoice, @@ -66,6 +34,5 @@ class TestSendInvoice: currency="BTC", prices=[LabeledPrice(amount=1, label="test")], ) - request: Request = bot.get_request() - assert request.method == "sendInvoice" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_send_location.py b/tests/test_api/test_methods/test_send_location.py index 7429f0b8..b662106d 100644 --- a/tests/test_api/test_methods/test_send_location.py +++ b/tests/test_api/test_methods/test_send_location.py @@ -6,23 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendLocation: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - SendLocation, - ok=True, - result=Message( - message_id=42, - date=datetime.datetime.now(), - location=Location(longitude=3.14, latitude=3.14), - chat=Chat(id=42, type="private"), - ), - ) - - response: Message = await SendLocation(chat_id=42, latitude=3.14, longitude=3.14) - request: Request = bot.get_request() - assert request.method == "sendLocation" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendLocation, @@ -36,6 +19,5 @@ class TestSendLocation: ) response: Message = await bot.send_location(chat_id=42, latitude=3.14, longitude=3.14) - request: Request = bot.get_request() - assert request.method == "sendLocation" + request = bot.get_request() assert response == prepare_result.result 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 149937d4..759184f7 100644 --- a/tests/test_api/test_methods/test_send_media_group.py +++ b/tests/test_api/test_methods/test_send_media_group.py @@ -15,47 +15,6 @@ from tests.mocked_bot import MockedBot class TestSendMediaGroup: - async def test_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, 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, - file_unique_id="file id", - ), - media_group_id="media group", - chat=Chat(id=42, type="private"), - ), - ], - ) - - response: List[Message] = await SendMediaGroup( - 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 - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendMediaGroup, @@ -93,6 +52,5 @@ class TestSendMediaGroup: InputMediaVideo(media=BufferedInputFile(b"", "video.mp4")), ], ) - request: Request = bot.get_request() - assert request.method == "sendMediaGroup" + request = bot.get_request() 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 5ebe604a..0210d73f 100644 --- a/tests/test_api/test_methods/test_send_message.py +++ b/tests/test_api/test_methods/test_send_message.py @@ -6,23 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendMessage: - async def test_method(self, bot: MockedBot): - 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=42, text="test") - request: Request = bot.get_request() - assert request.method == "sendMessage" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendMessage, @@ -36,8 +19,7 @@ class TestSendMessage: ) response: Message = await bot.send_message(chat_id=42, text="test") - request: Request = bot.get_request() - assert request.method == "sendMessage" + request = bot.get_request() assert response == prepare_result.result async def test_force_reply(self): diff --git a/tests/test_api/test_methods/test_send_photo.py b/tests/test_api/test_methods/test_send_photo.py index 0e955dd1..528a04a1 100644 --- a/tests/test_api/test_methods/test_send_photo.py +++ b/tests/test_api/test_methods/test_send_photo.py @@ -6,25 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendPhoto: - async def test_method(self, bot: MockedBot): - 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, file_unique_id="file id") - ], - chat=Chat(id=42, type="private"), - ), - ) - - response: Message = await SendPhoto(chat_id=42, photo="file id") - request: Request = bot.get_request() - assert request.method == "sendPhoto" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendPhoto, @@ -40,6 +21,5 @@ class TestSendPhoto: ) response: Message = await bot.send_photo(chat_id=42, photo="file id") - request: Request = bot.get_request() - assert request.method == "sendPhoto" + request = bot.get_request() 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 9f67af14..4bc791fc 100644 --- a/tests/test_api/test_methods/test_send_poll.py +++ b/tests/test_api/test_methods/test_send_poll.py @@ -6,38 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendPoll: - async def test_method(self, bot: MockedBot): - 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, - is_anonymous=False, - type="quiz", - allows_multiple_answers=False, - total_voter_count=0, - correct_option_id=0, - ), - chat=Chat(id=42, type="private"), - ), - ) - - response: Message = await SendPoll( - chat_id=42, question="Q?", options=["A", "B"], correct_option_id=0, type="quiz" - ) - request: Request = bot.get_request() - assert request.method == "sendPoll" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendPoll, @@ -66,6 +34,5 @@ class TestSendPoll: response: Message = await bot.send_poll( chat_id=42, question="Q?", options=["A", "B"], correct_option_id=0, type="quiz" ) - request: Request = bot.get_request() - assert request.method == "sendPoll" + request = bot.get_request() 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 b19313fc..af847e08 100644 --- a/tests/test_api/test_methods/test_send_sticker.py +++ b/tests/test_api/test_methods/test_send_sticker.py @@ -6,31 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendSticker: - async def test_method(self, bot: MockedBot): - 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, - is_video=False, - file_unique_id="file id", - type="regular", - ), - chat=Chat(id=42, type="private"), - ), - ) - - response: Message = await SendSticker(chat_id=42, sticker="file id") - request: Request = bot.get_request() - assert request.method == "sendSticker" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendSticker, @@ -52,6 +27,5 @@ class TestSendSticker: ) response: Message = await bot.send_sticker(chat_id=42, sticker="file id") - request: Request = bot.get_request() - assert request.method == "sendSticker" + request = bot.get_request() 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 6a529fcb..4234c7a5 100644 --- a/tests/test_api/test_methods/test_send_venue.py +++ b/tests/test_api/test_methods/test_send_venue.py @@ -6,35 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendVenue: - async def test_method(self, bot: MockedBot): - 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=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 response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendVenue, @@ -60,6 +31,5 @@ class TestSendVenue: address="Under the stairs, 4 Privet Drive, " "Little Whinging, Surrey, England, Great Britain", ) - request: Request = bot.get_request() - assert request.method == "sendVenue" + request = bot.get_request() 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 86e3c413..16572b3e 100644 --- a/tests/test_api/test_methods/test_send_video.py +++ b/tests/test_api/test_methods/test_send_video.py @@ -6,25 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendVideo: - async def test_method(self, bot: MockedBot): - 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, file_unique_id="file id" - ), - chat=Chat(id=42, type="private"), - ), - ) - - response: Message = await SendVideo(chat_id=42, video="file id") - request: Request = bot.get_request() - assert request.method == "sendVideo" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendVideo, @@ -40,6 +21,5 @@ class TestSendVideo: ) response: Message = await bot.send_video(chat_id=42, video="file id") - request: Request = bot.get_request() - assert request.method == "sendVideo" + request = bot.get_request() 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 bec233c7..3da752f5 100644 --- a/tests/test_api/test_methods/test_send_video_note.py +++ b/tests/test_api/test_methods/test_send_video_note.py @@ -6,29 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendVideoNote: - async def test_method(self, bot: MockedBot): - 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, file_unique_id="file id" - ), - chat=Chat(id=42, type="private"), - ), - ) - - response: Message = await SendVideoNote( - chat_id=42, - video_note="file id", - thumbnail=BufferedInputFile(b"", "file.png"), - ) - request: Request = bot.get_request() - assert request.method == "sendVideoNote" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendVideoNote, @@ -48,6 +25,5 @@ class TestSendVideoNote: video_note="file id", thumbnail=BufferedInputFile(b"", "file.png"), ) - request: Request = bot.get_request() - assert request.method == "sendVideoNote" + request = bot.get_request() 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 917a645b..2c55b07d 100644 --- a/tests/test_api/test_methods/test_send_voice.py +++ b/tests/test_api/test_methods/test_send_voice.py @@ -6,23 +6,6 @@ from tests.mocked_bot import MockedBot class TestSendVoice: - async def test_method(self, bot: MockedBot): - 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, file_unique_id="file id"), - chat=Chat(id=42, type="private"), - ), - ) - - response: Message = await SendVoice(chat_id=42, voice="file id") - request: Request = bot.get_request() - assert request.method == "sendVoice" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( SendVoice, @@ -36,6 +19,5 @@ class TestSendVoice: ) response: Message = await bot.send_voice(chat_id=42, voice="file id") - request: Request = bot.get_request() - assert request.method == "sendVoice" + request = bot.get_request() assert response == prepare_result.result 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 index 7581e37d..7a759618 100644 --- 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 @@ -3,22 +3,11 @@ from tests.mocked_bot import MockedBot class TestSetChatTitle: - 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 - 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" + request = bot.get_request() 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 0a11d7e3..eb9885d2 100644 --- a/tests/test_api/test_methods/test_set_chat_description.py +++ b/tests/test_api/test_methods/test_set_chat_description.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestSetChatDescription: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatDescription, ok=True, result=True) - - response: bool = await SetChatDescription(chat_id=-42, description="awesome chat") - request: Request = bot.get_request() - assert request.method == "setChatDescription" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(SetChatDescription, ok=True, result=True) response: bool = await bot.set_chat_description(chat_id=-42, description="awesome chat") - request: Request = bot.get_request() - assert request.method == "setChatDescription" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_chat_menu_button.py b/tests/test_api/test_methods/test_set_chat_menu_button.py index 74923a5f..1cac7081 100644 --- a/tests/test_api/test_methods/test_set_chat_menu_button.py +++ b/tests/test_api/test_methods/test_set_chat_menu_button.py @@ -3,20 +3,9 @@ from tests.mocked_bot import MockedBot class TestSetChatMenuButton: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatMenuButton, ok=True, result=True) - - response: bool = await SetChatMenuButton() - request: Request = bot.get_request() - assert request.method == "setChatMenuButton" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(SetChatMenuButton, ok=True, result=True) response: bool = await bot.set_chat_menu_button() - request: Request = bot.get_request() - assert request.method == "setChatMenuButton" - # assert request.data == {} + request = bot.get_request() 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 73f488c1..1dcd64b9 100644 --- a/tests/test_api/test_methods/test_set_chat_permissions.py +++ b/tests/test_api/test_methods/test_set_chat_permissions.py @@ -4,22 +4,11 @@ from tests.mocked_bot import MockedBot class TestSetChatPermissions: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatPermissions, ok=True, result=True) - - response: bool = await SetChatPermissions( - chat_id=-42, permissions=ChatPermissions(can_send_messages=False) - ) - request: Request = bot.get_request() - assert request.method == "setChatPermissions" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(SetChatPermissions, ok=True, result=True) 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" + request = bot.get_request() 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 e17126f6..68e0bbbc 100644 --- a/tests/test_api/test_methods/test_set_chat_photo.py +++ b/tests/test_api/test_methods/test_set_chat_photo.py @@ -4,22 +4,11 @@ from tests.mocked_bot import MockedBot class TestSetChatPhoto: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatPhoto, ok=True, result=True) - - response: bool = await SetChatPhoto( - chat_id=-42, photo=BufferedInputFile(b"", filename="file.png") - ) - request: Request = bot.get_request() - assert request.method == "setChatPhoto" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(SetChatPhoto, ok=True, result=True) 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" + request = bot.get_request() 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 cba3ba1f..c87be0cd 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 @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestSetChatStickerSet: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatStickerSet, ok=True, result=True) - - response: bool = await SetChatStickerSet(chat_id=-42, sticker_set_name="test") - request: Request = bot.get_request() - assert request.method == "setChatStickerSet" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(SetChatStickerSet, ok=True, result=True) response: bool = await bot.set_chat_sticker_set(chat_id=-42, sticker_set_name="test") - request: Request = bot.get_request() - assert request.method == "setChatStickerSet" + request = bot.get_request() 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 03f37b15..e45d24f2 100644 --- a/tests/test_api/test_methods/test_set_chat_title.py +++ b/tests/test_api/test_methods/test_set_chat_title.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestSetChatTitle: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetChatTitle, ok=True, result=True) - - response: bool = await SetChatTitle(chat_id=-42, title="test chat") - request: Request = bot.get_request() - assert request.method == "setChatTitle" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(SetChatTitle, ok=True, result=True) response: bool = await bot.set_chat_title(chat_id=-42, title="test chat") - request: Request = bot.get_request() - assert request.method == "setChatTitle" + request = bot.get_request() assert response == prepare_result.result 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 index 20ad08c9..75d056df 100644 --- 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 @@ -3,18 +3,6 @@ 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 @@ -23,6 +11,5 @@ class TestSetCustomEmojiStickerSetThumbnail: 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" + request = bot.get_request() 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 4e739a89..6da8e123 100644 --- a/tests/test_api/test_methods/test_set_game_score.py +++ b/tests/test_api/test_methods/test_set_game_score.py @@ -6,22 +6,11 @@ from tests.mocked_bot import MockedBot class TestSetGameScore: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetGameScore, ok=True, result=True) - - 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 response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(SetGameScore, ok=True, result=True) 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" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_my_commands.py b/tests/test_api/test_methods/test_set_my_commands.py index 35f62e0c..16066b73 100644 --- a/tests/test_api/test_methods/test_set_my_commands.py +++ b/tests/test_api/test_methods/test_set_my_commands.py @@ -4,23 +4,11 @@ from tests.mocked_bot import MockedBot class TestSetMyCommands: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetMyCommands, ok=True, result=None) - - response: bool = await SetMyCommands( - commands=[BotCommand(command="command", description="Bot command")], - ) - request: Request = bot.get_request() - assert request.method == "setMyCommands" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(SetMyCommands, ok=True, result=None) response: bool = await bot.set_my_commands( commands=[], ) - request: Request = bot.get_request() - assert request.method == "setMyCommands" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_set_my_default_administrator_rights.py b/tests/test_api/test_methods/test_set_my_default_administrator_rights.py index eb24a531..ac8e5d42 100644 --- a/tests/test_api/test_methods/test_set_my_default_administrator_rights.py +++ b/tests/test_api/test_methods/test_set_my_default_administrator_rights.py @@ -3,20 +3,9 @@ from tests.mocked_bot import MockedBot class TestSetMyDefaultAdministratorRights: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetMyDefaultAdministratorRights, ok=True, result=True) - - response: bool = await SetMyDefaultAdministratorRights() - request: Request = bot.get_request() - assert request.method == "setMyDefaultAdministratorRights" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(SetMyDefaultAdministratorRights, ok=True, result=True) response: bool = await bot.set_my_default_administrator_rights() - request: Request = bot.get_request() - assert request.method == "setMyDefaultAdministratorRights" - # assert request.data == {} + request = bot.get_request() 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 index 843b66d2..05e9bd7c 100644 --- a/tests/test_api/test_methods/test_set_my_description.py +++ b/tests/test_api/test_methods/test_set_my_description.py @@ -3,18 +3,9 @@ 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" + request = bot.get_request() 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 index c985dee2..9b40721d 100644 --- a/tests/test_api/test_methods/test_set_my_short_description.py +++ b/tests/test_api/test_methods/test_set_my_short_description.py @@ -3,18 +3,9 @@ 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" + request = bot.get_request() 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 cdc77778..ecc2425b 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 @@ -4,20 +4,11 @@ from tests.mocked_bot import MockedBot class TestSetPassportDataErrors: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetPassportDataErrors, ok=True, result=True) - - response: bool = await SetPassportDataErrors(user_id=42, errors=[PassportElementError()]) - request: Request = bot.get_request() - assert request.method == "setPassportDataErrors" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(SetPassportDataErrors, ok=True, result=True) response: bool = await bot.set_passport_data_errors( user_id=42, errors=[PassportElementError()] ) - request: Request = bot.get_request() - assert request.method == "setPassportDataErrors" + request = bot.get_request() 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 index b5ae829c..76984264 100644 --- a/tests/test_api/test_methods/test_set_sticker_emoji_list.py +++ b/tests/test_api/test_methods/test_set_sticker_emoji_list.py @@ -3,18 +3,9 @@ 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" + request = bot.get_request() 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 index 7cea6cae..ff9b31e4 100644 --- a/tests/test_api/test_methods/test_set_sticker_keywords.py +++ b/tests/test_api/test_methods/test_set_sticker_keywords.py @@ -3,18 +3,9 @@ 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" + request = bot.get_request() 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 index dec92d19..fa041461 100644 --- a/tests/test_api/test_methods/test_set_sticker_mask_position.py +++ b/tests/test_api/test_methods/test_set_sticker_mask_position.py @@ -3,18 +3,9 @@ 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" + request = bot.get_request() 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 c67c7be5..ce06652c 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 @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestSetStickerPositionInSet: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetStickerPositionInSet, ok=True, result=True) - - response: bool = await SetStickerPositionInSet(sticker="sticker", position=42) - request: Request = bot.get_request() - assert request.method == "setStickerPositionInSet" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(SetStickerPositionInSet, ok=True, result=True) response: bool = await bot.set_sticker_position_in_set(sticker="sticker", position=42) - request: Request = bot.get_request() - assert request.method == "setStickerPositionInSet" + request = bot.get_request() 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 index 41795be6..6c33f862 100644 --- a/tests/test_api/test_methods/test_set_sticker_set_thumbnail.py +++ b/tests/test_api/test_methods/test_set_sticker_set_thumbnail.py @@ -3,20 +3,9 @@ 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 == {} + request = bot.get_request() 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 index 1dc306bc..2a9645cb 100644 --- a/tests/test_api/test_methods/test_set_sticker_set_title.py +++ b/tests/test_api/test_methods/test_set_sticker_set_title.py @@ -3,18 +3,9 @@ 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" + request = bot.get_request() 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 cfa291c3..c38a2bfa 100644 --- a/tests/test_api/test_methods/test_set_webhook.py +++ b/tests/test_api/test_methods/test_set_webhook.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestSetWebhook: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(SetWebhook, ok=True, result=True) - - response: bool = await SetWebhook(url="https://example.com") - request: Request = bot.get_request() - assert request.method == "setWebhook" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(SetWebhook, ok=True, result=True) response: bool = await bot.set_webhook(url="https://example.com") - request: Request = bot.get_request() - assert request.method == "setWebhook" + request = bot.get_request() 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 2c1168f1..99c8b675 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 @@ -6,22 +6,11 @@ from tests.mocked_bot import MockedBot class TestStopMessageLiveLocation: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(StopMessageLiveLocation, ok=True, result=True) - - response: Union[Message, bool] = await StopMessageLiveLocation( - inline_message_id="inline message id" - ) - request: Request = bot.get_request() - assert request.method == "stopMessageLiveLocation" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(StopMessageLiveLocation, ok=True, result=True) 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" + request = bot.get_request() 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 7601c771..ef2d36d6 100644 --- a/tests/test_api/test_methods/test_stop_poll.py +++ b/tests/test_api/test_methods/test_stop_poll.py @@ -4,28 +4,6 @@ from tests.mocked_bot import MockedBot class TestStopPoll: - async def test_method(self, bot: MockedBot): - 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, - is_anonymous=False, - type="quiz", - allows_multiple_answers=False, - total_voter_count=0, - correct_option_id=0, - ), - ) - - response: Poll = await StopPoll(chat_id=42, message_id=42) - request: Request = bot.get_request() - assert request.method == "stopPoll" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( StopPoll, @@ -44,6 +22,5 @@ class TestStopPoll: ) response: Poll = await bot.stop_poll(chat_id=42, message_id=42) - request: Request = bot.get_request() - assert request.method == "stopPoll" + request = bot.get_request() 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 72ba662c..291512fa 100644 --- a/tests/test_api/test_methods/test_unban_chat_member.py +++ b/tests/test_api/test_methods/test_unban_chat_member.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestUnbanChatMember: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(UnbanChatMember, ok=True, result=True) - - response: bool = await UnbanChatMember(chat_id=-42, user_id=42) - request: Request = bot.get_request() - assert request.method == "unbanChatMember" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(UnbanChatMember, ok=True, result=True) response: bool = await bot.unban_chat_member(chat_id=-42, user_id=42) - request: Request = bot.get_request() - assert request.method == "unbanChatMember" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_unban_chat_sender_chat.py b/tests/test_api/test_methods/test_unban_chat_sender_chat.py index 4a259c62..54c334ab 100755 --- a/tests/test_api/test_methods/test_unban_chat_sender_chat.py +++ b/tests/test_api/test_methods/test_unban_chat_sender_chat.py @@ -3,18 +3,6 @@ from tests.mocked_bot import MockedBot class TestUnbanChatSenderChat: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(UnbanChatSenderChat, ok=True, result=True) - - response: bool = await UnbanChatSenderChat( - chat_id=-42, - sender_chat_id=-1337, - ) - request: Request = bot.get_request() - assert request.method == "unbanChatSenderChat" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(UnbanChatSenderChat, ok=True, result=True) @@ -22,7 +10,5 @@ class TestUnbanChatSenderChat: chat_id=-42, sender_chat_id=-1337, ) - request: Request = bot.get_request() - assert request.method == "unbanChatSenderChat" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_unhide_general_forum_topic.py b/tests/test_api/test_methods/test_unhide_general_forum_topic.py index 45fcb0c8..eb69223b 100644 --- a/tests/test_api/test_methods/test_unhide_general_forum_topic.py +++ b/tests/test_api/test_methods/test_unhide_general_forum_topic.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestUnhideGeneralForumTopic: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(UnhideGeneralForumTopic, ok=True, result=True) - - response: bool = await bot(UnhideGeneralForumTopic(chat_id=42)) - request: Request = bot.get_request() - assert request.method == "unhideGeneralForumTopic" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(UnhideGeneralForumTopic, ok=True, result=True) response: bool = await bot.unhide_general_forum_topic(chat_id=42) - request: Request = bot.get_request() - assert request.method == "unhideGeneralForumTopic" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_unpin_all_chat_messages.py b/tests/test_api/test_methods/test_unpin_all_chat_messages.py index 82202742..173ce711 100644 --- a/tests/test_api/test_methods/test_unpin_all_chat_messages.py +++ b/tests/test_api/test_methods/test_unpin_all_chat_messages.py @@ -3,24 +3,11 @@ from tests.mocked_bot import MockedBot class TestUnpinAllChatMessages: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(UnpinAllChatMessages, ok=True, result=True) - - response: bool = await UnpinAllChatMessages( - chat_id=42, - ) - request: Request = bot.get_request() - assert request.method == "unpinAllChatMessages" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(UnpinAllChatMessages, ok=True, result=True) response: bool = await bot.unpin_all_chat_messages( chat_id=42, ) - request: Request = bot.get_request() - assert request.method == "unpinAllChatMessages" - # assert request.data == {} + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_api/test_methods/test_unpin_all_forum_topic_messages.py b/tests/test_api/test_methods/test_unpin_all_forum_topic_messages.py index 445f2b4c..ac7b409c 100644 --- a/tests/test_api/test_methods/test_unpin_all_forum_topic_messages.py +++ b/tests/test_api/test_methods/test_unpin_all_forum_topic_messages.py @@ -3,18 +3,6 @@ from tests.mocked_bot import MockedBot class TestUnpinAllForumTopicMessages: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(UnpinAllForumTopicMessages, ok=True, result=True) - - response: bool = await UnpinAllForumTopicMessages( - chat_id=42, - message_thread_id=42, - ) - request: Request = bot.get_request() - assert request.method == "unpinAllForumTopicMessages" - # assert request.data == {} - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(UnpinAllForumTopicMessages, ok=True, result=True) @@ -22,7 +10,5 @@ class TestUnpinAllForumTopicMessages: chat_id=42, message_thread_id=42, ) - request: Request = bot.get_request() - assert request.method == "unpinAllForumTopicMessages" - # assert request.data == {} + request = bot.get_request() 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 52f8765a..804b3ae2 100644 --- a/tests/test_api/test_methods/test_unpin_chat_message.py +++ b/tests/test_api/test_methods/test_unpin_chat_message.py @@ -3,18 +3,9 @@ from tests.mocked_bot import MockedBot class TestUnpinChatMessage: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for(UnpinChatMessage, ok=True, result=True) - - response: bool = await UnpinChatMessage(chat_id=-42) - request: Request = bot.get_request() - assert request.method == "unpinChatMessage" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for(UnpinChatMessage, ok=True, result=True) response: bool = await bot.unpin_chat_message(chat_id=-42) - request: Request = bot.get_request() - assert request.method == "unpinChatMessage" + request = bot.get_request() 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 7a6bded9..fda4c4d0 100644 --- a/tests/test_api/test_methods/test_upload_sticker_file.py +++ b/tests/test_api/test_methods/test_upload_sticker_file.py @@ -5,20 +5,6 @@ from tests.mocked_bot import MockedBot class TestUploadStickerFile: - async def test_method(self, bot: MockedBot): - prepare_result = bot.add_result_for( - UploadStickerFile, ok=True, result=File(file_id="file id", file_unique_id="file id") - ) - - response: File = await UploadStickerFile( - user_id=42, - sticker=BufferedInputFile(b"", "file.png"), - sticker_format=StickerFormat.STATIC, - ) - request: Request = bot.get_request() - assert request.method == "uploadStickerFile" - assert response == prepare_result.result - async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( UploadStickerFile, ok=True, result=File(file_id="file id", file_unique_id="file id") @@ -29,6 +15,5 @@ class TestUploadStickerFile: sticker=BufferedInputFile(b"", "file.png"), sticker_format=StickerFormat.STATIC, ) - request: Request = bot.get_request() - assert request.method == "uploadStickerFile" + request = bot.get_request() assert response == prepare_result.result diff --git a/tests/test_dispatcher/test_dispatcher.py b/tests/test_dispatcher/test_dispatcher.py index 509bff35..4fb2b113 100644 --- a/tests/test_dispatcher/test_dispatcher.py +++ b/tests/test_dispatcher/test_dispatcher.py @@ -14,7 +14,7 @@ from aiogram import Bot from aiogram.dispatcher.dispatcher import Dispatcher from aiogram.dispatcher.event.bases import UNHANDLED, SkipHandler from aiogram.dispatcher.router import Router -from aiogram.methods import GetMe, GetUpdates, Request, SendMessage +from aiogram.methods import GetMe, GetUpdates, Request, SendMessage, TelegramMethod from aiogram.types import ( CallbackQuery, Chat, @@ -775,9 +775,7 @@ class TestDispatcher: dispatcher.message.register(simple_message_handler) response = await dispatcher.feed_webhook_update(bot, RAW_UPDATE, _timeout=0.3) - assert isinstance(response, Request) - assert response.method == "sendMessage" - assert response.data["text"] == "ok" + assert isinstance(response, TelegramMethod) async def test_feed_webhook_update_slow_process(self, bot: MockedBot, recwarn): warnings.simplefilter("always") diff --git a/tests/test_webhook/test_aiohtt_server.py b/tests/test_webhook/test_aiohtt_server.py index 8bd2cf2d..5be8f43e 100644 --- a/tests/test_webhook/test_aiohtt_server.py +++ b/tests/test_webhook/test_aiohtt_server.py @@ -102,7 +102,8 @@ class TestSimpleRequestHandler: result[part.name] = value.decode() assert result["method"] == "sendDocument" assert result["caption"] == "PASS" - assert result["document"] == "test" + assert result["document"].startswith("attach://") + assert result[result["document"][9:]] async def test_reply_into_webhook_text(self, bot: MockedBot, aiohttp_client): app = Application()