mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 02:03:04 +00:00
Added shortcuts for ChatMemberUpdate event (#1234)
* Added shortcuts for ChatMemberUpdate event * Added changelog
This commit is contained in:
parent
baad0ebef2
commit
a1513ddb2d
22 changed files with 1343 additions and 3 deletions
|
|
@ -24,7 +24,6 @@ class TestSendMessage:
|
|||
|
||||
async def test_force_reply(self):
|
||||
# https://github.com/aiogram/aiogram/issues/901
|
||||
print("::::", SendMessage.__pydantic_core_schema__)
|
||||
method = SendMessage(text="test", chat_id=42, reply_markup=ForceReply())
|
||||
assert isinstance(method.reply_markup, ForceReply)
|
||||
|
||||
|
|
|
|||
124
tests/test_api/test_types/test_chat_member_updated.py
Normal file
124
tests/test_api/test_types/test_chat_member_updated.py
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
import datetime
|
||||
from typing import Any, Dict, Type, Union
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram.methods import (
|
||||
SendAnimation,
|
||||
SendAudio,
|
||||
SendContact,
|
||||
SendDice,
|
||||
SendDocument,
|
||||
SendGame,
|
||||
SendInvoice,
|
||||
SendLocation,
|
||||
SendMediaGroup,
|
||||
SendMessage,
|
||||
SendPhoto,
|
||||
SendPoll,
|
||||
SendSticker,
|
||||
SendVenue,
|
||||
SendVideo,
|
||||
SendVideoNote,
|
||||
SendVoice,
|
||||
)
|
||||
from aiogram.types import (
|
||||
Chat,
|
||||
ChatMemberLeft,
|
||||
ChatMemberMember,
|
||||
ChatMemberUpdated,
|
||||
User,
|
||||
)
|
||||
from aiogram.types.message import Message
|
||||
|
||||
|
||||
class TestChatMemberUpdated:
|
||||
@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],
|
||||
],
|
||||
)
|
||||
def test_answer_aliases(
|
||||
self,
|
||||
alias_for_method: 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,
|
||||
]
|
||||
],
|
||||
):
|
||||
user = User(id=42, is_bot=False, first_name="Test")
|
||||
event = ChatMemberUpdated(
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
date=datetime.datetime.now(),
|
||||
old_chat_member=ChatMemberLeft(user=user),
|
||||
new_chat_member=ChatMemberMember(user=user),
|
||||
)
|
||||
|
||||
alias = getattr(event, alias_for_method)
|
||||
assert callable(alias)
|
||||
|
||||
api_method = alias(**kwargs)
|
||||
assert isinstance(api_method, method_class)
|
||||
|
||||
assert api_method.chat_id == event.chat.id
|
||||
|
||||
for key, value in kwargs.items():
|
||||
assert getattr(api_method, key) == value
|
||||
Loading…
Add table
Add a link
Reference in a new issue