mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-06 07:50:32 +00:00
commit
b5e351c749
6 changed files with 727 additions and 117 deletions
|
|
@ -606,7 +606,7 @@ class Bot(BaseBot):
|
|||
|
||||
:param chat_id: Unique identifier for the target chat or username of the target channel
|
||||
:type chat_id: :obj:`typing.Union[base.Integer, base.String]`
|
||||
:param media: A JSON-serialized array describing photos and videos to be sent
|
||||
:param media: A JSON-serialized array describing photos and videos to be sent. Must include 2–10 items
|
||||
:type media: :obj:`typing.Union[types.MediaGroup, typing.List]`
|
||||
:param disable_notification: Sends the message silently. Users will receive a notification with no sound.
|
||||
:type disable_notification: :obj:`typing.Union[base.Boolean, None]`
|
||||
|
|
|
|||
|
|
@ -130,9 +130,9 @@ class InputMediaPhoto(InputMedia):
|
|||
https://core.telegram.org/bots/api#inputmediaphoto
|
||||
"""
|
||||
|
||||
def __init__(self, media: base.InputFile, thumb: typing.Union[base.InputFile, base.String] = None,
|
||||
def __init__(self, media: typing.Union[base.InputFile, base.String],
|
||||
caption: base.String = None, parse_mode: base.Boolean = None, **kwargs):
|
||||
super(InputMediaPhoto, self).__init__(type='photo', media=media, thumb=thumb,
|
||||
super(InputMediaPhoto, self).__init__(type='photo', media=media,
|
||||
caption=caption, parse_mode=parse_mode,
|
||||
conf=kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
import aresponses
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
from aiogram.dispatcher import ctx
|
||||
from aiogram import Bot
|
||||
|
||||
TOKEN = '123456789:AABBCCDDEEFFaabbccddeeff-1234567890'
|
||||
|
||||
|
||||
class FakeTelegram(aresponses.ResponsesMockServer):
|
||||
def __init__(self, message_dict, bot=None, monkeypatch=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self._body, self._headers = self.parse_data(message_dict)
|
||||
|
||||
if isinstance(bot, Bot) and monkeypatch:
|
||||
self.monkeypatch = monkeypatch
|
||||
self.monkeypatch.setattr(ctx, 'get_bot', lambda: bot)
|
||||
|
||||
async def __aenter__(self):
|
||||
await super().__aenter__()
|
||||
_response = self.Response(text=self._body, headers=self._headers, status=200, reason='OK')
|
||||
self.add(self.ANY, response=_response)
|
||||
|
||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||
if hasattr(self, 'monkeypatch'):
|
||||
self.monkeypatch.undo()
|
||||
await super().__aexit__(exc_type, exc_val, exc_tb)
|
||||
|
||||
@staticmethod
|
||||
def parse_data(message_dict):
|
||||
import json
|
||||
|
||||
_body = '{"ok":true,"result":' + json.dumps(message_dict) + '}'
|
||||
_headers = {'Server': 'nginx/1.12.2',
|
||||
'Date': 'Tue, 03 Apr 2018 16:59:54 GMT',
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': str(len(_body)),
|
||||
'Connection': 'keep-alive',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
||||
'Access-Control-Expose-Headers': 'Content-Length,Content-Type,Date,Server,Connection',
|
||||
'Strict-Transport-Security': 'max-age=31536000; includeSubdomains'}
|
||||
return _body, _headers
|
||||
|
|
@ -1,40 +1,14 @@
|
|||
import aresponses
|
||||
from asyncio import BaseEventLoop
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram import Bot, types
|
||||
from . import FakeTelegram, TOKEN
|
||||
|
||||
TOKEN = '123456789:AABBCCDDEEFFaabbccddeeff-1234567890'
|
||||
|
||||
|
||||
class FakeTelegram(aresponses.ResponsesMockServer):
|
||||
def __init__(self, message_dict, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self._body, self._headers = self.parse_data(message_dict)
|
||||
|
||||
async def __aenter__(self):
|
||||
await super().__aenter__()
|
||||
_response = self.Response(text=self._body, headers=self._headers, status=200, reason='OK')
|
||||
self.add(self.ANY, response=_response)
|
||||
|
||||
@staticmethod
|
||||
def parse_data(message_dict):
|
||||
import json
|
||||
|
||||
_body = '{"ok":true,"result":' + json.dumps(message_dict) + '}'
|
||||
_headers = {'Server': 'nginx/1.12.2',
|
||||
'Date': 'Tue, 03 Apr 2018 16:59:54 GMT',
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': str(len(_body)),
|
||||
'Connection': 'keep-alive',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
||||
'Access-Control-Expose-Headers': 'Content-Length,Content-Type,Date,Server,Connection',
|
||||
'Strict-Transport-Security': 'max-age=31536000; includeSubdomains'}
|
||||
return _body, _headers
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
@pytest.yield_fixture()
|
||||
@pytest.mark.asyncio
|
||||
async def bot(event_loop):
|
||||
""" Bot fixture """
|
||||
_bot = Bot(TOKEN, loop=event_loop, parse_mode=types.ParseMode.MARKDOWN)
|
||||
|
|
@ -42,8 +16,7 @@ async def bot(event_loop):
|
|||
await _bot.close()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_me(bot: Bot, event_loop):
|
||||
async def test_get_me(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" getMe method test """
|
||||
from .types.dataset import USER
|
||||
user = types.User(**USER)
|
||||
|
|
@ -53,8 +26,7 @@ async def test_get_me(bot: Bot, event_loop):
|
|||
assert result == user
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_message(bot: Bot, event_loop):
|
||||
async def test_send_message(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" sendMessage method test """
|
||||
from .types.dataset import MESSAGE
|
||||
msg = types.Message(**MESSAGE)
|
||||
|
|
@ -64,8 +36,7 @@ async def test_send_message(bot: Bot, event_loop):
|
|||
assert result == msg
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_forward_message(bot: Bot, event_loop):
|
||||
async def test_forward_message(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" forwardMessage method test """
|
||||
from .types.dataset import FORWARDED_MESSAGE
|
||||
msg = types.Message(**FORWARDED_MESSAGE)
|
||||
|
|
@ -76,8 +47,7 @@ async def test_forward_message(bot: Bot, event_loop):
|
|||
assert result == msg
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_photo(bot: Bot, event_loop):
|
||||
async def test_send_photo(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" sendPhoto method test with file_id """
|
||||
from .types.dataset import MESSAGE_WITH_PHOTO, PHOTO
|
||||
msg = types.Message(**MESSAGE_WITH_PHOTO)
|
||||
|
|
@ -89,8 +59,7 @@ async def test_send_photo(bot: Bot, event_loop):
|
|||
assert result == msg
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_audio(bot: Bot, event_loop):
|
||||
async def test_send_audio(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" sendAudio method test with file_id """
|
||||
from .types.dataset import MESSAGE_WITH_AUDIO
|
||||
msg = types.Message(**MESSAGE_WITH_AUDIO)
|
||||
|
|
@ -102,8 +71,7 @@ async def test_send_audio(bot: Bot, event_loop):
|
|||
assert result == msg
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_document(bot: Bot, event_loop):
|
||||
async def test_send_document(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" sendDocument method test with file_id """
|
||||
from .types.dataset import MESSAGE_WITH_DOCUMENT
|
||||
msg = types.Message(**MESSAGE_WITH_DOCUMENT)
|
||||
|
|
@ -114,8 +82,7 @@ async def test_send_document(bot: Bot, event_loop):
|
|||
assert result == msg
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_video(bot: Bot, event_loop):
|
||||
async def test_send_video(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" sendVideo method test with file_id """
|
||||
from .types.dataset import MESSAGE_WITH_VIDEO, VIDEO
|
||||
msg = types.Message(**MESSAGE_WITH_VIDEO)
|
||||
|
|
@ -129,8 +96,7 @@ async def test_send_video(bot: Bot, event_loop):
|
|||
assert result == msg
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_voice(bot: Bot, event_loop):
|
||||
async def test_send_voice(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" sendVoice method test with file_id """
|
||||
from .types.dataset import MESSAGE_WITH_VOICE, VOICE
|
||||
msg = types.Message(**MESSAGE_WITH_VOICE)
|
||||
|
|
@ -143,8 +109,7 @@ async def test_send_voice(bot: Bot, event_loop):
|
|||
assert result == msg
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_video_note(bot: Bot, event_loop):
|
||||
async def test_send_video_note(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" sendVideoNote method test with file_id """
|
||||
from .types.dataset import MESSAGE_WITH_VIDEO_NOTE, VIDEO_NOTE
|
||||
msg = types.Message(**MESSAGE_WITH_VIDEO_NOTE)
|
||||
|
|
@ -157,8 +122,7 @@ async def test_send_video_note(bot: Bot, event_loop):
|
|||
assert result == msg
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_media_group(bot: Bot, event_loop):
|
||||
async def test_send_media_group(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" sendMediaGroup method test with file_id """
|
||||
from .types.dataset import MESSAGE_WITH_MEDIA_GROUP, PHOTO
|
||||
msg = types.Message(**MESSAGE_WITH_MEDIA_GROUP)
|
||||
|
|
@ -171,8 +135,7 @@ async def test_send_media_group(bot: Bot, event_loop):
|
|||
assert result.pop().media_group_id
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_location(bot: Bot, event_loop):
|
||||
async def test_send_location(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" sendLocation method test """
|
||||
from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION
|
||||
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
||||
|
|
@ -184,8 +147,7 @@ async def test_send_location(bot: Bot, event_loop):
|
|||
assert result == msg
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_edit_message_live_location(bot: Bot, event_loop):
|
||||
async def test_edit_message_live_location(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" editMessageLiveLocation method test """
|
||||
from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION
|
||||
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
||||
|
|
@ -204,8 +166,7 @@ async def test_edit_message_live_location(bot: Bot, event_loop):
|
|||
assert isinstance(result, bool) and result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_message_live_location(bot: Bot, event_loop):
|
||||
async def test_stop_message_live_location(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" stopMessageLiveLocation method test """
|
||||
from .types.dataset import MESSAGE_WITH_LOCATION
|
||||
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
||||
|
|
@ -222,8 +183,7 @@ async def test_stop_message_live_location(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_venue(bot: Bot, event_loop):
|
||||
async def test_send_venue(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" sendVenue method test """
|
||||
from .types.dataset import MESSAGE_WITH_VENUE, VENUE, LOCATION
|
||||
msg = types.Message(**MESSAGE_WITH_VENUE)
|
||||
|
|
@ -237,8 +197,7 @@ async def test_send_venue(bot: Bot, event_loop):
|
|||
assert result == msg
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_contact(bot: Bot, event_loop):
|
||||
async def test_send_contact(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" sendContact method test """
|
||||
from .types.dataset import MESSAGE_WITH_CONTACT, CONTACT
|
||||
msg = types.Message(**MESSAGE_WITH_CONTACT)
|
||||
|
|
@ -250,8 +209,7 @@ async def test_send_contact(bot: Bot, event_loop):
|
|||
assert result == msg
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_chat_action(bot: Bot, event_loop):
|
||||
async def test_send_chat_action(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" sendChatAction method test """
|
||||
from .types.dataset import CHAT
|
||||
chat = types.Chat(**CHAT)
|
||||
|
|
@ -262,8 +220,7 @@ async def test_send_chat_action(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_user_profile_photo(bot: Bot, event_loop):
|
||||
async def test_get_user_profile_photo(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" getUserProfilePhotos method test """
|
||||
from .types.dataset import USER_PROFILE_PHOTOS, USER
|
||||
user = types.User(**USER)
|
||||
|
|
@ -273,8 +230,7 @@ async def test_get_user_profile_photo(bot: Bot, event_loop):
|
|||
assert isinstance(result, types.UserProfilePhotos)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_file(bot: Bot, event_loop):
|
||||
async def test_get_file(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" getFile method test """
|
||||
from .types.dataset import FILE
|
||||
file = types.File(**FILE)
|
||||
|
|
@ -284,8 +240,7 @@ async def test_get_file(bot: Bot, event_loop):
|
|||
assert isinstance(result, types.File)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_kick_chat_member(bot: Bot, event_loop):
|
||||
async def test_kick_chat_member(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" kickChatMember method test """
|
||||
from .types.dataset import USER, CHAT
|
||||
user = types.User(**USER)
|
||||
|
|
@ -297,8 +252,7 @@ async def test_kick_chat_member(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unban_chat_member(bot: Bot, event_loop):
|
||||
async def test_unban_chat_member(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" unbanChatMember method test """
|
||||
from .types.dataset import USER, CHAT
|
||||
user = types.User(**USER)
|
||||
|
|
@ -310,8 +264,7 @@ async def test_unban_chat_member(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_restrict_chat_member(bot: Bot, event_loop):
|
||||
async def test_restrict_chat_member(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" restrictChatMember method test """
|
||||
from .types.dataset import USER, CHAT
|
||||
user = types.User(**USER)
|
||||
|
|
@ -325,8 +278,7 @@ async def test_restrict_chat_member(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_promote_chat_member(bot: Bot, event_loop):
|
||||
async def test_promote_chat_member(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" promoteChatMember method test """
|
||||
from .types.dataset import USER, CHAT
|
||||
user = types.User(**USER)
|
||||
|
|
@ -341,8 +293,7 @@ async def test_promote_chat_member(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_export_chat_invite_link(bot: Bot, event_loop):
|
||||
async def test_export_chat_invite_link(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" exportChatInviteLink method test """
|
||||
from .types.dataset import CHAT, INVITE_LINK
|
||||
chat = types.Chat(**CHAT)
|
||||
|
|
@ -352,8 +303,7 @@ async def test_export_chat_invite_link(bot: Bot, event_loop):
|
|||
assert result == INVITE_LINK
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_chat_photo(bot: Bot, event_loop):
|
||||
async def test_delete_chat_photo(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" deleteChatPhoto method test """
|
||||
from .types.dataset import CHAT
|
||||
chat = types.Chat(**CHAT)
|
||||
|
|
@ -364,8 +314,7 @@ async def test_delete_chat_photo(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_chat_title(bot: Bot, event_loop):
|
||||
async def test_set_chat_title(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" setChatTitle method test """
|
||||
from .types.dataset import CHAT
|
||||
chat = types.Chat(**CHAT)
|
||||
|
|
@ -376,8 +325,7 @@ async def test_set_chat_title(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_chat_description(bot: Bot, event_loop):
|
||||
async def test_set_chat_description(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" setChatDescription method test """
|
||||
from .types.dataset import CHAT
|
||||
chat = types.Chat(**CHAT)
|
||||
|
|
@ -388,8 +336,7 @@ async def test_set_chat_description(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pin_chat_message(bot: Bot, event_loop):
|
||||
async def test_pin_chat_message(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" pinChatMessage method test """
|
||||
from .types.dataset import MESSAGE
|
||||
message = types.Message(**MESSAGE)
|
||||
|
|
@ -401,8 +348,7 @@ async def test_pin_chat_message(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unpin_chat_message(bot: Bot, event_loop):
|
||||
async def test_unpin_chat_message(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" unpinChatMessage method test """
|
||||
from .types.dataset import CHAT
|
||||
chat = types.Chat(**CHAT)
|
||||
|
|
@ -413,8 +359,7 @@ async def test_unpin_chat_message(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_leave_chat(bot: Bot, event_loop):
|
||||
async def test_leave_chat(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" leaveChat method test """
|
||||
from .types.dataset import CHAT
|
||||
chat = types.Chat(**CHAT)
|
||||
|
|
@ -425,8 +370,7 @@ async def test_leave_chat(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_chat(bot: Bot, event_loop):
|
||||
async def test_get_chat(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" getChat method test """
|
||||
from .types.dataset import CHAT
|
||||
chat = types.Chat(**CHAT)
|
||||
|
|
@ -436,8 +380,7 @@ async def test_get_chat(bot: Bot, event_loop):
|
|||
assert result == chat
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_chat_administrators(bot: Bot, event_loop):
|
||||
async def test_get_chat_administrators(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" getChatAdministrators method test """
|
||||
from .types.dataset import CHAT, CHAT_MEMBER
|
||||
chat = types.Chat(**CHAT)
|
||||
|
|
@ -449,8 +392,7 @@ async def test_get_chat_administrators(bot: Bot, event_loop):
|
|||
assert len(result) == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_chat_members_count(bot: Bot, event_loop):
|
||||
async def test_get_chat_members_count(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" getChatMembersCount method test """
|
||||
from .types.dataset import CHAT
|
||||
chat = types.Chat(**CHAT)
|
||||
|
|
@ -461,8 +403,7 @@ async def test_get_chat_members_count(bot: Bot, event_loop):
|
|||
assert result == count
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_chat_member(bot: Bot, event_loop):
|
||||
async def test_get_chat_member(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" getChatMember method test """
|
||||
from .types.dataset import CHAT, CHAT_MEMBER
|
||||
chat = types.Chat(**CHAT)
|
||||
|
|
@ -474,8 +415,7 @@ async def test_get_chat_member(bot: Bot, event_loop):
|
|||
assert result == member
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_chat_sticker_set(bot: Bot, event_loop):
|
||||
async def test_set_chat_sticker_set(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" setChatStickerSet method test """
|
||||
from .types.dataset import CHAT
|
||||
chat = types.Chat(**CHAT)
|
||||
|
|
@ -486,8 +426,7 @@ async def test_set_chat_sticker_set(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_chat_sticker_set(bot: Bot, event_loop):
|
||||
async def test_delete_chat_sticker_set(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" setChatStickerSet method test """
|
||||
from .types.dataset import CHAT
|
||||
chat = types.Chat(**CHAT)
|
||||
|
|
@ -498,8 +437,7 @@ async def test_delete_chat_sticker_set(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_answer_callback_query(bot: Bot, event_loop):
|
||||
async def test_answer_callback_query(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" answerCallbackQuery method test """
|
||||
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
|
|
@ -508,8 +446,7 @@ async def test_answer_callback_query(bot: Bot, event_loop):
|
|||
assert result is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_edit_message_text(bot: Bot, event_loop):
|
||||
async def test_edit_message_text(bot: Bot, event_loop: BaseEventLoop):
|
||||
""" editMessageText method test """
|
||||
from .types.dataset import EDITED_MESSAGE
|
||||
msg = types.Message(**EDITED_MESSAGE)
|
||||
|
|
|
|||
480
tests/test_message.py
Normal file
480
tests/test_message.py
Normal file
|
|
@ -0,0 +1,480 @@
|
|||
from asyncio import BaseEventLoop
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram import Bot, types
|
||||
from . import FakeTelegram, TOKEN
|
||||
from .types import dataset
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
@pytest.yield_fixture()
|
||||
async def bot(event_loop):
|
||||
""" Bot fixture """
|
||||
_bot = Bot(TOKEN, loop=event_loop, parse_mode=types.ParseMode.HTML)
|
||||
yield _bot
|
||||
await _bot.close()
|
||||
|
||||
|
||||
@pytest.yield_fixture()
|
||||
async def message(bot, event_loop):
|
||||
"""
|
||||
Message fixture
|
||||
|
||||
:param bot: Telegram bot fixture
|
||||
:type bot: Bot
|
||||
:param event_loop: asyncio event loop
|
||||
:type event_loop: BaseEventLoop
|
||||
"""
|
||||
from .types.dataset import MESSAGE
|
||||
msg = types.Message(**MESSAGE)
|
||||
|
||||
async with FakeTelegram(message_dict=MESSAGE, loop=event_loop):
|
||||
_message = await bot.send_message(chat_id=msg.chat.id, text=msg.text)
|
||||
|
||||
yield _message
|
||||
|
||||
|
||||
class TestMessageContentType:
|
||||
async def test_message_content_type_text(self):
|
||||
""" Test message with text content type """
|
||||
msg = types.Message(**dataset.MESSAGE)
|
||||
assert msg.content_type in types.ContentType.TEXT
|
||||
|
||||
async def test_message_content_type_audio(self):
|
||||
""" Test message with audio content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_AUDIO)
|
||||
assert msg.content_type in types.ContentType.AUDIO
|
||||
|
||||
async def test_message_content_type_animation(self):
|
||||
""" Test message with animation content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_ANIMATION)
|
||||
assert msg.content_type in types.ContentType.ANIMATION
|
||||
|
||||
async def test_message_content_type_document(self):
|
||||
""" Test message with document content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_DOCUMENT)
|
||||
assert msg.content_type in types.ContentType.DOCUMENT
|
||||
|
||||
async def test_message_content_type_game(self):
|
||||
""" Test message with game content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_GAME)
|
||||
assert msg.content_type in types.ContentType.GAME
|
||||
|
||||
async def test_message_content_type_photo(self):
|
||||
""" Test message with photo content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_PHOTO)
|
||||
assert msg.content_type in types.ContentType.PHOTO
|
||||
|
||||
async def test_message_content_type_sticker(self):
|
||||
""" Test message with sticker content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_STICKER)
|
||||
assert msg.content_type in types.ContentType.STICKER
|
||||
|
||||
async def test_message_content_type_video(self):
|
||||
""" Test message with video content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_VIDEO)
|
||||
assert msg.content_type in types.ContentType.VIDEO
|
||||
|
||||
async def test_message_content_type_video_note(self):
|
||||
""" Test message with video note content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_VIDEO_NOTE)
|
||||
assert msg.content_type in types.ContentType.VIDEO_NOTE
|
||||
|
||||
async def test_message_content_type_voice(self):
|
||||
""" Test message with voice content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_VOICE)
|
||||
assert msg.content_type in types.ContentType.VOICE
|
||||
|
||||
async def test_message_content_type_contact(self):
|
||||
""" Test message with contact content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_CONTACT)
|
||||
assert msg.content_type in types.ContentType.CONTACT
|
||||
|
||||
async def test_message_content_type_venue(self):
|
||||
""" Test message with venue content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_VENUE)
|
||||
assert msg.content_type in types.ContentType.VENUE
|
||||
|
||||
async def test_message_content_type_location(self):
|
||||
""" Test message with location content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_LOCATION)
|
||||
assert msg.content_type in types.ContentType.LOCATION
|
||||
|
||||
async def test_message_content_type_new_chat_members(self):
|
||||
""" Test message with new chat members content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_NEW_CHAT_MEMBERS)
|
||||
assert msg.content_type in types.ContentType.NEW_CHAT_MEMBERS
|
||||
|
||||
async def test_message_content_type_left_chat_member(self):
|
||||
""" Test message with left chat member content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_LEFT_CHAT_MEMBER)
|
||||
assert msg.content_type in types.ContentType.LEFT_CHAT_MEMBER
|
||||
|
||||
async def test_message_content_type_invoice(self):
|
||||
""" Test message with invoice content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_INVOICE)
|
||||
assert msg.content_type in types.ContentType.INVOICE
|
||||
|
||||
async def test_message_content_type_successful_payment(self):
|
||||
""" Test message with successful payment content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_SUCCESSFUL_PAYMENT)
|
||||
assert msg.content_type in types.ContentType.SUCCESSFUL_PAYMENT
|
||||
|
||||
@pytest.mark.skipif(not dataset.MESSAGE_WITH_CONNECTED_WEBSITE, reason='No MESSAGE_WITH_CONNECTED_WEBSITE')
|
||||
async def test_message_content_type_connected_website(self):
|
||||
""" Test message with connected website content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_CONNECTED_WEBSITE)
|
||||
assert msg.content_type in types.ContentType.CONNECTED_WEBSITE
|
||||
|
||||
async def test_message_content_type_migrate_from_chat_id(self):
|
||||
""" Test message with migrate from chat id content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_MIGRATE_FROM_CHAT_ID)
|
||||
assert msg.content_type in types.ContentType.MIGRATE_FROM_CHAT_ID
|
||||
|
||||
async def test_message_content_type_migrate_to_chat_id(self):
|
||||
""" Test message with migrate to chat id content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_MIGRATE_TO_CHAT_ID)
|
||||
assert msg.content_type in types.ContentType.MIGRATE_TO_CHAT_ID
|
||||
|
||||
async def test_message_content_type_pinned_message(self):
|
||||
""" Test message with pin content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_PINNED_MESSAGE)
|
||||
assert msg.content_type in types.ContentType.PINNED_MESSAGE
|
||||
|
||||
async def test_message_content_type_new_chat_title(self):
|
||||
""" Test message with new chat title content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_NEW_CHAT_TITLE)
|
||||
assert msg.content_type in types.ContentType.NEW_CHAT_TITLE
|
||||
|
||||
async def test_message_content_type_new_chat_photo(self):
|
||||
""" Test message with new chat photo content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_NEW_CHAT_PHOTO)
|
||||
assert msg.content_type in types.ContentType.NEW_CHAT_PHOTO
|
||||
|
||||
@pytest.mark.skipif(not dataset.MESSAGE_WITH_GROUP_CHAT_CREATED, reason='No MESSAGE_WITH_GROUP_CHAT_CREATED')
|
||||
async def test_message_content_type_group_chat_created(self):
|
||||
""" Test message with group created content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_GROUP_CHAT_CREATED)
|
||||
assert msg.content_type in types.ContentType.GROUP_CHAT_CREATED
|
||||
|
||||
@pytest.mark.skipif(not dataset.MESSAGE_WITH_PASSPORT_DATA, reason='No MESSAGE_WITH_PASSPORT_DATA')
|
||||
async def test_message_content_type_passport_data(self):
|
||||
""" Test message with passport data content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_PASSPORT_DATA)
|
||||
assert msg.content_type in types.ContentType.PASSPORT_DATA
|
||||
|
||||
async def test_message_content_type_unknown(self):
|
||||
""" Test message with unknown content type """
|
||||
msg = types.Message(**dataset.MESSAGE_UNKNOWN)
|
||||
assert msg.content_type in types.ContentType.UNKNOWN
|
||||
|
||||
async def test_message_content_type_delete_chat_photo(self):
|
||||
""" Test message with delete chat photo content type """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_DELETE_CHAT_PHOTO)
|
||||
assert msg.content_type in types.ContentType.DELETE_CHAT_PHOTO
|
||||
|
||||
|
||||
class TestMessageCommand:
|
||||
PURE_COMMAND = 'command'
|
||||
COMMAND = f'/{PURE_COMMAND}@TestBot'
|
||||
NOT_COMMAND = 'not command'
|
||||
ARGS = 'simple text'
|
||||
|
||||
async def test_message_is_command(self):
|
||||
msg = types.Message(text=self.COMMAND)
|
||||
assert msg.is_command() is True
|
||||
|
||||
async def test_message_is_not_command(self):
|
||||
msg = types.Message(text=self.NOT_COMMAND)
|
||||
assert msg.is_command() is False
|
||||
|
||||
async def test_message_get_full_command(self):
|
||||
msg = types.Message(text=f'{self.COMMAND} {self.ARGS}')
|
||||
command, args = msg.get_full_command()
|
||||
assert command == self.COMMAND
|
||||
assert args == self.ARGS
|
||||
|
||||
async def test_message_get_command(self):
|
||||
msg = types.Message(text=f'{self.COMMAND} {self.ARGS}')
|
||||
command = msg.get_command()
|
||||
assert command == self.COMMAND
|
||||
|
||||
async def test_message_get_command_pure(self):
|
||||
msg = types.Message(text=f'{self.COMMAND} {self.ARGS}')
|
||||
command = msg.get_command(pure=True)
|
||||
assert command == self.PURE_COMMAND
|
||||
|
||||
async def test_message_get_args(self):
|
||||
msg = types.Message(text=f'{self.COMMAND} {self.ARGS}')
|
||||
args = msg.get_args()
|
||||
assert args == self.ARGS
|
||||
|
||||
|
||||
class TestMessageEntities:
|
||||
@pytest.mark.skip(reason='Need to add md entities result assertion')
|
||||
async def test_message_parse_md_entities(self):
|
||||
msg = types.Message(text="""*sample text*""")
|
||||
_ = msg.md_text
|
||||
|
||||
@pytest.mark.skip(reason='Need to add html entities result assertion')
|
||||
async def test_message_parse_html_entities(self):
|
||||
msg = types.Message(text="""<b>sample text</b>""")
|
||||
_ = msg.html_text
|
||||
|
||||
|
||||
class TestMessageReply:
|
||||
async def test_reply(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply method test """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_REPLY_TO_MESSAGE)
|
||||
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_REPLY_TO_MESSAGE,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply(text=msg.text)
|
||||
|
||||
assert result == msg
|
||||
|
||||
async def test_reply_without_reply(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply method test (without reply_to_message) """
|
||||
msg = types.Message(**dataset.MESSAGE)
|
||||
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply(text=msg.text, reply=False)
|
||||
|
||||
assert result == msg
|
||||
|
||||
|
||||
class TestMessageReplyPhoto:
|
||||
async def test_reply_photo(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_photo method test """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_PHOTO_AND_REPLY)
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_PHOTO_AND_REPLY,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_photo(photo=msg.photo[0].file_id, caption=msg.caption)
|
||||
|
||||
assert result == msg
|
||||
|
||||
async def test_reply_photo_without_reply(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_photo method test (without reply_to_message) """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_PHOTO)
|
||||
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_PHOTO,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_photo(photo=msg.photo[0].file_id, caption=msg.caption, reply=False)
|
||||
|
||||
assert result == msg
|
||||
|
||||
|
||||
class TestMessageReplyAudio:
|
||||
async def test_reply_audio(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_audio method test """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_AUDIO_AND_REPLY)
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_AUDIO_AND_REPLY,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_audio(audio=msg.audio.file_id, caption=msg.caption)
|
||||
|
||||
assert result == msg
|
||||
|
||||
async def test_reply_photo_without_reply(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_audio method test (without reply_to_message) """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_AUDIO)
|
||||
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_AUDIO,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_audio(audio=msg.audio.file_id, caption=msg.caption, reply=False)
|
||||
|
||||
assert result == msg
|
||||
|
||||
|
||||
class TestMessageReplyDocument:
|
||||
async def test_reply_document(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_document method test """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_DOCUMENT_AND_REPLY)
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_DOCUMENT_AND_REPLY,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_document(document=msg.document.file_id, caption=msg.caption)
|
||||
|
||||
assert result == msg
|
||||
|
||||
async def test_reply_document_without_reply(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_document method test (without reply_to_message) """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_DOCUMENT)
|
||||
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_DOCUMENT,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_document(document=msg.document.file_id, caption=msg.caption, reply=False)
|
||||
|
||||
assert result == msg
|
||||
|
||||
|
||||
class TestMessageReplyVideo:
|
||||
async def test_reply_video(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_video method test """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_VIDEO_AND_REPLY)
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_VIDEO_AND_REPLY,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_video(video=msg.video.file_id, caption=msg.caption)
|
||||
|
||||
assert result == msg
|
||||
|
||||
async def test_reply_video_without_reply(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_video method test (without reply_to_message) """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_VIDEO)
|
||||
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_VIDEO,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_video(video=msg.video.file_id, caption=msg.caption, reply=False)
|
||||
|
||||
assert result == msg
|
||||
|
||||
|
||||
class TestMessageReplyVoice:
|
||||
async def test_reply_voice(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_voice method test """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_VOICE_AND_REPLY)
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_VOICE_AND_REPLY,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_voice(voice=msg.voice.file_id, caption=msg.caption)
|
||||
|
||||
assert result == msg
|
||||
|
||||
async def test_reply_voice_without_reply(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_voice method test (without reply_to_message) """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_VOICE)
|
||||
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_VOICE,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_voice(voice=msg.voice.file_id, caption=msg.caption, reply=False)
|
||||
|
||||
assert result == msg
|
||||
|
||||
|
||||
class TestMessageReplyVideoNote:
|
||||
async def test_reply_video_note(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_video_note method test """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_VIDEO_NOTE_AND_REPLY)
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_VIDEO_NOTE_AND_REPLY,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
vn = msg.video_note
|
||||
result = await message.reply_video_note(video_note=vn.file_id, duration=vn.duration, length=vn.length)
|
||||
|
||||
assert result == msg
|
||||
|
||||
async def test_reply_video_note_without_reply(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_video_note method test (without reply_to_message) """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_VIDEO_NOTE)
|
||||
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_VIDEO_NOTE,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
vn = msg.video_note
|
||||
result = await message.reply_video_note(video_note=vn.file_id, duration=vn.duration,
|
||||
length=vn.length, reply=False)
|
||||
|
||||
assert result == msg
|
||||
|
||||
|
||||
class TestMessageReplyMediaGroup:
|
||||
photo = types.PhotoSize(**dataset.PHOTO)
|
||||
media = [types.InputMediaPhoto(media=photo.file_id), types.InputMediaPhoto(media=photo.file_id)]
|
||||
|
||||
async def test_reply_media_group(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_media_group method test """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_MEDIA_GROUP_AND_REPLY)
|
||||
|
||||
async with FakeTelegram(message_dict=[dataset.MESSAGE_WITH_MEDIA_GROUP_AND_REPLY,
|
||||
dataset.MESSAGE_WITH_MEDIA_GROUP_AND_REPLY],
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_media_group(media=self.media)
|
||||
|
||||
assert len(result) == len(self.media)
|
||||
assert result[0] == msg
|
||||
|
||||
async def test_reply_video_note_without_reply(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_media_group method test (without reply_to_message) """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_MEDIA_GROUP)
|
||||
|
||||
async with FakeTelegram(message_dict=[dataset.MESSAGE_WITH_MEDIA_GROUP,
|
||||
dataset.MESSAGE_WITH_MEDIA_GROUP],
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_media_group(media=self.media, reply=False)
|
||||
|
||||
assert len(result) == len(self.media)
|
||||
assert result[0] == msg
|
||||
|
||||
|
||||
class TestMessageReplyLocation:
|
||||
location = types.Location(**dataset.LOCATION)
|
||||
|
||||
async def test_reply_location(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_location method test """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_LOCATION_AND_REPLY)
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_LOCATION_AND_REPLY,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_location(latitude=self.location.latitude,
|
||||
longitude=self.location.longitude)
|
||||
|
||||
assert result == msg
|
||||
|
||||
async def test_reply_location_without_reply(self, message, bot, monkeypatch, event_loop):
|
||||
""" Message.reply_location method test (without reply_to_message) """
|
||||
msg = types.Message(**dataset.MESSAGE_WITH_LOCATION)
|
||||
|
||||
async with FakeTelegram(message_dict=dataset.MESSAGE_WITH_LOCATION,
|
||||
loop=event_loop, bot=bot, monkeypatch=monkeypatch):
|
||||
result = await message.reply_location(latitude=self.location.latitude,
|
||||
longitude=self.location.longitude, reply=False)
|
||||
|
||||
assert result == msg
|
||||
|
||||
|
||||
@pytest.mark.skip(reason='Need to add TestMessageEditLiveLocation tests')
|
||||
class TestMessageEditLiveLocation:
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason='Need to add TestMessageStopLiveLocation tests')
|
||||
class TestMessageStopLiveLocation:
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason='Need to add TestMessageSendVenue tests')
|
||||
class TestMessageSendVenue:
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason='Need to add test_message_forward test')
|
||||
async def test_message_forward(message):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason='Need to add test_edit_text test')
|
||||
async def test_message_edit_text(message):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason='Need to add edit_reply_markup test')
|
||||
async def test_message_edit_reply_markup(message):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason='Need to add test_message_delete test')
|
||||
async def test_message_delete(message):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason='Need to add test_message_reply_sticker test')
|
||||
async def test_message_reply_sticker(message):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip(reason='Need to add test_message_pin test')
|
||||
async def test_message_pin(message):
|
||||
pass
|
||||
|
||||
|
||||
async def test_message_int():
|
||||
msg = types.Message(**dataset.MESSAGE)
|
||||
msg_id = int(msg)
|
||||
assert msg.message_id == msg_id
|
||||
|
|
@ -61,11 +61,14 @@ DOCUMENT = {
|
|||
}
|
||||
|
||||
ANIMATION = {
|
||||
"file_name": "a9b0e0ca537aa344338f80978f0896b7.gif.mp4",
|
||||
"file_name": "video.mp4",
|
||||
"mime_type": "video/mp4",
|
||||
"duration": 5,
|
||||
"width": 400,
|
||||
"height": 400,
|
||||
"thumb": PHOTO,
|
||||
"file_id": "CgADBAAD4DUAAoceZAe2WiE9y0crrAI",
|
||||
"file_size": 65837
|
||||
"file_id": "CgADAgADdwpgEAAorJawd8EJtC7FQI",
|
||||
"file_size": 521272
|
||||
}
|
||||
|
||||
ENTITY_BOLD = {
|
||||
|
|
@ -241,10 +244,31 @@ MESSAGE_WITH_AUDIO = {
|
|||
"caption": "This is my favourite song"
|
||||
}
|
||||
|
||||
MESSAGE_WITH_AUDIO_AND_REPLY = {
|
||||
"message_id": 12345,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1508739776,
|
||||
"reply_to_message": MESSAGE,
|
||||
"audio": AUDIO,
|
||||
"caption": "This is my favourite song"
|
||||
}
|
||||
|
||||
MESSAGE_WITH_ANIMATION = {
|
||||
"message_id": 78493,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1533675862,
|
||||
"animation": ANIMATION,
|
||||
"document": ANIMATION,
|
||||
}
|
||||
|
||||
MESSAGE_WITH_AUTHOR_SIGNATURE = {}
|
||||
|
||||
MESSAGE_WITH_CHANNEL_CHAT_CREATED = {}
|
||||
|
||||
MESSAGE_WITH_CONNECTED_WEBSITE = {}
|
||||
|
||||
MESSAGE_WITH_CONTACT = {
|
||||
"message_id": 56006,
|
||||
"from": USER,
|
||||
|
|
@ -253,7 +277,13 @@ MESSAGE_WITH_CONTACT = {
|
|||
"contact": CONTACT
|
||||
}
|
||||
|
||||
MESSAGE_WITH_DELETE_CHAT_PHOTO = {}
|
||||
MESSAGE_WITH_DELETE_CHAT_PHOTO = {
|
||||
"message_id": 3872,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1533677865,
|
||||
"delete_chat_photo": True
|
||||
}
|
||||
|
||||
MESSAGE_WITH_DOCUMENT = {
|
||||
"message_id": 12345,
|
||||
|
|
@ -264,6 +294,16 @@ MESSAGE_WITH_DOCUMENT = {
|
|||
"caption": "Read my document"
|
||||
}
|
||||
|
||||
MESSAGE_WITH_DOCUMENT_AND_REPLY = {
|
||||
"message_id": 12345,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1508768012,
|
||||
"reply_to_message": MESSAGE,
|
||||
"document": DOCUMENT,
|
||||
"caption": "Read my document"
|
||||
}
|
||||
|
||||
MESSAGE_WITH_EDIT_DATE = {}
|
||||
|
||||
MESSAGE_WITH_ENTITIES = {}
|
||||
|
|
@ -286,7 +326,14 @@ MESSAGE_WITH_INVOICE = {
|
|||
"invoice": INVOICE
|
||||
}
|
||||
|
||||
MESSAGE_WITH_LEFT_CHAT_MEMBER = {}
|
||||
MESSAGE_WITH_LEFT_CHAT_MEMBER = {
|
||||
"message_id": 2475,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1522251938,
|
||||
"left_chat_participant": USER,
|
||||
"left_chat_member": USER
|
||||
}
|
||||
|
||||
MESSAGE_WITH_LOCATION = {
|
||||
"message_id": 12345,
|
||||
|
|
@ -296,6 +343,15 @@ MESSAGE_WITH_LOCATION = {
|
|||
"location": LOCATION
|
||||
}
|
||||
|
||||
MESSAGE_WITH_LOCATION_AND_REPLY = {
|
||||
"message_id": 12345,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1508755473,
|
||||
"reply_to_message": MESSAGE,
|
||||
"location": LOCATION
|
||||
}
|
||||
|
||||
MESSAGE_WITH_MIGRATE_TO_CHAT_ID = {
|
||||
"message_id": 12345,
|
||||
"from": USER,
|
||||
|
|
@ -312,11 +368,33 @@ MESSAGE_WITH_MIGRATE_FROM_CHAT_ID = {
|
|||
"migrate_from_chat_id": -123456789
|
||||
}
|
||||
|
||||
MESSAGE_WITH_NEW_CHAT_MEMBERS = {}
|
||||
MESSAGE_WITH_NEW_CHAT_MEMBERS = {
|
||||
"message_id": 3724,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1533026106,
|
||||
"new_chat_participant": USER,
|
||||
"new_chat_member": USER,
|
||||
"new_chat_members": [USER]
|
||||
}
|
||||
|
||||
MESSAGE_WITH_NEW_CHAT_PHOTO = {}
|
||||
MESSAGE_WITH_NEW_CHAT_PHOTO = {
|
||||
"message_id": 3873,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1533677974,
|
||||
"new_chat_photo": [PHOTO, PHOTO, PHOTO]
|
||||
}
|
||||
|
||||
MESSAGE_WITH_NEW_CHAT_TITLE = {}
|
||||
MESSAGE_WITH_NEW_CHAT_TITLE = {
|
||||
"message_id": 3874,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1533678102,
|
||||
"new_chat_title": "new title text"
|
||||
}
|
||||
|
||||
MESSAGE_WITH_PASSPORT_DATA = {}
|
||||
|
||||
MESSAGE_WITH_PHOTO = {
|
||||
"message_id": 12345,
|
||||
|
|
@ -327,6 +405,16 @@ MESSAGE_WITH_PHOTO = {
|
|||
"caption": "photo description"
|
||||
}
|
||||
|
||||
MESSAGE_WITH_PHOTO_AND_REPLY = {
|
||||
"message_id": 12345,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1508825154,
|
||||
"reply_to_message": MESSAGE,
|
||||
"photo": [PHOTO, PHOTO, PHOTO, PHOTO],
|
||||
"caption": "photo description",
|
||||
}
|
||||
|
||||
MESSAGE_WITH_MEDIA_GROUP = {
|
||||
"message_id": 55966,
|
||||
"from": USER,
|
||||
|
|
@ -336,9 +424,34 @@ MESSAGE_WITH_MEDIA_GROUP = {
|
|||
"photo": [PHOTO, PHOTO, PHOTO, PHOTO]
|
||||
}
|
||||
|
||||
MESSAGE_WITH_PINNED_MESSAGE = {}
|
||||
MESSAGE_WITH_MEDIA_GROUP_AND_REPLY = {
|
||||
"message_id": 55966,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1522843665,
|
||||
"reply_to_message": MESSAGE,
|
||||
"media_group_id": "12182749320567362",
|
||||
"photo": [PHOTO, PHOTO, PHOTO, PHOTO]
|
||||
}
|
||||
|
||||
MESSAGE_WITH_REPLY_TO_MESSAGE = {}
|
||||
MESSAGE_UNKNOWN = {}
|
||||
|
||||
MESSAGE_WITH_PINNED_MESSAGE = {
|
||||
"message_id": 3875,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1533678172,
|
||||
"pinned_message": MESSAGE
|
||||
}
|
||||
|
||||
MESSAGE_WITH_REPLY_TO_MESSAGE = {
|
||||
"message_id": 12346,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1508761170,
|
||||
"reply_to_message": MESSAGE,
|
||||
"text": "Reply to Hello World!"
|
||||
}
|
||||
|
||||
MESSAGE_WITH_STICKER = {
|
||||
"message_id": 12345,
|
||||
|
|
@ -367,6 +480,16 @@ MESSAGE_WITH_VENUE = {
|
|||
"venue": VENUE
|
||||
}
|
||||
|
||||
MESSAGE_WITH_VENUE_AND_REPLY = {
|
||||
"message_id": 56004,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1522849819,
|
||||
"reply_to_message": MESSAGE,
|
||||
"location": LOCATION,
|
||||
"venue": VENUE
|
||||
}
|
||||
|
||||
MESSAGE_WITH_VIDEO = {
|
||||
"message_id": 12345,
|
||||
"from": USER,
|
||||
|
|
@ -376,6 +499,16 @@ MESSAGE_WITH_VIDEO = {
|
|||
"caption": "description"
|
||||
}
|
||||
|
||||
MESSAGE_WITH_VIDEO_AND_REPLY = {
|
||||
"message_id": 12345,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1508756494,
|
||||
"reply_to_message": MESSAGE,
|
||||
"video": VIDEO,
|
||||
"caption": "description"
|
||||
}
|
||||
|
||||
MESSAGE_WITH_VIDEO_NOTE = {
|
||||
"message_id": 55934,
|
||||
"from": USER,
|
||||
|
|
@ -384,6 +517,15 @@ MESSAGE_WITH_VIDEO_NOTE = {
|
|||
"video_note": VIDEO_NOTE
|
||||
}
|
||||
|
||||
MESSAGE_WITH_VIDEO_NOTE_AND_REPLY = {
|
||||
"message_id": 55934,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"reply_to_message": MESSAGE,
|
||||
"date": 1522835890,
|
||||
"video_note": VIDEO_NOTE
|
||||
}
|
||||
|
||||
MESSAGE_WITH_VOICE = {
|
||||
"message_id": 12345,
|
||||
"from": USER,
|
||||
|
|
@ -392,6 +534,15 @@ MESSAGE_WITH_VOICE = {
|
|||
"voice": VOICE
|
||||
}
|
||||
|
||||
MESSAGE_WITH_VOICE_AND_REPLY = {
|
||||
"message_id": 12345,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1508768403,
|
||||
"reply_to_message": MESSAGE,
|
||||
"voice": VOICE
|
||||
}
|
||||
|
||||
PRE_CHECKOUT_QUERY = {
|
||||
"id": "262181558630368727",
|
||||
"from": USER,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue