mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Clean project
This commit is contained in:
parent
a83dd3ca63
commit
bdae5fb026
259 changed files with 1303 additions and 21135 deletions
|
|
@ -3,7 +3,7 @@ import pytest
|
|||
|
||||
from aiogram import Bot, types
|
||||
|
||||
TOKEN = '123456789:AABBCCDDEEFFaabbccddeeff-1234567890'
|
||||
TOKEN = "123456789:AABBCCDDEEFFaabbccddeeff-1234567890"
|
||||
|
||||
|
||||
class FakeTelegram(aresponses.ResponsesMockServer):
|
||||
|
|
@ -13,23 +13,25 @@ class FakeTelegram(aresponses.ResponsesMockServer):
|
|||
|
||||
async def __aenter__(self):
|
||||
await super().__aenter__()
|
||||
_response = self.Response(text=self._body, headers=self._headers, status=200, reason='OK')
|
||||
_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'}
|
||||
_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
|
||||
|
||||
|
||||
|
|
@ -46,6 +48,7 @@ async def bot(event_loop):
|
|||
async def test_get_me(bot: Bot, event_loop):
|
||||
""" getMe method test """
|
||||
from .types.dataset import USER
|
||||
|
||||
user = types.User(**USER)
|
||||
|
||||
async with FakeTelegram(message_dict=USER, loop=event_loop):
|
||||
|
|
@ -57,6 +60,7 @@ async def test_get_me(bot: Bot, event_loop):
|
|||
async def test_send_message(bot: Bot, event_loop):
|
||||
""" sendMessage method test """
|
||||
from .types.dataset import MESSAGE
|
||||
|
||||
msg = types.Message(**MESSAGE)
|
||||
|
||||
async with FakeTelegram(message_dict=MESSAGE, loop=event_loop):
|
||||
|
|
@ -68,11 +72,15 @@ async def test_send_message(bot: Bot, event_loop):
|
|||
async def test_forward_message(bot: Bot, event_loop):
|
||||
""" forwardMessage method test """
|
||||
from .types.dataset import FORWARDED_MESSAGE
|
||||
|
||||
msg = types.Message(**FORWARDED_MESSAGE)
|
||||
|
||||
async with FakeTelegram(message_dict=FORWARDED_MESSAGE, loop=event_loop):
|
||||
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)
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -80,12 +88,18 @@ async def test_forward_message(bot: Bot, event_loop):
|
|||
async def test_send_photo(bot: Bot, event_loop):
|
||||
""" 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_dict=MESSAGE_WITH_PHOTO, loop=event_loop):
|
||||
result = await bot.send_photo(msg.chat.id, photo=photo.file_id, caption=msg.caption,
|
||||
parse_mode=types.ParseMode.HTML, disable_notification=False)
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -93,12 +107,20 @@ async def test_send_photo(bot: Bot, event_loop):
|
|||
async def test_send_audio(bot: Bot, event_loop):
|
||||
""" sendAudio method test with file_id """
|
||||
from .types.dataset import MESSAGE_WITH_AUDIO
|
||||
|
||||
msg = types.Message(**MESSAGE_WITH_AUDIO)
|
||||
|
||||
async with FakeTelegram(message_dict=MESSAGE_WITH_AUDIO, loop=event_loop):
|
||||
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)
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -106,11 +128,17 @@ async def test_send_audio(bot: Bot, event_loop):
|
|||
async def test_send_document(bot: Bot, event_loop):
|
||||
""" sendDocument method test with file_id """
|
||||
from .types.dataset import MESSAGE_WITH_DOCUMENT
|
||||
|
||||
msg = types.Message(**MESSAGE_WITH_DOCUMENT)
|
||||
|
||||
async with FakeTelegram(message_dict=MESSAGE_WITH_DOCUMENT, loop=event_loop):
|
||||
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)
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -118,14 +146,22 @@ async def test_send_document(bot: Bot, event_loop):
|
|||
async def test_send_video(bot: Bot, event_loop):
|
||||
""" 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_dict=MESSAGE_WITH_VIDEO, loop=event_loop):
|
||||
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,
|
||||
disable_notification=False)
|
||||
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,
|
||||
disable_notification=False,
|
||||
)
|
||||
assert result == msg
|
||||
|
||||
|
||||
|
|
@ -133,13 +169,19 @@ async def test_send_video(bot: Bot, event_loop):
|
|||
async def test_send_voice(bot: Bot, event_loop):
|
||||
""" 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_dict=MESSAGE_WITH_VOICE, loop=event_loop):
|
||||
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)
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -147,13 +189,18 @@ async def test_send_voice(bot: Bot, event_loop):
|
|||
async def test_send_video_note(bot: Bot, event_loop):
|
||||
""" 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_dict=MESSAGE_WITH_VIDEO_NOTE, loop=event_loop):
|
||||
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)
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -161,11 +208,17 @@ async def test_send_video_note(bot: Bot, event_loop):
|
|||
async def test_send_media_group(bot: Bot, event_loop):
|
||||
""" 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)]
|
||||
media = [
|
||||
types.InputMediaPhoto(media=photo.file_id),
|
||||
types.InputMediaPhoto(media=photo.file_id),
|
||||
]
|
||||
|
||||
async with FakeTelegram(message_dict=[MESSAGE_WITH_MEDIA_GROUP, MESSAGE_WITH_MEDIA_GROUP], loop=event_loop):
|
||||
async with FakeTelegram(
|
||||
message_dict=[MESSAGE_WITH_MEDIA_GROUP, MESSAGE_WITH_MEDIA_GROUP], loop=event_loop
|
||||
):
|
||||
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
|
||||
|
|
@ -175,12 +228,18 @@ async def test_send_media_group(bot: Bot, event_loop):
|
|||
async def test_send_location(bot: Bot, event_loop):
|
||||
""" 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_dict=MESSAGE_WITH_LOCATION, loop=event_loop):
|
||||
result = await bot.send_location(msg.chat.id, latitude=location.latitude, longitude=location.longitude,
|
||||
live_period=10, disable_notification=False)
|
||||
result = await bot.send_location(
|
||||
msg.chat.id,
|
||||
latitude=location.latitude,
|
||||
longitude=location.longitude,
|
||||
live_period=10,
|
||||
disable_notification=False,
|
||||
)
|
||||
assert result == msg
|
||||
|
||||
|
||||
|
|
@ -188,13 +247,18 @@ async def test_send_location(bot: Bot, event_loop):
|
|||
async def test_edit_message_live_location_by_bot(bot: Bot, event_loop):
|
||||
""" 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_dict=MESSAGE_WITH_LOCATION, loop=event_loop):
|
||||
result = await bot.edit_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id,
|
||||
latitude=location.latitude, longitude=location.longitude)
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -202,13 +266,18 @@ async def test_edit_message_live_location_by_bot(bot: Bot, event_loop):
|
|||
async def test_edit_message_live_location_by_user(bot: Bot, event_loop):
|
||||
""" 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_dict=True, loop=event_loop):
|
||||
result = await bot.edit_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id,
|
||||
latitude=location.latitude, longitude=location.longitude)
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -216,11 +285,14 @@ async def test_edit_message_live_location_by_user(bot: Bot, event_loop):
|
|||
async def test_stop_message_live_location_by_bot(bot: Bot, event_loop):
|
||||
""" stopMessageLiveLocation method test """
|
||||
from .types.dataset import MESSAGE_WITH_LOCATION
|
||||
|
||||
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
||||
|
||||
# stopping bot message
|
||||
async with FakeTelegram(message_dict=MESSAGE_WITH_LOCATION, loop=event_loop):
|
||||
result = await bot.stop_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id)
|
||||
result = await bot.stop_message_live_location(
|
||||
chat_id=msg.chat.id, message_id=msg.message_id
|
||||
)
|
||||
assert result == msg
|
||||
|
||||
|
||||
|
|
@ -228,11 +300,14 @@ async def test_stop_message_live_location_by_bot(bot: Bot, event_loop):
|
|||
async def test_stop_message_live_location_by_user(bot: Bot, event_loop):
|
||||
""" stopMessageLiveLocation method test """
|
||||
from .types.dataset import MESSAGE_WITH_LOCATION
|
||||
|
||||
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
||||
|
||||
# stopping user's message
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
result = await bot.stop_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id)
|
||||
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
|
||||
|
||||
|
|
@ -241,14 +316,21 @@ async def test_stop_message_live_location_by_user(bot: Bot, event_loop):
|
|||
async def test_send_venue(bot: Bot, event_loop):
|
||||
""" 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_dict=MESSAGE_WITH_VENUE, loop=event_loop):
|
||||
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)
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -256,12 +338,18 @@ async def test_send_venue(bot: Bot, event_loop):
|
|||
async def test_send_contact(bot: Bot, event_loop):
|
||||
""" 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_dict=MESSAGE_WITH_CONTACT, loop=event_loop):
|
||||
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)
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -269,6 +357,7 @@ async def test_send_contact(bot: Bot, event_loop):
|
|||
async def test_send_chat_action(bot: Bot, event_loop):
|
||||
""" sendChatAction method test """
|
||||
from .types.dataset import CHAT
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
|
|
@ -281,6 +370,7 @@ async def test_send_chat_action(bot: Bot, event_loop):
|
|||
async def test_get_user_profile_photo(bot: Bot, event_loop):
|
||||
""" getUserProfilePhotos method test """
|
||||
from .types.dataset import USER_PROFILE_PHOTOS, USER
|
||||
|
||||
user = types.User(**USER)
|
||||
|
||||
async with FakeTelegram(message_dict=USER_PROFILE_PHOTOS, loop=event_loop):
|
||||
|
|
@ -292,6 +382,7 @@ async def test_get_user_profile_photo(bot: Bot, event_loop):
|
|||
async def test_get_file(bot: Bot, event_loop):
|
||||
""" getFile method test """
|
||||
from .types.dataset import FILE
|
||||
|
||||
file = types.File(**FILE)
|
||||
|
||||
async with FakeTelegram(message_dict=FILE, loop=event_loop):
|
||||
|
|
@ -303,6 +394,7 @@ async def test_get_file(bot: Bot, event_loop):
|
|||
async def test_kick_chat_member(bot: Bot, event_loop):
|
||||
""" kickChatMember method test """
|
||||
from .types.dataset import USER, CHAT
|
||||
|
||||
user = types.User(**USER)
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
|
|
@ -316,6 +408,7 @@ async def test_kick_chat_member(bot: Bot, event_loop):
|
|||
async def test_unban_chat_member(bot: Bot, event_loop):
|
||||
""" unbanChatMember method test """
|
||||
from .types.dataset import USER, CHAT
|
||||
|
||||
user = types.User(**USER)
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
|
|
@ -329,6 +422,7 @@ async def test_unban_chat_member(bot: Bot, event_loop):
|
|||
async def test_restrict_chat_member(bot: Bot, event_loop):
|
||||
""" restrictChatMember method test """
|
||||
from .types.dataset import USER, CHAT
|
||||
|
||||
user = types.User(**USER)
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
|
|
@ -340,8 +434,10 @@ async def test_restrict_chat_member(bot: Bot, event_loop):
|
|||
can_add_web_page_previews=False,
|
||||
can_send_media_messages=False,
|
||||
can_send_messages=False,
|
||||
can_send_other_messages=False
|
||||
), until_date=123)
|
||||
can_send_other_messages=False,
|
||||
),
|
||||
until_date=123,
|
||||
)
|
||||
assert isinstance(result, bool)
|
||||
assert result is True
|
||||
|
||||
|
|
@ -350,14 +446,23 @@ async def test_restrict_chat_member(bot: Bot, event_loop):
|
|||
async def test_promote_chat_member(bot: Bot, event_loop):
|
||||
""" promoteChatMember method test """
|
||||
from .types.dataset import USER, CHAT
|
||||
|
||||
user = types.User(**USER)
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
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,
|
||||
can_promote_members=True, can_restrict_members=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,
|
||||
can_promote_members=True,
|
||||
can_restrict_members=True,
|
||||
)
|
||||
assert isinstance(result, bool)
|
||||
assert result is True
|
||||
|
||||
|
|
@ -366,6 +471,7 @@ async def test_promote_chat_member(bot: Bot, event_loop):
|
|||
async def test_export_chat_invite_link(bot: Bot, event_loop):
|
||||
""" exportChatInviteLink method test """
|
||||
from .types.dataset import CHAT, INVITE_LINK
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
async with FakeTelegram(message_dict=INVITE_LINK, loop=event_loop):
|
||||
|
|
@ -377,6 +483,7 @@ async def test_export_chat_invite_link(bot: Bot, event_loop):
|
|||
async def test_delete_chat_photo(bot: Bot, event_loop):
|
||||
""" deleteChatPhoto method test """
|
||||
from .types.dataset import CHAT
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
|
|
@ -389,10 +496,11 @@ async def test_delete_chat_photo(bot: Bot, event_loop):
|
|||
async def test_set_chat_title(bot: Bot, event_loop):
|
||||
""" setChatTitle method test """
|
||||
from .types.dataset import CHAT
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
result = await bot.set_chat_title(chat_id=chat.id, title='Test title')
|
||||
result = await bot.set_chat_title(chat_id=chat.id, title="Test title")
|
||||
assert isinstance(result, bool)
|
||||
assert result is True
|
||||
|
||||
|
|
@ -401,10 +509,11 @@ async def test_set_chat_title(bot: Bot, event_loop):
|
|||
async def test_set_chat_description(bot: Bot, event_loop):
|
||||
""" setChatDescription method test """
|
||||
from .types.dataset import CHAT
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
result = await bot.set_chat_description(chat_id=chat.id, description='Test description')
|
||||
result = await bot.set_chat_description(chat_id=chat.id, description="Test description")
|
||||
assert isinstance(result, bool)
|
||||
assert result is True
|
||||
|
||||
|
|
@ -413,11 +522,13 @@ async def test_set_chat_description(bot: Bot, event_loop):
|
|||
async def test_pin_chat_message(bot: Bot, event_loop):
|
||||
""" pinChatMessage method test """
|
||||
from .types.dataset import MESSAGE
|
||||
|
||||
message = types.Message(**MESSAGE)
|
||||
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
result = await bot.pin_chat_message(chat_id=message.chat.id, message_id=message.message_id,
|
||||
disable_notification=False)
|
||||
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
|
||||
|
||||
|
|
@ -426,6 +537,7 @@ async def test_pin_chat_message(bot: Bot, event_loop):
|
|||
async def test_unpin_chat_message(bot: Bot, event_loop):
|
||||
""" unpinChatMessage method test """
|
||||
from .types.dataset import CHAT
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
|
|
@ -438,6 +550,7 @@ async def test_unpin_chat_message(bot: Bot, event_loop):
|
|||
async def test_leave_chat(bot: Bot, event_loop):
|
||||
""" leaveChat method test """
|
||||
from .types.dataset import CHAT
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
|
|
@ -450,6 +563,7 @@ async def test_leave_chat(bot: Bot, event_loop):
|
|||
async def test_get_chat(bot: Bot, event_loop):
|
||||
""" getChat method test """
|
||||
from .types.dataset import CHAT
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
async with FakeTelegram(message_dict=CHAT, loop=event_loop):
|
||||
|
|
@ -461,6 +575,7 @@ async def test_get_chat(bot: Bot, event_loop):
|
|||
async def test_get_chat_administrators(bot: Bot, event_loop):
|
||||
""" getChatAdministrators method test """
|
||||
from .types.dataset import CHAT, CHAT_MEMBER
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
member = types.ChatMember(**CHAT_MEMBER)
|
||||
|
||||
|
|
@ -474,6 +589,7 @@ async def test_get_chat_administrators(bot: Bot, event_loop):
|
|||
async def test_get_chat_members_count(bot: Bot, event_loop):
|
||||
""" getChatMembersCount method test """
|
||||
from .types.dataset import CHAT
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
count = 5
|
||||
|
||||
|
|
@ -486,6 +602,7 @@ async def test_get_chat_members_count(bot: Bot, event_loop):
|
|||
async def test_get_chat_member(bot: Bot, event_loop):
|
||||
""" getChatMember method test """
|
||||
from .types.dataset import CHAT, CHAT_MEMBER
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
member = types.ChatMember(**CHAT_MEMBER)
|
||||
|
||||
|
|
@ -499,10 +616,13 @@ async def test_get_chat_member(bot: Bot, event_loop):
|
|||
async def test_set_chat_sticker_set(bot: Bot, event_loop):
|
||||
""" setChatStickerSet method test """
|
||||
from .types.dataset import CHAT
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
result = await bot.set_chat_sticker_set(chat_id=chat.id, sticker_set_name='aiogram_stickers')
|
||||
result = await bot.set_chat_sticker_set(
|
||||
chat_id=chat.id, sticker_set_name="aiogram_stickers"
|
||||
)
|
||||
assert isinstance(result, bool)
|
||||
assert result is True
|
||||
|
||||
|
|
@ -511,6 +631,7 @@ async def test_set_chat_sticker_set(bot: Bot, event_loop):
|
|||
async def test_delete_chat_sticker_set(bot: Bot, event_loop):
|
||||
""" setChatStickerSet method test """
|
||||
from .types.dataset import CHAT
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
|
|
@ -524,7 +645,7 @@ async def test_answer_callback_query(bot: Bot, event_loop):
|
|||
""" answerCallbackQuery method test """
|
||||
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
result = await bot.answer_callback_query(callback_query_id='QuERyId', text='Test Answer')
|
||||
result = await bot.answer_callback_query(callback_query_id="QuERyId", text="Test Answer")
|
||||
assert isinstance(result, bool)
|
||||
assert result is True
|
||||
|
||||
|
|
@ -533,11 +654,14 @@ async def test_answer_callback_query(bot: Bot, event_loop):
|
|||
async def test_edit_message_text_by_bot(bot: Bot, event_loop):
|
||||
""" editMessageText method test """
|
||||
from .types.dataset import EDITED_MESSAGE
|
||||
|
||||
msg = types.Message(**EDITED_MESSAGE)
|
||||
|
||||
# message by bot
|
||||
async with FakeTelegram(message_dict=EDITED_MESSAGE, loop=event_loop):
|
||||
result = await bot.edit_message_text(text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id)
|
||||
result = await bot.edit_message_text(
|
||||
text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id
|
||||
)
|
||||
assert result == msg
|
||||
|
||||
|
||||
|
|
@ -545,10 +669,13 @@ async def test_edit_message_text_by_bot(bot: Bot, event_loop):
|
|||
async def test_edit_message_text_by_user(bot: Bot, event_loop):
|
||||
""" editMessageText method test """
|
||||
from .types.dataset import EDITED_MESSAGE
|
||||
|
||||
msg = types.Message(**EDITED_MESSAGE)
|
||||
|
||||
# message by user
|
||||
async with FakeTelegram(message_dict=True, loop=event_loop):
|
||||
result = await bot.edit_message_text(text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id)
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue