Added full support of Bot API 7.6 (#1533)

* Added full support of Bot API 7.6

* Fixed imports

* fix tests (#1534)

* Fixed coverage

* Override InputPaidMedia media type to `str | InputFile`

* Added shortcut

* Fixed PaidMediaType enum

* Added changelog

---------

Co-authored-by: Oleg A <t0rr@mail.ru>
This commit is contained in:
Alex Root Junior 2024-07-06 20:31:49 +03:00 committed by GitHub
parent 3baa7383c1
commit 11efa8e186
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
97 changed files with 2058 additions and 274 deletions

View file

@ -0,0 +1,43 @@
import datetime
from aiogram.methods import SendPaidMedia
from aiogram.types import (
Message,
Chat,
PaidMediaPhoto,
PaidMediaInfo,
PhotoSize,
InputPaidMediaPhoto,
)
from tests.mocked_bot import MockedBot
class TestSendPaidMedia:
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
SendPaidMedia,
ok=True,
result=Message(
message_id=42,
date=datetime.datetime.now(),
chat=Chat(id=42, type="private"),
paid_media=PaidMediaInfo(
paid_media=[
PaidMediaPhoto(
photo=[
PhotoSize(
file_id="test", width=42, height=42, file_unique_id="test"
)
]
)
],
star_count=1,
),
),
)
response: Message = await bot.send_paid_media(
chat_id=-42, star_count=1, media=[InputPaidMediaPhoto(media="file_id")]
)
request = bot.get_request()
assert response == prepare_result.result

View file

@ -35,6 +35,7 @@ from aiogram.methods import (
StopMessageLiveLocation,
TelegramMethod,
UnpinChatMessage,
SendPaidMedia,
)
from aiogram.types import (
UNSET_PARSE_MODE,
@ -68,6 +69,8 @@ from aiogram.types import (
Location,
MessageAutoDeleteTimerChanged,
MessageEntity,
PaidMediaInfo,
PaidMediaPhoto,
PassportData,
PhotoSize,
Poll,
@ -331,6 +334,22 @@ TEST_MESSAGE_CHANNEL_CHAT_CREATED = Message(
chat=Chat(id=-10042, type="channel"),
from_user=User(id=42, is_bot=False, first_name="Test"),
)
TEST_MESSAGE_PAID_MEDIA = Message(
message_id=42,
date=datetime.datetime.now(),
paid_media=PaidMediaInfo(
star_count=100500,
paid_media=[
PaidMediaPhoto(
photo=[
PhotoSize(file_id="file id", file_unique_id="file id", width=42, height=42)
],
)
],
),
chat=Chat(id=42, type="private"),
from_user=User(id=42, is_bot=False, first_name="Test"),
)
TEST_MESSAGE_PASSPORT_DATA = Message(
message_id=42,
date=datetime.datetime.now(),
@ -603,6 +622,7 @@ MESSAGES_AND_CONTENT_TYPES = [
[TEST_MESSAGE_GROUP_CHAT_CREATED, ContentType.GROUP_CHAT_CREATED],
[TEST_MESSAGE_SUPERGROUP_CHAT_CREATED, ContentType.SUPERGROUP_CHAT_CREATED],
[TEST_MESSAGE_CHANNEL_CHAT_CREATED, ContentType.CHANNEL_CHAT_CREATED],
[TEST_MESSAGE_PAID_MEDIA, ContentType.PAID_MEDIA],
[TEST_MESSAGE_PASSPORT_DATA, ContentType.PASSPORT_DATA],
[TEST_MESSAGE_PROXIMITY_ALERT_TRIGGERED, ContentType.PROXIMITY_ALERT_TRIGGERED],
[TEST_MESSAGE_POLL, ContentType.POLL],
@ -669,6 +689,7 @@ MESSAGES_AND_COPY_METHODS = [
[TEST_MESSAGE_GROUP_CHAT_CREATED, None],
[TEST_MESSAGE_SUPERGROUP_CHAT_CREATED, None],
[TEST_MESSAGE_CHANNEL_CHAT_CREATED, None],
[TEST_MESSAGE_PAID_MEDIA, None],
[TEST_MESSAGE_PASSPORT_DATA, None],
[TEST_MESSAGE_PROXIMITY_ALERT_TRIGGERED, None],
[TEST_MESSAGE_POLL, SendPoll],
@ -778,6 +799,7 @@ class TestMessage:
["video", dict(video="video"), SendVideo],
["video_note", dict(video_note="video_note"), SendVideoNote],
["voice", dict(voice="voice"), SendVoice],
["paid_media", dict(media=[], star_count=42), SendPaidMedia],
],
)
@pytest.mark.parametrize("alias_type", ["reply", "answer"])
@ -805,9 +827,14 @@ class TestMessage:
SendVideo,
SendVideoNote,
SendVoice,
SendPaidMedia,
]
],
):
if alias_for_method == "paid_media" and alias_type == "reply":
# Replies should be completely reworked
pytest.skip("Reply alias for paid media is not implemented yet.")
message = Message(
message_id=42, chat=Chat(id=42, type="private"), date=datetime.datetime.now()
)
@ -820,10 +847,11 @@ class TestMessage:
assert isinstance(api_method, method_class)
assert api_method.chat_id == message.chat.id
if alias_type == "reply":
assert api_method.reply_to_message_id == message.message_id
else:
assert api_method.reply_to_message_id is None
if hasattr(api_method, "reply_to_message_id"):
if alias_type == "reply":
assert api_method.reply_to_message_id == message.message_id
else:
assert api_method.reply_to_message_id is None
for key, value in kwargs.items():
assert getattr(api_method, key) == value