From ee3b0954a31125ddc43de2eee2c41bed184e0827 Mon Sep 17 00:00:00 2001 From: Oleg A Date: Thu, 12 Nov 2020 15:02:52 -0500 Subject: [PATCH 01/10] Telegram API readme updated (#463) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5cc22e92..3c43b881 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![PyPi status](https://img.shields.io/pypi/status/aiogram.svg?style=flat-square)](https://pypi.python.org/pypi/aiogram) [![Downloads](https://img.shields.io/pypi/dm/aiogram.svg?style=flat-square)](https://pypi.python.org/pypi/aiogram) [![Supported python versions](https://img.shields.io/pypi/pyversions/aiogram.svg?style=flat-square)](https://pypi.python.org/pypi/aiogram) -[![Telegram Bot API](https://img.shields.io/badge/Telegram%20Bot%20API-4.9-blue.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) +[![Telegram Bot API](https://img.shields.io/badge/Telegram%20Bot%20API-5.0-blue.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) [![Documentation Status](https://img.shields.io/readthedocs/aiogram?style=flat-square)](http://docs.aiogram.dev/en/latest/?badge=latest) [![Github issues](https://img.shields.io/github/issues/aiogram/aiogram.svg?style=flat-square)](https://github.com/aiogram/aiogram/issues) [![MIT License](https://img.shields.io/pypi/l/aiogram.svg?style=flat-square)](https://opensource.org/licenses/MIT) From ae7b250e3349bb7cc9aec7729aed6ec2186346e6 Mon Sep 17 00:00:00 2001 From: Oleg A Date: Fri, 13 Nov 2020 14:58:00 -0500 Subject: [PATCH 02/10] fixed: Cannot send playlist of audio files (#465) * fixed: Cannot send playlist of audio files #464 * #463 removed document and audio from check * #463 style fix --- aiogram/types/input_media.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aiogram/types/input_media.py b/aiogram/types/input_media.py index 943a534c..e60913ff 100644 --- a/aiogram/types/input_media.py +++ b/aiogram/types/input_media.py @@ -270,10 +270,10 @@ class MediaGroup(base.TelegramObject): media = InputMediaPhoto(**media) elif media_type == 'video': media = InputMediaVideo(**media) - # elif media_type == 'document': - # media = InputMediaDocument(**media) - # elif media_type == 'audio': - # media = InputMediaAudio(**media) + elif media_type == 'document': + media = InputMediaDocument(**media) + elif media_type == 'audio': + media = InputMediaAudio(**media) # elif media_type == 'animation': # media = InputMediaAnimation(**media) else: @@ -282,8 +282,8 @@ class MediaGroup(base.TelegramObject): elif not isinstance(media, InputMedia): raise TypeError(f"Media must be an instance of InputMedia or dict, not {type(media).__name__}") - elif media.type in ('document', 'audio', 'animation'): - raise ValueError(f"This type of media is not supported by media groups!") + elif media.type == 'animation': + raise ValueError("This type of media is not supported by media groups!") self.media.append(media) From 2cf6b22a693d0bc11303c3fc28e5be43deb92b3c Mon Sep 17 00:00:00 2001 From: Forden Date: Sun, 15 Nov 2020 21:19:08 +0300 Subject: [PATCH 03/10] Update message.py (#466) Added DICE to ContentTypes --- aiogram/types/message.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/aiogram/types/message.py b/aiogram/types/message.py index a260e62d..4b5a47bc 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -2901,6 +2901,8 @@ class ContentType(helper.Helper): :key: CONTACT :key: LOCATION :key: VENUE + :key: POLL + :key: DICE :key: NEW_CHAT_MEMBERS :key: LEFT_CHAT_MEMBER :key: INVOICE @@ -2966,6 +2968,8 @@ class ContentTypes(helper.Helper): :key: CONTACT :key: LOCATION :key: VENUE + :key: POLL + :key: DICE :key: NEW_CHAT_MEMBERS :key: LEFT_CHAT_MEMBER :key: INVOICE @@ -2992,6 +2996,8 @@ class ContentTypes(helper.Helper): CONTACT = helper.ListItem() # contact LOCATION = helper.ListItem() # location VENUE = helper.ListItem() # venue + POLL = helper.ListItem() # poll + DICE = helper.ListItem() # dice NEW_CHAT_MEMBERS = helper.ListItem() # new_chat_member LEFT_CHAT_MEMBER = helper.ListItem() # left_chat_member INVOICE = helper.ListItem() # invoice @@ -3005,7 +3011,6 @@ class ContentTypes(helper.Helper): DELETE_CHAT_PHOTO = helper.ListItem() # delete_chat_photo GROUP_CHAT_CREATED = helper.ListItem() # group_chat_created PASSPORT_DATA = helper.ListItem() # passport_data - POLL = helper.ListItem() UNKNOWN = helper.ListItem() # unknown ANY = helper.ListItem() # any From b3103183d735576f5fd684c1bf6d16eec179f14c Mon Sep 17 00:00:00 2001 From: Oleg A Date: Tue, 17 Nov 2020 19:06:59 -0500 Subject: [PATCH 04/10] #467 Uncommented `attach_document` and `attach_audio` MediaGroup methods (#468) --- aiogram/types/input_media.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiogram/types/input_media.py b/aiogram/types/input_media.py index e60913ff..2d325d89 100644 --- a/aiogram/types/input_media.py +++ b/aiogram/types/input_media.py @@ -309,6 +309,7 @@ class MediaGroup(base.TelegramObject): width=width, height=height, duration=duration, parse_mode=parse_mode) self.attach(animation) + ''' def attach_audio(self, audio: base.InputFile, thumb: typing.Union[base.InputFile, base.String] = None, @@ -351,7 +352,6 @@ class MediaGroup(base.TelegramObject): if not isinstance(document, InputMedia): document = InputMediaDocument(media=document, thumb=thumb, caption=caption, parse_mode=parse_mode) self.attach(document) - ''' def attach_photo(self, photo: typing.Union[InputMediaPhoto, base.InputFile], caption: base.String = None): From ca45b248a895c526927201ff812684cec3b4b429 Mon Sep 17 00:00:00 2001 From: SvineruS <37367870+SvineruS@users.noreply.github.com> Date: Sat, 5 Dec 2020 15:28:34 +0200 Subject: [PATCH 05/10] Fixed optionality of some properties, add vcard argument to InputContactMessageContent constructor (#473) --- aiogram/types/input_message_content.py | 55 ++++++++++++++++---------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/aiogram/types/input_message_content.py b/aiogram/types/input_message_content.py index 522d44c5..0008a2ee 100644 --- a/aiogram/types/input_message_content.py +++ b/aiogram/types/input_message_content.py @@ -27,14 +27,21 @@ class InputContactMessageContent(InputMessageContent): """ phone_number: base.String = fields.Field() first_name: base.String = fields.Field() - last_name: base.String = fields.Field() - vcard: base.String = fields.Field() + last_name: typing.Optional[base.String] = fields.Field() + vcard: typing.Optional[base.String] = fields.Field() - def __init__(self, phone_number: base.String, - first_name: typing.Optional[base.String] = None, - last_name: typing.Optional[base.String] = None): - super(InputContactMessageContent, self).__init__(phone_number=phone_number, first_name=first_name, - last_name=last_name) + def __init__(self, + phone_number: base.String, + first_name: base.String = None, + last_name: typing.Optional[base.String] = None, + vcard: typing.Optional[base.String] = None, + ): + super().__init__( + phone_number=phone_number, + first_name=first_name, + last_name=last_name, + vcard=vcard + ) class InputLocationMessageContent(InputMessageContent): @@ -75,7 +82,8 @@ class InputTextMessageContent(InputMessageContent): https://core.telegram.org/bots/api#inputtextmessagecontent """ message_text: base.String = fields.Field() - parse_mode: base.String = fields.Field() + parse_mode: typing.Optional[base.String] = fields.Field() + caption_entities: typing.Optional[typing.List[MessageEntity]] = fields.Field() disable_web_page_preview: base.Boolean = fields.Field() def safe_get_parse_mode(self): @@ -86,7 +94,7 @@ class InputTextMessageContent(InputMessageContent): def __init__( self, - message_text: typing.Optional[base.String] = None, + message_text: base.String, parse_mode: typing.Optional[base.String] = None, caption_entities: typing.Optional[typing.List[MessageEntity]] = None, disable_web_page_preview: typing.Optional[base.Boolean] = None, @@ -95,7 +103,8 @@ class InputTextMessageContent(InputMessageContent): parse_mode = self.safe_get_parse_mode() super().__init__( - message_text=message_text, parse_mode=parse_mode, + message_text=message_text, + parse_mode=parse_mode, caption_entities=caption_entities, disable_web_page_preview=disable_web_page_preview, ) @@ -114,25 +123,29 @@ class InputVenueMessageContent(InputMessageContent): longitude: base.Float = fields.Field() title: base.String = fields.Field() address: base.String = fields.Field() - foursquare_id: base.String = fields.Field() - foursquare_type: base.String = fields.Field() - google_place_id: base.String = fields.Field() - google_place_type: base.String = fields.Field() + foursquare_id: typing.Optional[base.String] = fields.Field() + foursquare_type: typing.Optional[base.String] = fields.Field() + google_place_id: typing.Optional[base.String] = fields.Field() + google_place_type: typing.Optional[base.String] = fields.Field() def __init__( self, - latitude: typing.Optional[base.Float] = None, - longitude: typing.Optional[base.Float] = None, - title: typing.Optional[base.String] = None, - address: typing.Optional[base.String] = None, + latitude: base.Float, + longitude: base.Float, + title: base.String, + address: base.String, foursquare_id: typing.Optional[base.String] = None, foursquare_type: typing.Optional[base.String] = None, google_place_id: typing.Optional[base.String] = None, google_place_type: typing.Optional[base.String] = None, ): super().__init__( - latitude=latitude, longitude=longitude, title=title, - address=address, foursquare_id=foursquare_id, - foursquare_type=foursquare_type, google_place_id=google_place_id, + latitude=latitude, + longitude=longitude, + title=title, + address=address, + foursquare_id=foursquare_id, + foursquare_type=foursquare_type, + google_place_id=google_place_id, google_place_type=google_place_type, ) From 3440ab3c96e31384cbcf515e75904dcade6f5fd0 Mon Sep 17 00:00:00 2001 From: OGURCHINSKIY <41481736+OGURCHINSKIY@users.noreply.github.com> Date: Sat, 5 Dec 2020 16:28:56 +0300 Subject: [PATCH 06/10] Add exception MessageIdInvalid (#474) --- aiogram/utils/exceptions.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aiogram/utils/exceptions.py b/aiogram/utils/exceptions.py index cc1885dd..d38ff009 100644 --- a/aiogram/utils/exceptions.py +++ b/aiogram/utils/exceptions.py @@ -6,6 +6,7 @@ - MessageError - MessageNotModified - MessageToForwardNotFound + - MessageIdInvalid - MessageToDeleteNotFound - MessageToPinNotFound - MessageIdentifierNotSpecified @@ -178,6 +179,11 @@ class MessageToForwardNotFound(MessageError): match = 'message to forward not found' +class MessageIdInvalid(MessageError): + text = 'Invalid message id' + match = 'message_id_invalid' + + class MessageToDeleteNotFound(MessageError): """ Will be raised when you try to delete very old or deleted or unknown message. From d7b1bd2daecd6ec82438ac2ef4b001e642c91b56 Mon Sep 17 00:00:00 2001 From: Felix Yan Date: Sun, 10 Jan 2021 12:49:48 -0600 Subject: [PATCH 07/10] Correct a typo in executor.py (#489) --- aiogram/utils/executor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiogram/utils/executor.py b/aiogram/utils/executor.py index 1b5b0b0b..35107975 100644 --- a/aiogram/utils/executor.py +++ b/aiogram/utils/executor.py @@ -155,7 +155,7 @@ class Executor: def set_web_app(self, application: web.Application): """ - Change instance of aiohttp.web.Applicaton + Change instance of aiohttp.web.Application :param application: """ From 4fb4d6cac1253b677709d4b1f35312f4df43b825 Mon Sep 17 00:00:00 2001 From: Ibraheem Asaad Date: Sun, 10 Jan 2021 20:52:50 +0200 Subject: [PATCH 08/10] fix return value of FSMContextProxy's setdefault (#405) (#491) --- aiogram/dispatcher/storage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiogram/dispatcher/storage.py b/aiogram/dispatcher/storage.py index 9a4eac76..74492361 100644 --- a/aiogram/dispatcher/storage.py +++ b/aiogram/dispatcher/storage.py @@ -397,7 +397,7 @@ class FSMContextProxy: def setdefault(self, key, default): self._check_closed() - self._data.setdefault(key, default) + return self._data.setdefault(key, default) def update(self, data=None, **kwargs): self._check_closed() From ee12911f240175d216ce33c78012994a34fe2e25 Mon Sep 17 00:00:00 2001 From: Oleg A Date: Sun, 10 Jan 2021 21:53:59 +0300 Subject: [PATCH 09/10] pytest update; yield_fixture deprecation fix; event_loop removed (#479) --- dev_requirements.txt | 3 +- tests/test_bot.py | 190 +++++++++++++++++++-------------------- tests/test_dispatcher.py | 7 +- tests/test_message.py | 12 +-- 4 files changed, 105 insertions(+), 107 deletions(-) diff --git a/dev_requirements.txt b/dev_requirements.txt index 0252e7e1..ef5272af 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -3,11 +3,10 @@ ujson>=1.35 python-rapidjson>=0.7.0 emoji>=0.5.2 -pytest>=5.4 +pytest>=6.2.1 pytest-asyncio>=0.10.0 tox>=3.9.0 aresponses>=1.1.1 -uvloop>=0.12.2 aioredis>=1.2.0 wheel>=0.31.1 sphinx>=2.0.1 diff --git a/tests/test_bot.py b/tests/test_bot.py index 45d3a3fa..224666ec 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -6,103 +6,103 @@ from . import FakeTelegram, TOKEN, BOT_ID pytestmark = pytest.mark.asyncio -@pytest.yield_fixture(name='bot') -async def bot_fixture(event_loop): +@pytest.fixture(name='bot') +async def bot_fixture(): """ Bot fixture """ - _bot = Bot(TOKEN, loop=event_loop, parse_mode=types.ParseMode.MARKDOWN) + _bot = Bot(TOKEN, parse_mode=types.ParseMode.MARKDOWN_V2) yield _bot await _bot.close() -async def test_get_me(bot: Bot, event_loop): +async def test_get_me(bot: Bot): """ getMe method test """ from .types.dataset import USER user = types.User(**USER) - async with FakeTelegram(message_data=USER, loop=event_loop): + async with FakeTelegram(message_data=USER): result = await bot.me assert result == user -async def test_log_out(bot: Bot, event_loop): +async def test_log_out(bot: Bot): """ logOut method test """ - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.log_out() assert result is True -async def test_close_bot(bot: Bot, event_loop): +async def test_close_bot(bot: Bot): """ close method test """ - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.close_bot() assert result is True -async def test_send_message(bot: Bot, event_loop): +async def test_send_message(bot: Bot): """ sendMessage method test """ from .types.dataset import MESSAGE msg = types.Message(**MESSAGE) - async with FakeTelegram(message_data=MESSAGE, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE): result = await bot.send_message(chat_id=msg.chat.id, text=msg.text) assert result == msg -async def test_forward_message(bot: Bot, event_loop): +async def test_forward_message(bot: Bot): """ forwardMessage method test """ from .types.dataset import FORWARDED_MESSAGE msg = types.Message(**FORWARDED_MESSAGE) - async with FakeTelegram(message_data=FORWARDED_MESSAGE, loop=event_loop): + async with FakeTelegram(message_data=FORWARDED_MESSAGE): result = await bot.forward_message(chat_id=msg.chat.id, from_chat_id=msg.forward_from_chat.id, message_id=msg.forward_from_message_id) assert result == msg -async def test_send_photo(bot: Bot, event_loop): +async def test_send_photo(bot: Bot): """ sendPhoto method test with file_id """ from .types.dataset import MESSAGE_WITH_PHOTO, PHOTO msg = types.Message(**MESSAGE_WITH_PHOTO) photo = types.PhotoSize(**PHOTO) - async with FakeTelegram(message_data=MESSAGE_WITH_PHOTO, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE_WITH_PHOTO): result = await bot.send_photo(msg.chat.id, photo=photo.file_id, caption=msg.caption, parse_mode=types.ParseMode.HTML, disable_notification=False) assert result == msg -async def test_send_audio(bot: Bot, event_loop): +async def test_send_audio(bot: Bot): """ sendAudio method test with file_id """ from .types.dataset import MESSAGE_WITH_AUDIO msg = types.Message(**MESSAGE_WITH_AUDIO) - async with FakeTelegram(message_data=MESSAGE_WITH_AUDIO, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE_WITH_AUDIO): result = await bot.send_audio(chat_id=msg.chat.id, audio=msg.audio.file_id, caption=msg.caption, parse_mode=types.ParseMode.HTML, duration=msg.audio.duration, performer=msg.audio.performer, title=msg.audio.title, disable_notification=False) assert result == msg -async def test_send_document(bot: Bot, event_loop): +async def test_send_document(bot: Bot): """ sendDocument method test with file_id """ from .types.dataset import MESSAGE_WITH_DOCUMENT msg = types.Message(**MESSAGE_WITH_DOCUMENT) - async with FakeTelegram(message_data=MESSAGE_WITH_DOCUMENT, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE_WITH_DOCUMENT): result = await bot.send_document(chat_id=msg.chat.id, document=msg.document.file_id, caption=msg.caption, parse_mode=types.ParseMode.HTML, disable_notification=False) assert result == msg -async def test_send_video(bot: Bot, event_loop): +async def test_send_video(bot: Bot): """ sendVideo method test with file_id """ from .types.dataset import MESSAGE_WITH_VIDEO, VIDEO msg = types.Message(**MESSAGE_WITH_VIDEO) video = types.Video(**VIDEO) - async with FakeTelegram(message_data=MESSAGE_WITH_VIDEO, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE_WITH_VIDEO): result = await bot.send_video(chat_id=msg.chat.id, video=video.file_id, duration=video.duration, width=video.width, height=video.height, caption=msg.caption, parse_mode=types.ParseMode.HTML, supports_streaming=True, @@ -110,204 +110,204 @@ async def test_send_video(bot: Bot, event_loop): assert result == msg -async def test_send_voice(bot: Bot, event_loop): +async def test_send_voice(bot: Bot): """ sendVoice method test with file_id """ from .types.dataset import MESSAGE_WITH_VOICE, VOICE msg = types.Message(**MESSAGE_WITH_VOICE) voice = types.Voice(**VOICE) - async with FakeTelegram(message_data=MESSAGE_WITH_VOICE, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE_WITH_VOICE): result = await bot.send_voice(chat_id=msg.chat.id, voice=voice.file_id, caption=msg.caption, parse_mode=types.ParseMode.HTML, duration=voice.duration, disable_notification=False) assert result == msg -async def test_send_video_note(bot: Bot, event_loop): +async def test_send_video_note(bot: Bot): """ sendVideoNote method test with file_id """ from .types.dataset import MESSAGE_WITH_VIDEO_NOTE, VIDEO_NOTE msg = types.Message(**MESSAGE_WITH_VIDEO_NOTE) video_note = types.VideoNote(**VIDEO_NOTE) - async with FakeTelegram(message_data=MESSAGE_WITH_VIDEO_NOTE, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE_WITH_VIDEO_NOTE): result = await bot.send_video_note(chat_id=msg.chat.id, video_note=video_note.file_id, duration=video_note.duration, length=video_note.length, disable_notification=False) assert result == msg -async def test_send_media_group(bot: Bot, event_loop): +async def test_send_media_group(bot: Bot): """ sendMediaGroup method test with file_id """ from .types.dataset import MESSAGE_WITH_MEDIA_GROUP, PHOTO msg = types.Message(**MESSAGE_WITH_MEDIA_GROUP) photo = types.PhotoSize(**PHOTO) media = [types.InputMediaPhoto(media=photo.file_id), types.InputMediaPhoto(media=photo.file_id)] - async with FakeTelegram(message_data=[MESSAGE_WITH_MEDIA_GROUP, MESSAGE_WITH_MEDIA_GROUP], loop=event_loop): + async with FakeTelegram(message_data=[MESSAGE_WITH_MEDIA_GROUP, MESSAGE_WITH_MEDIA_GROUP]): result = await bot.send_media_group(msg.chat.id, media=media, disable_notification=False) assert len(result) == len(media) assert result.pop().media_group_id -async def test_send_location(bot: Bot, event_loop): +async def test_send_location(bot: Bot): """ sendLocation method test """ from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION msg = types.Message(**MESSAGE_WITH_LOCATION) location = types.Location(**LOCATION) - async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION): result = await bot.send_location(msg.chat.id, latitude=location.latitude, longitude=location.longitude, live_period=10, disable_notification=False) assert result == msg -async def test_edit_message_live_location_by_bot(bot: Bot, event_loop): +async def test_edit_message_live_location_by_bot(bot: Bot): """ editMessageLiveLocation method test """ from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION msg = types.Message(**MESSAGE_WITH_LOCATION) location = types.Location(**LOCATION) # editing bot message - async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION): result = await bot.edit_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id, latitude=location.latitude, longitude=location.longitude) assert result == msg -async def test_edit_message_live_location_by_user(bot: Bot, event_loop): +async def test_edit_message_live_location_by_user(bot: Bot): """ editMessageLiveLocation method test """ from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION msg = types.Message(**MESSAGE_WITH_LOCATION) location = types.Location(**LOCATION) # editing user's message - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.edit_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id, latitude=location.latitude, longitude=location.longitude) assert isinstance(result, bool) and result is True -async def test_stop_message_live_location_by_bot(bot: Bot, event_loop): +async def test_stop_message_live_location_by_bot(bot: Bot): """ stopMessageLiveLocation method test """ from .types.dataset import MESSAGE_WITH_LOCATION msg = types.Message(**MESSAGE_WITH_LOCATION) # stopping bot message - async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION): result = await bot.stop_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id) assert result == msg -async def test_stop_message_live_location_by_user(bot: Bot, event_loop): +async def test_stop_message_live_location_by_user(bot: Bot): """ stopMessageLiveLocation method test """ from .types.dataset import MESSAGE_WITH_LOCATION msg = types.Message(**MESSAGE_WITH_LOCATION) # stopping user's message - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.stop_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id) assert isinstance(result, bool) assert result is True -async def test_send_venue(bot: Bot, event_loop): +async def test_send_venue(bot: Bot): """ sendVenue method test """ from .types.dataset import MESSAGE_WITH_VENUE, VENUE, LOCATION msg = types.Message(**MESSAGE_WITH_VENUE) location = types.Location(**LOCATION) venue = types.Venue(**VENUE) - async with FakeTelegram(message_data=MESSAGE_WITH_VENUE, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE_WITH_VENUE): result = await bot.send_venue(msg.chat.id, latitude=location.latitude, longitude=location.longitude, title=venue.title, address=venue.address, foursquare_id=venue.foursquare_id, disable_notification=False) assert result == msg -async def test_send_contact(bot: Bot, event_loop): +async def test_send_contact(bot: Bot): """ sendContact method test """ from .types.dataset import MESSAGE_WITH_CONTACT, CONTACT msg = types.Message(**MESSAGE_WITH_CONTACT) contact = types.Contact(**CONTACT) - async with FakeTelegram(message_data=MESSAGE_WITH_CONTACT, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE_WITH_CONTACT): result = await bot.send_contact(msg.chat.id, phone_number=contact.phone_number, first_name=contact.first_name, last_name=contact.last_name, disable_notification=False) assert result == msg -async def test_send_dice(bot: Bot, event_loop): +async def test_send_dice(bot: Bot): """ sendDice method test """ from .types.dataset import MESSAGE_WITH_DICE msg = types.Message(**MESSAGE_WITH_DICE) - async with FakeTelegram(message_data=MESSAGE_WITH_DICE, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE_WITH_DICE): result = await bot.send_dice(msg.chat.id, disable_notification=False) assert result == msg -async def test_send_chat_action(bot: Bot, event_loop): +async def test_send_chat_action(bot: Bot): """ sendChatAction method test """ from .types.dataset import CHAT chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.send_chat_action(chat_id=chat.id, action=types.ChatActions.TYPING) assert isinstance(result, bool) assert result is True -async def test_get_user_profile_photo(bot: Bot, event_loop): +async def test_get_user_profile_photo(bot: Bot): """ getUserProfilePhotos method test """ from .types.dataset import USER_PROFILE_PHOTOS, USER user = types.User(**USER) - async with FakeTelegram(message_data=USER_PROFILE_PHOTOS, loop=event_loop): + async with FakeTelegram(message_data=USER_PROFILE_PHOTOS): result = await bot.get_user_profile_photos(user_id=user.id, offset=1, limit=1) assert isinstance(result, types.UserProfilePhotos) -async def test_get_file(bot: Bot, event_loop): +async def test_get_file(bot: Bot): """ getFile method test """ from .types.dataset import FILE file = types.File(**FILE) - async with FakeTelegram(message_data=FILE, loop=event_loop): + async with FakeTelegram(message_data=FILE): result = await bot.get_file(file_id=file.file_id) assert isinstance(result, types.File) -async def test_kick_chat_member(bot: Bot, event_loop): +async def test_kick_chat_member(bot: Bot): """ kickChatMember method test """ from .types.dataset import USER, CHAT user = types.User(**USER) chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.kick_chat_member(chat_id=chat.id, user_id=user.id, until_date=123) assert isinstance(result, bool) assert result is True -async def test_unban_chat_member(bot: Bot, event_loop): +async def test_unban_chat_member(bot: Bot): """ unbanChatMember method test """ from .types.dataset import USER, CHAT user = types.User(**USER) chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.unban_chat_member(chat_id=chat.id, user_id=user.id) assert isinstance(result, bool) assert result is True -async def test_restrict_chat_member(bot: Bot, event_loop): +async def test_restrict_chat_member(bot: Bot): """ restrictChatMember method test """ from .types.dataset import USER, CHAT user = types.User(**USER) chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.restrict_chat_member( chat_id=chat.id, user_id=user.id, @@ -321,13 +321,13 @@ async def test_restrict_chat_member(bot: Bot, event_loop): assert result is True -async def test_promote_chat_member(bot: Bot, event_loop): +async def test_promote_chat_member(bot: Bot): """ promoteChatMember method test """ from .types.dataset import USER, CHAT user = types.User(**USER) chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.promote_chat_member(chat_id=chat.id, user_id=user.id, can_change_info=True, can_delete_messages=True, can_edit_messages=True, can_invite_users=True, can_pin_messages=True, can_post_messages=True, @@ -336,208 +336,208 @@ async def test_promote_chat_member(bot: Bot, event_loop): assert result is True -async def test_export_chat_invite_link(bot: Bot, event_loop): +async def test_export_chat_invite_link(bot: Bot): """ exportChatInviteLink method test """ from .types.dataset import CHAT, INVITE_LINK chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=INVITE_LINK, loop=event_loop): + async with FakeTelegram(message_data=INVITE_LINK): result = await bot.export_chat_invite_link(chat_id=chat.id) assert result == INVITE_LINK -async def test_delete_chat_photo(bot: Bot, event_loop): +async def test_delete_chat_photo(bot: Bot): """ deleteChatPhoto method test """ from .types.dataset import CHAT chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.delete_chat_photo(chat_id=chat.id) assert isinstance(result, bool) assert result is True -async def test_set_chat_title(bot: Bot, event_loop): +async def test_set_chat_title(bot: Bot): """ setChatTitle method test """ from .types.dataset import CHAT chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.set_chat_title(chat_id=chat.id, title='Test title') assert isinstance(result, bool) assert result is True -async def test_set_chat_description(bot: Bot, event_loop): +async def test_set_chat_description(bot: Bot): """ setChatDescription method test """ from .types.dataset import CHAT chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.set_chat_description(chat_id=chat.id, description='Test description') assert isinstance(result, bool) assert result is True -async def test_pin_chat_message(bot: Bot, event_loop): +async def test_pin_chat_message(bot: Bot): """ pinChatMessage method test """ from .types.dataset import MESSAGE message = types.Message(**MESSAGE) - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.pin_chat_message(chat_id=message.chat.id, message_id=message.message_id, disable_notification=False) assert isinstance(result, bool) assert result is True -async def test_unpin_chat_message(bot: Bot, event_loop): +async def test_unpin_chat_message(bot: Bot): """ unpinChatMessage method test """ from .types.dataset import CHAT chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.unpin_chat_message(chat_id=chat.id) assert isinstance(result, bool) assert result is True -async def test_leave_chat(bot: Bot, event_loop): +async def test_leave_chat(bot: Bot): """ leaveChat method test """ from .types.dataset import CHAT chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.leave_chat(chat_id=chat.id) assert isinstance(result, bool) assert result is True -async def test_get_chat(bot: Bot, event_loop): +async def test_get_chat(bot: Bot): """ getChat method test """ from .types.dataset import CHAT chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=CHAT, loop=event_loop): + async with FakeTelegram(message_data=CHAT): result = await bot.get_chat(chat_id=chat.id) assert result == chat -async def test_get_chat_administrators(bot: Bot, event_loop): +async def test_get_chat_administrators(bot: Bot): """ getChatAdministrators method test """ from .types.dataset import CHAT, CHAT_MEMBER chat = types.Chat(**CHAT) member = types.ChatMember(**CHAT_MEMBER) - async with FakeTelegram(message_data=[CHAT_MEMBER, CHAT_MEMBER], loop=event_loop): + async with FakeTelegram(message_data=[CHAT_MEMBER, CHAT_MEMBER]): result = await bot.get_chat_administrators(chat_id=chat.id) assert result[0] == member assert len(result) == 2 -async def test_get_chat_members_count(bot: Bot, event_loop): +async def test_get_chat_members_count(bot: Bot): """ getChatMembersCount method test """ from .types.dataset import CHAT chat = types.Chat(**CHAT) count = 5 - async with FakeTelegram(message_data=count, loop=event_loop): + async with FakeTelegram(message_data=count): result = await bot.get_chat_members_count(chat_id=chat.id) assert result == count -async def test_get_chat_member(bot: Bot, event_loop): +async def test_get_chat_member(bot: Bot): """ getChatMember method test """ from .types.dataset import CHAT, CHAT_MEMBER chat = types.Chat(**CHAT) member = types.ChatMember(**CHAT_MEMBER) - async with FakeTelegram(message_data=CHAT_MEMBER, loop=event_loop): + async with FakeTelegram(message_data=CHAT_MEMBER): result = await bot.get_chat_member(chat_id=chat.id, user_id=member.user.id) assert isinstance(result, types.ChatMember) assert result == member -async def test_set_chat_sticker_set(bot: Bot, event_loop): +async def test_set_chat_sticker_set(bot: Bot): """ setChatStickerSet method test """ from .types.dataset import CHAT chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.set_chat_sticker_set(chat_id=chat.id, sticker_set_name='aiogram_stickers') assert isinstance(result, bool) assert result is True -async def test_delete_chat_sticker_set(bot: Bot, event_loop): +async def test_delete_chat_sticker_set(bot: Bot): """ setChatStickerSet method test """ from .types.dataset import CHAT chat = types.Chat(**CHAT) - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.delete_chat_sticker_set(chat_id=chat.id) assert isinstance(result, bool) assert result is True -async def test_answer_callback_query(bot: Bot, event_loop): +async def test_answer_callback_query(bot: Bot): """ answerCallbackQuery method test """ - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.answer_callback_query(callback_query_id='QuERyId', text='Test Answer') assert isinstance(result, bool) assert result is True -async def test_set_my_commands(bot: Bot, event_loop): +async def test_set_my_commands(bot: Bot): """ setMyCommands method test """ from .types.dataset import BOT_COMMAND - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): commands = [types.BotCommand(**BOT_COMMAND), types.BotCommand(**BOT_COMMAND)] result = await bot.set_my_commands(commands) assert isinstance(result, bool) assert result is True -async def test_get_my_commands(bot: Bot, event_loop): +async def test_get_my_commands(bot: Bot): """ getMyCommands method test """ from .types.dataset import BOT_COMMAND command = types.BotCommand(**BOT_COMMAND) commands = [command, command] - async with FakeTelegram(message_data=commands, loop=event_loop): + async with FakeTelegram(message_data=commands): result = await bot.get_my_commands() assert isinstance(result, list) assert all([isinstance(command, types.BotCommand) for command in result]) -async def test_edit_message_text_by_bot(bot: Bot, event_loop): +async def test_edit_message_text_by_bot(bot: Bot): """ editMessageText method test """ from .types.dataset import EDITED_MESSAGE msg = types.Message(**EDITED_MESSAGE) # message by bot - async with FakeTelegram(message_data=EDITED_MESSAGE, loop=event_loop): + async with FakeTelegram(message_data=EDITED_MESSAGE): result = await bot.edit_message_text(text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id) assert result == msg -async def test_edit_message_text_by_user(bot: Bot, event_loop): +async def test_edit_message_text_by_user(bot: Bot): """ editMessageText method test """ from .types.dataset import EDITED_MESSAGE msg = types.Message(**EDITED_MESSAGE) # message by user - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.edit_message_text(text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id) assert isinstance(result, bool) assert result is True -async def test_set_sticker_set_thumb(bot: Bot, event_loop): +async def test_set_sticker_set_thumb(bot: Bot): """ setStickerSetThumb method test """ - async with FakeTelegram(message_data=True, loop=event_loop): + async with FakeTelegram(message_data=True): result = await bot.set_sticker_set_thumb(name='test', user_id=123456789, thumb='file_id') assert isinstance(result, bool) assert result is True diff --git a/tests/test_dispatcher.py b/tests/test_dispatcher.py index 6ebaf472..81ae565c 100644 --- a/tests/test_dispatcher.py +++ b/tests/test_dispatcher.py @@ -5,11 +5,10 @@ from aiogram import Dispatcher, Bot pytestmark = pytest.mark.asyncio -@pytest.yield_fixture() -async def bot(event_loop): +@pytest.fixture(name='bot') +async def bot_fixture(): """ Bot fixture """ - _bot = Bot(token='123456789:AABBCCDDEEFFaabbccddeeff-1234567890', - loop=event_loop) + _bot = Bot(token='123456789:AABBCCDDEEFFaabbccddeeff-1234567890') yield _bot await _bot.close() diff --git a/tests/test_message.py b/tests/test_message.py index 32168d57..6fca789f 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -8,16 +8,16 @@ from . import FakeTelegram, TOKEN pytestmark = pytest.mark.asyncio -@pytest.yield_fixture() -async def bot(event_loop): +@pytest.fixture(name='bot') +async def bot_fixture(): """ Bot fixture """ - _bot = Bot(TOKEN, loop=event_loop, parse_mode=types.ParseMode.HTML) + _bot = Bot(TOKEN, parse_mode=types.ParseMode.HTML) yield _bot await _bot.close() -@pytest.yield_fixture() -async def message(bot, event_loop): +@pytest.fixture() +async def message(bot): """ Message fixture :param bot: Telegram bot fixture @@ -28,7 +28,7 @@ async def message(bot, event_loop): from .types.dataset import MESSAGE msg = types.Message(**MESSAGE) - async with FakeTelegram(message_data=MESSAGE, loop=event_loop): + async with FakeTelegram(message_data=MESSAGE): _message = await bot.send_message(chat_id=msg.chat.id, text=msg.text) yield _message From 1349554dfd1f5c34523b5277427bb5f75f744125 Mon Sep 17 00:00:00 2001 From: Felix Yan Date: Tue, 12 Jan 2021 14:31:08 -0600 Subject: [PATCH 10/10] Update installation instruction for Arch (#490) * Update installation instruction for Arch The package is now available in the official repository. * Add pacman command example * Add an additional empty line --- docs/source/install.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/source/install.rst b/docs/source/install.rst index e4717a42..74c12865 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -13,9 +13,13 @@ Using Pipenv $ pipenv install aiogram -Using AUR +Using Pacman --------- -*aiogram* is also available in Arch User Repository, so you can install this framework on any Arch-based distribution like ArchLinux, Antergos, Manjaro, etc. To do this, use your favorite AUR-helper and install the `python-aiogram `_ package. +*aiogram* is also available in Arch Linux Repository, so you can install this framework on any Arch-based distribution like Arch Linux, Antergos, Manjaro, etc. To do this, just use pacman to install the `python-aiogram `_ package: + + .. code-block:: bash + + $ pacman -S python-aiogram From sources ------------