mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Chat join request shortcuts (#1235)
* Add additional API message methods to ChatJoinRequest class ChatJoinRequest now includes additional message methods including SendAnimation, SendAudio, SendContact, and many more. The changes are useful for sending various types of messages during chat join requests. * Added changelog
This commit is contained in:
parent
a1513ddb2d
commit
faadc80460
23 changed files with 2527 additions and 9 deletions
|
|
@ -1,7 +1,34 @@
|
|||
import datetime
|
||||
from typing import Any, Dict, Type, Union
|
||||
|
||||
from aiogram.methods import ApproveChatJoinRequest, DeclineChatJoinRequest
|
||||
from aiogram.types import Chat, ChatJoinRequest, User
|
||||
import pytest
|
||||
|
||||
from aiogram.methods import (
|
||||
ApproveChatJoinRequest,
|
||||
DeclineChatJoinRequest,
|
||||
SendAnimation,
|
||||
SendAudio,
|
||||
SendContact,
|
||||
SendDice,
|
||||
SendDocument,
|
||||
SendGame,
|
||||
SendInvoice,
|
||||
SendLocation,
|
||||
SendMediaGroup,
|
||||
SendMessage,
|
||||
SendPhoto,
|
||||
SendPoll,
|
||||
SendSticker,
|
||||
SendVenue,
|
||||
SendVideo,
|
||||
SendVideoNote,
|
||||
SendVoice,
|
||||
)
|
||||
from aiogram.types import (
|
||||
Chat,
|
||||
ChatJoinRequest,
|
||||
User,
|
||||
)
|
||||
|
||||
|
||||
class TestChatJoinRequest:
|
||||
|
|
@ -32,3 +59,96 @@ class TestChatJoinRequest:
|
|||
assert isinstance(api_method, DeclineChatJoinRequest)
|
||||
assert api_method.chat_id == chat_join_request.chat.id
|
||||
assert api_method.user_id == chat_join_request.from_user.id
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"alias_for_method,kwargs,method_class",
|
||||
[
|
||||
["answer_animation", dict(animation="animation"), SendAnimation],
|
||||
["answer_audio", dict(audio="audio"), SendAudio],
|
||||
["answer_contact", dict(phone_number="+000000000000", first_name="Test"), SendContact],
|
||||
["answer_document", dict(document="document"), SendDocument],
|
||||
["answer_game", dict(game_short_name="game"), SendGame],
|
||||
[
|
||||
"answer_invoice",
|
||||
dict(
|
||||
title="title",
|
||||
description="description",
|
||||
payload="payload",
|
||||
provider_token="provider_token",
|
||||
start_parameter="start_parameter",
|
||||
currency="currency",
|
||||
prices=[],
|
||||
),
|
||||
SendInvoice,
|
||||
],
|
||||
["answer_location", dict(latitude=0.42, longitude=0.42), SendLocation],
|
||||
["answer_media_group", dict(media=[]), SendMediaGroup],
|
||||
["answer", dict(text="test"), SendMessage],
|
||||
["answer_photo", dict(photo="photo"), SendPhoto],
|
||||
["answer_poll", dict(question="Q?", options=[]), SendPoll],
|
||||
["answer_dice", dict(), SendDice],
|
||||
["answer_sticker", dict(sticker="sticker"), SendSticker],
|
||||
["answer_sticker", dict(sticker="sticker"), SendSticker],
|
||||
[
|
||||
"answer_venue",
|
||||
dict(
|
||||
latitude=0.42,
|
||||
longitude=0.42,
|
||||
title="title",
|
||||
address="address",
|
||||
),
|
||||
SendVenue,
|
||||
],
|
||||
["answer_video", dict(video="video"), SendVideo],
|
||||
["answer_video_note", dict(video_note="video_note"), SendVideoNote],
|
||||
["answer_voice", dict(voice="voice"), SendVoice],
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("suffix", ["", "_pm"])
|
||||
def test_answer_aliases(
|
||||
self,
|
||||
alias_for_method: str,
|
||||
suffix: str,
|
||||
kwargs: Dict[str, Any],
|
||||
method_class: Type[
|
||||
Union[
|
||||
SendAnimation,
|
||||
SendAudio,
|
||||
SendContact,
|
||||
SendDocument,
|
||||
SendGame,
|
||||
SendInvoice,
|
||||
SendLocation,
|
||||
SendMediaGroup,
|
||||
SendMessage,
|
||||
SendPhoto,
|
||||
SendPoll,
|
||||
SendSticker,
|
||||
SendSticker,
|
||||
SendVenue,
|
||||
SendVideo,
|
||||
SendVideoNote,
|
||||
SendVoice,
|
||||
]
|
||||
],
|
||||
):
|
||||
event = ChatJoinRequest(
|
||||
chat=Chat(id=-42, type="channel"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
user_chat_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
)
|
||||
|
||||
alias = getattr(event, alias_for_method + suffix)
|
||||
assert callable(alias)
|
||||
|
||||
api_method = alias(**kwargs)
|
||||
assert isinstance(api_method, method_class)
|
||||
|
||||
if suffix == "_pm":
|
||||
assert api_method.chat_id == event.user_chat_id
|
||||
else:
|
||||
assert api_method.chat_id == event.chat.id
|
||||
|
||||
for key, value in kwargs.items():
|
||||
assert getattr(api_method, key) == value
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ from aiogram.types import (
|
|||
ChatMemberUpdated,
|
||||
User,
|
||||
)
|
||||
from aiogram.types.message import Message
|
||||
|
||||
|
||||
class TestChatMemberUpdated:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue