mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
pytest update; yield_fixture deprecation fix; event_loop removed (#479)
This commit is contained in:
parent
4fb4d6cac1
commit
ee12911f24
4 changed files with 105 additions and 107 deletions
|
|
@ -3,11 +3,10 @@
|
||||||
ujson>=1.35
|
ujson>=1.35
|
||||||
python-rapidjson>=0.7.0
|
python-rapidjson>=0.7.0
|
||||||
emoji>=0.5.2
|
emoji>=0.5.2
|
||||||
pytest>=5.4
|
pytest>=6.2.1
|
||||||
pytest-asyncio>=0.10.0
|
pytest-asyncio>=0.10.0
|
||||||
tox>=3.9.0
|
tox>=3.9.0
|
||||||
aresponses>=1.1.1
|
aresponses>=1.1.1
|
||||||
uvloop>=0.12.2
|
|
||||||
aioredis>=1.2.0
|
aioredis>=1.2.0
|
||||||
wheel>=0.31.1
|
wheel>=0.31.1
|
||||||
sphinx>=2.0.1
|
sphinx>=2.0.1
|
||||||
|
|
|
||||||
|
|
@ -6,103 +6,103 @@ from . import FakeTelegram, TOKEN, BOT_ID
|
||||||
pytestmark = pytest.mark.asyncio
|
pytestmark = pytest.mark.asyncio
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture(name='bot')
|
@pytest.fixture(name='bot')
|
||||||
async def bot_fixture(event_loop):
|
async def bot_fixture():
|
||||||
""" 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
|
yield _bot
|
||||||
await _bot.close()
|
await _bot.close()
|
||||||
|
|
||||||
|
|
||||||
async def test_get_me(bot: Bot, event_loop):
|
async def test_get_me(bot: Bot):
|
||||||
""" getMe method test """
|
""" getMe method test """
|
||||||
from .types.dataset import USER
|
from .types.dataset import USER
|
||||||
user = types.User(**USER)
|
user = types.User(**USER)
|
||||||
|
|
||||||
async with FakeTelegram(message_data=USER, loop=event_loop):
|
async with FakeTelegram(message_data=USER):
|
||||||
result = await bot.me
|
result = await bot.me
|
||||||
assert result == user
|
assert result == user
|
||||||
|
|
||||||
|
|
||||||
async def test_log_out(bot: Bot, event_loop):
|
async def test_log_out(bot: Bot):
|
||||||
""" logOut method test """
|
""" logOut method test """
|
||||||
|
|
||||||
async with FakeTelegram(message_data=True, loop=event_loop):
|
async with FakeTelegram(message_data=True):
|
||||||
result = await bot.log_out()
|
result = await bot.log_out()
|
||||||
assert result is True
|
assert result is True
|
||||||
|
|
||||||
|
|
||||||
async def test_close_bot(bot: Bot, event_loop):
|
async def test_close_bot(bot: Bot):
|
||||||
""" close method test """
|
""" close method test """
|
||||||
|
|
||||||
async with FakeTelegram(message_data=True, loop=event_loop):
|
async with FakeTelegram(message_data=True):
|
||||||
result = await bot.close_bot()
|
result = await bot.close_bot()
|
||||||
assert result is True
|
assert result is True
|
||||||
|
|
||||||
|
|
||||||
async def test_send_message(bot: Bot, event_loop):
|
async def test_send_message(bot: Bot):
|
||||||
""" sendMessage method test """
|
""" sendMessage method test """
|
||||||
from .types.dataset import MESSAGE
|
from .types.dataset import MESSAGE
|
||||||
msg = types.Message(**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)
|
result = await bot.send_message(chat_id=msg.chat.id, text=msg.text)
|
||||||
assert result == msg
|
assert result == msg
|
||||||
|
|
||||||
|
|
||||||
async def test_forward_message(bot: Bot, event_loop):
|
async def test_forward_message(bot: Bot):
|
||||||
""" forwardMessage method test """
|
""" forwardMessage method test """
|
||||||
from .types.dataset import FORWARDED_MESSAGE
|
from .types.dataset import FORWARDED_MESSAGE
|
||||||
msg = types.Message(**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,
|
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)
|
message_id=msg.forward_from_message_id)
|
||||||
assert result == msg
|
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 """
|
""" sendPhoto method test with file_id """
|
||||||
from .types.dataset import MESSAGE_WITH_PHOTO, PHOTO
|
from .types.dataset import MESSAGE_WITH_PHOTO, PHOTO
|
||||||
msg = types.Message(**MESSAGE_WITH_PHOTO)
|
msg = types.Message(**MESSAGE_WITH_PHOTO)
|
||||||
photo = types.PhotoSize(**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,
|
result = await bot.send_photo(msg.chat.id, photo=photo.file_id, caption=msg.caption,
|
||||||
parse_mode=types.ParseMode.HTML, disable_notification=False)
|
parse_mode=types.ParseMode.HTML, disable_notification=False)
|
||||||
assert result == msg
|
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 """
|
""" sendAudio method test with file_id """
|
||||||
from .types.dataset import MESSAGE_WITH_AUDIO
|
from .types.dataset import MESSAGE_WITH_AUDIO
|
||||||
msg = types.Message(**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,
|
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,
|
parse_mode=types.ParseMode.HTML, duration=msg.audio.duration,
|
||||||
performer=msg.audio.performer, title=msg.audio.title, disable_notification=False)
|
performer=msg.audio.performer, title=msg.audio.title, disable_notification=False)
|
||||||
assert result == msg
|
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 """
|
""" sendDocument method test with file_id """
|
||||||
from .types.dataset import MESSAGE_WITH_DOCUMENT
|
from .types.dataset import MESSAGE_WITH_DOCUMENT
|
||||||
msg = types.Message(**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,
|
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)
|
parse_mode=types.ParseMode.HTML, disable_notification=False)
|
||||||
assert result == msg
|
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 """
|
""" sendVideo method test with file_id """
|
||||||
from .types.dataset import MESSAGE_WITH_VIDEO, VIDEO
|
from .types.dataset import MESSAGE_WITH_VIDEO, VIDEO
|
||||||
msg = types.Message(**MESSAGE_WITH_VIDEO)
|
msg = types.Message(**MESSAGE_WITH_VIDEO)
|
||||||
video = types.Video(**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,
|
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,
|
width=video.width, height=video.height, caption=msg.caption,
|
||||||
parse_mode=types.ParseMode.HTML, supports_streaming=True,
|
parse_mode=types.ParseMode.HTML, supports_streaming=True,
|
||||||
|
|
@ -110,204 +110,204 @@ async def test_send_video(bot: Bot, event_loop):
|
||||||
assert result == msg
|
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 """
|
""" sendVoice method test with file_id """
|
||||||
from .types.dataset import MESSAGE_WITH_VOICE, VOICE
|
from .types.dataset import MESSAGE_WITH_VOICE, VOICE
|
||||||
msg = types.Message(**MESSAGE_WITH_VOICE)
|
msg = types.Message(**MESSAGE_WITH_VOICE)
|
||||||
voice = types.Voice(**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,
|
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,
|
parse_mode=types.ParseMode.HTML, duration=voice.duration,
|
||||||
disable_notification=False)
|
disable_notification=False)
|
||||||
assert result == msg
|
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 """
|
""" sendVideoNote method test with file_id """
|
||||||
from .types.dataset import MESSAGE_WITH_VIDEO_NOTE, VIDEO_NOTE
|
from .types.dataset import MESSAGE_WITH_VIDEO_NOTE, VIDEO_NOTE
|
||||||
msg = types.Message(**MESSAGE_WITH_VIDEO_NOTE)
|
msg = types.Message(**MESSAGE_WITH_VIDEO_NOTE)
|
||||||
video_note = types.VideoNote(**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,
|
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,
|
duration=video_note.duration, length=video_note.length,
|
||||||
disable_notification=False)
|
disable_notification=False)
|
||||||
assert result == msg
|
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 """
|
""" sendMediaGroup method test with file_id """
|
||||||
from .types.dataset import MESSAGE_WITH_MEDIA_GROUP, PHOTO
|
from .types.dataset import MESSAGE_WITH_MEDIA_GROUP, PHOTO
|
||||||
msg = types.Message(**MESSAGE_WITH_MEDIA_GROUP)
|
msg = types.Message(**MESSAGE_WITH_MEDIA_GROUP)
|
||||||
photo = types.PhotoSize(**PHOTO)
|
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_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)
|
result = await bot.send_media_group(msg.chat.id, media=media, disable_notification=False)
|
||||||
assert len(result) == len(media)
|
assert len(result) == len(media)
|
||||||
assert result.pop().media_group_id
|
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 """
|
""" sendLocation method test """
|
||||||
from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION
|
from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION
|
||||||
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
||||||
location = types.Location(**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,
|
result = await bot.send_location(msg.chat.id, latitude=location.latitude, longitude=location.longitude,
|
||||||
live_period=10, disable_notification=False)
|
live_period=10, disable_notification=False)
|
||||||
assert result == msg
|
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 """
|
""" editMessageLiveLocation method test """
|
||||||
from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION
|
from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION
|
||||||
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
||||||
location = types.Location(**LOCATION)
|
location = types.Location(**LOCATION)
|
||||||
|
|
||||||
# editing bot message
|
# 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,
|
result = await bot.edit_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id,
|
||||||
latitude=location.latitude, longitude=location.longitude)
|
latitude=location.latitude, longitude=location.longitude)
|
||||||
assert result == msg
|
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 """
|
""" editMessageLiveLocation method test """
|
||||||
from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION
|
from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION
|
||||||
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
||||||
location = types.Location(**LOCATION)
|
location = types.Location(**LOCATION)
|
||||||
|
|
||||||
# editing user's message
|
# 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,
|
result = await bot.edit_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id,
|
||||||
latitude=location.latitude, longitude=location.longitude)
|
latitude=location.latitude, longitude=location.longitude)
|
||||||
assert isinstance(result, bool) and result is True
|
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 """
|
""" stopMessageLiveLocation method test """
|
||||||
from .types.dataset import MESSAGE_WITH_LOCATION
|
from .types.dataset import MESSAGE_WITH_LOCATION
|
||||||
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
||||||
|
|
||||||
# stopping bot message
|
# 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)
|
result = await bot.stop_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id)
|
||||||
assert result == msg
|
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 """
|
""" stopMessageLiveLocation method test """
|
||||||
from .types.dataset import MESSAGE_WITH_LOCATION
|
from .types.dataset import MESSAGE_WITH_LOCATION
|
||||||
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
msg = types.Message(**MESSAGE_WITH_LOCATION)
|
||||||
|
|
||||||
# stopping user's message
|
# 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)
|
result = await bot.stop_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id)
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
assert result is True
|
||||||
|
|
||||||
|
|
||||||
async def test_send_venue(bot: Bot, event_loop):
|
async def test_send_venue(bot: Bot):
|
||||||
""" sendVenue method test """
|
""" sendVenue method test """
|
||||||
from .types.dataset import MESSAGE_WITH_VENUE, VENUE, LOCATION
|
from .types.dataset import MESSAGE_WITH_VENUE, VENUE, LOCATION
|
||||||
msg = types.Message(**MESSAGE_WITH_VENUE)
|
msg = types.Message(**MESSAGE_WITH_VENUE)
|
||||||
location = types.Location(**LOCATION)
|
location = types.Location(**LOCATION)
|
||||||
venue = types.Venue(**VENUE)
|
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,
|
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,
|
title=venue.title, address=venue.address, foursquare_id=venue.foursquare_id,
|
||||||
disable_notification=False)
|
disable_notification=False)
|
||||||
assert result == msg
|
assert result == msg
|
||||||
|
|
||||||
|
|
||||||
async def test_send_contact(bot: Bot, event_loop):
|
async def test_send_contact(bot: Bot):
|
||||||
""" sendContact method test """
|
""" sendContact method test """
|
||||||
from .types.dataset import MESSAGE_WITH_CONTACT, CONTACT
|
from .types.dataset import MESSAGE_WITH_CONTACT, CONTACT
|
||||||
msg = types.Message(**MESSAGE_WITH_CONTACT)
|
msg = types.Message(**MESSAGE_WITH_CONTACT)
|
||||||
contact = types.Contact(**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,
|
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)
|
last_name=contact.last_name, disable_notification=False)
|
||||||
assert result == msg
|
assert result == msg
|
||||||
|
|
||||||
|
|
||||||
async def test_send_dice(bot: Bot, event_loop):
|
async def test_send_dice(bot: Bot):
|
||||||
""" sendDice method test """
|
""" sendDice method test """
|
||||||
from .types.dataset import MESSAGE_WITH_DICE
|
from .types.dataset import MESSAGE_WITH_DICE
|
||||||
msg = types.Message(**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)
|
result = await bot.send_dice(msg.chat.id, disable_notification=False)
|
||||||
assert result == msg
|
assert result == msg
|
||||||
|
|
||||||
|
|
||||||
async def test_send_chat_action(bot: Bot, event_loop):
|
async def test_send_chat_action(bot: Bot):
|
||||||
""" sendChatAction method test """
|
""" sendChatAction method test """
|
||||||
from .types.dataset import CHAT
|
from .types.dataset import CHAT
|
||||||
chat = types.Chat(**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)
|
result = await bot.send_chat_action(chat_id=chat.id, action=types.ChatActions.TYPING)
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
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 """
|
""" getUserProfilePhotos method test """
|
||||||
from .types.dataset import USER_PROFILE_PHOTOS, USER
|
from .types.dataset import USER_PROFILE_PHOTOS, USER
|
||||||
user = types.User(**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)
|
result = await bot.get_user_profile_photos(user_id=user.id, offset=1, limit=1)
|
||||||
assert isinstance(result, types.UserProfilePhotos)
|
assert isinstance(result, types.UserProfilePhotos)
|
||||||
|
|
||||||
|
|
||||||
async def test_get_file(bot: Bot, event_loop):
|
async def test_get_file(bot: Bot):
|
||||||
""" getFile method test """
|
""" getFile method test """
|
||||||
from .types.dataset import FILE
|
from .types.dataset import FILE
|
||||||
file = types.File(**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)
|
result = await bot.get_file(file_id=file.file_id)
|
||||||
assert isinstance(result, types.File)
|
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 """
|
""" kickChatMember method test """
|
||||||
from .types.dataset import USER, CHAT
|
from .types.dataset import USER, CHAT
|
||||||
user = types.User(**USER)
|
user = types.User(**USER)
|
||||||
chat = types.Chat(**CHAT)
|
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)
|
result = await bot.kick_chat_member(chat_id=chat.id, user_id=user.id, until_date=123)
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
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 """
|
""" unbanChatMember method test """
|
||||||
from .types.dataset import USER, CHAT
|
from .types.dataset import USER, CHAT
|
||||||
user = types.User(**USER)
|
user = types.User(**USER)
|
||||||
chat = types.Chat(**CHAT)
|
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)
|
result = await bot.unban_chat_member(chat_id=chat.id, user_id=user.id)
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
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 """
|
""" restrictChatMember method test """
|
||||||
from .types.dataset import USER, CHAT
|
from .types.dataset import USER, CHAT
|
||||||
user = types.User(**USER)
|
user = types.User(**USER)
|
||||||
chat = types.Chat(**CHAT)
|
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(
|
result = await bot.restrict_chat_member(
|
||||||
chat_id=chat.id,
|
chat_id=chat.id,
|
||||||
user_id=user.id,
|
user_id=user.id,
|
||||||
|
|
@ -321,13 +321,13 @@ async def test_restrict_chat_member(bot: Bot, event_loop):
|
||||||
assert result is True
|
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 """
|
""" promoteChatMember method test """
|
||||||
from .types.dataset import USER, CHAT
|
from .types.dataset import USER, CHAT
|
||||||
user = types.User(**USER)
|
user = types.User(**USER)
|
||||||
chat = types.Chat(**CHAT)
|
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,
|
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_delete_messages=True, can_edit_messages=True,
|
||||||
can_invite_users=True, can_pin_messages=True, can_post_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
|
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 """
|
""" exportChatInviteLink method test """
|
||||||
from .types.dataset import CHAT, INVITE_LINK
|
from .types.dataset import CHAT, INVITE_LINK
|
||||||
chat = types.Chat(**CHAT)
|
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)
|
result = await bot.export_chat_invite_link(chat_id=chat.id)
|
||||||
assert result == INVITE_LINK
|
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 """
|
""" deleteChatPhoto method test """
|
||||||
from .types.dataset import CHAT
|
from .types.dataset import CHAT
|
||||||
chat = types.Chat(**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)
|
result = await bot.delete_chat_photo(chat_id=chat.id)
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
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 """
|
""" setChatTitle method test """
|
||||||
from .types.dataset import CHAT
|
from .types.dataset import CHAT
|
||||||
chat = types.Chat(**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')
|
result = await bot.set_chat_title(chat_id=chat.id, title='Test title')
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
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 """
|
""" setChatDescription method test """
|
||||||
from .types.dataset import CHAT
|
from .types.dataset import CHAT
|
||||||
chat = types.Chat(**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')
|
result = await bot.set_chat_description(chat_id=chat.id, description='Test description')
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
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 """
|
""" pinChatMessage method test """
|
||||||
from .types.dataset import MESSAGE
|
from .types.dataset import MESSAGE
|
||||||
message = types.Message(**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,
|
result = await bot.pin_chat_message(chat_id=message.chat.id, message_id=message.message_id,
|
||||||
disable_notification=False)
|
disable_notification=False)
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
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 """
|
""" unpinChatMessage method test """
|
||||||
from .types.dataset import CHAT
|
from .types.dataset import CHAT
|
||||||
chat = types.Chat(**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)
|
result = await bot.unpin_chat_message(chat_id=chat.id)
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
assert result is True
|
||||||
|
|
||||||
|
|
||||||
async def test_leave_chat(bot: Bot, event_loop):
|
async def test_leave_chat(bot: Bot):
|
||||||
""" leaveChat method test """
|
""" leaveChat method test """
|
||||||
from .types.dataset import CHAT
|
from .types.dataset import CHAT
|
||||||
chat = types.Chat(**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)
|
result = await bot.leave_chat(chat_id=chat.id)
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
assert result is True
|
||||||
|
|
||||||
|
|
||||||
async def test_get_chat(bot: Bot, event_loop):
|
async def test_get_chat(bot: Bot):
|
||||||
""" getChat method test """
|
""" getChat method test """
|
||||||
from .types.dataset import CHAT
|
from .types.dataset import CHAT
|
||||||
chat = types.Chat(**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)
|
result = await bot.get_chat(chat_id=chat.id)
|
||||||
assert result == chat
|
assert result == chat
|
||||||
|
|
||||||
|
|
||||||
async def test_get_chat_administrators(bot: Bot, event_loop):
|
async def test_get_chat_administrators(bot: Bot):
|
||||||
""" getChatAdministrators method test """
|
""" getChatAdministrators method test """
|
||||||
from .types.dataset import CHAT, CHAT_MEMBER
|
from .types.dataset import CHAT, CHAT_MEMBER
|
||||||
chat = types.Chat(**CHAT)
|
chat = types.Chat(**CHAT)
|
||||||
member = types.ChatMember(**CHAT_MEMBER)
|
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)
|
result = await bot.get_chat_administrators(chat_id=chat.id)
|
||||||
assert result[0] == member
|
assert result[0] == member
|
||||||
assert len(result) == 2
|
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 """
|
""" getChatMembersCount method test """
|
||||||
from .types.dataset import CHAT
|
from .types.dataset import CHAT
|
||||||
chat = types.Chat(**CHAT)
|
chat = types.Chat(**CHAT)
|
||||||
count = 5
|
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)
|
result = await bot.get_chat_members_count(chat_id=chat.id)
|
||||||
assert result == count
|
assert result == count
|
||||||
|
|
||||||
|
|
||||||
async def test_get_chat_member(bot: Bot, event_loop):
|
async def test_get_chat_member(bot: Bot):
|
||||||
""" getChatMember method test """
|
""" getChatMember method test """
|
||||||
from .types.dataset import CHAT, CHAT_MEMBER
|
from .types.dataset import CHAT, CHAT_MEMBER
|
||||||
chat = types.Chat(**CHAT)
|
chat = types.Chat(**CHAT)
|
||||||
member = types.ChatMember(**CHAT_MEMBER)
|
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)
|
result = await bot.get_chat_member(chat_id=chat.id, user_id=member.user.id)
|
||||||
assert isinstance(result, types.ChatMember)
|
assert isinstance(result, types.ChatMember)
|
||||||
assert result == member
|
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 """
|
""" setChatStickerSet method test """
|
||||||
from .types.dataset import CHAT
|
from .types.dataset import CHAT
|
||||||
chat = types.Chat(**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')
|
result = await bot.set_chat_sticker_set(chat_id=chat.id, sticker_set_name='aiogram_stickers')
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
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 """
|
""" setChatStickerSet method test """
|
||||||
from .types.dataset import CHAT
|
from .types.dataset import CHAT
|
||||||
chat = types.Chat(**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)
|
result = await bot.delete_chat_sticker_set(chat_id=chat.id)
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
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 """
|
""" 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')
|
result = await bot.answer_callback_query(callback_query_id='QuERyId', text='Test Answer')
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
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 """
|
""" setMyCommands method test """
|
||||||
from .types.dataset import BOT_COMMAND
|
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)]
|
commands = [types.BotCommand(**BOT_COMMAND), types.BotCommand(**BOT_COMMAND)]
|
||||||
result = await bot.set_my_commands(commands)
|
result = await bot.set_my_commands(commands)
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
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 """
|
""" getMyCommands method test """
|
||||||
from .types.dataset import BOT_COMMAND
|
from .types.dataset import BOT_COMMAND
|
||||||
command = types.BotCommand(**BOT_COMMAND)
|
command = types.BotCommand(**BOT_COMMAND)
|
||||||
commands = [command, 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()
|
result = await bot.get_my_commands()
|
||||||
assert isinstance(result, list)
|
assert isinstance(result, list)
|
||||||
assert all([isinstance(command, types.BotCommand) for command in result])
|
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 """
|
""" editMessageText method test """
|
||||||
from .types.dataset import EDITED_MESSAGE
|
from .types.dataset import EDITED_MESSAGE
|
||||||
msg = types.Message(**EDITED_MESSAGE)
|
msg = types.Message(**EDITED_MESSAGE)
|
||||||
|
|
||||||
# message by bot
|
# 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)
|
result = await bot.edit_message_text(text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id)
|
||||||
assert result == msg
|
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 """
|
""" editMessageText method test """
|
||||||
from .types.dataset import EDITED_MESSAGE
|
from .types.dataset import EDITED_MESSAGE
|
||||||
msg = types.Message(**EDITED_MESSAGE)
|
msg = types.Message(**EDITED_MESSAGE)
|
||||||
|
|
||||||
# message by user
|
# 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)
|
result = await bot.edit_message_text(text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id)
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
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 """
|
""" 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')
|
result = await bot.set_sticker_set_thumb(name='test', user_id=123456789, thumb='file_id')
|
||||||
assert isinstance(result, bool)
|
assert isinstance(result, bool)
|
||||||
assert result is True
|
assert result is True
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,10 @@ from aiogram import Dispatcher, Bot
|
||||||
pytestmark = pytest.mark.asyncio
|
pytestmark = pytest.mark.asyncio
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture()
|
@pytest.fixture(name='bot')
|
||||||
async def bot(event_loop):
|
async def bot_fixture():
|
||||||
""" Bot fixture """
|
""" Bot fixture """
|
||||||
_bot = Bot(token='123456789:AABBCCDDEEFFaabbccddeeff-1234567890',
|
_bot = Bot(token='123456789:AABBCCDDEEFFaabbccddeeff-1234567890')
|
||||||
loop=event_loop)
|
|
||||||
yield _bot
|
yield _bot
|
||||||
await _bot.close()
|
await _bot.close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,16 @@ from . import FakeTelegram, TOKEN
|
||||||
pytestmark = pytest.mark.asyncio
|
pytestmark = pytest.mark.asyncio
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture()
|
@pytest.fixture(name='bot')
|
||||||
async def bot(event_loop):
|
async def bot_fixture():
|
||||||
""" 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
|
yield _bot
|
||||||
await _bot.close()
|
await _bot.close()
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture()
|
@pytest.fixture()
|
||||||
async def message(bot, event_loop):
|
async def message(bot):
|
||||||
"""
|
"""
|
||||||
Message fixture
|
Message fixture
|
||||||
:param bot: Telegram bot fixture
|
:param bot: Telegram bot fixture
|
||||||
|
|
@ -28,7 +28,7 @@ async def message(bot, event_loop):
|
||||||
from .types.dataset import MESSAGE
|
from .types.dataset import MESSAGE
|
||||||
msg = types.Message(**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)
|
_message = await bot.send_message(chat_id=msg.chat.id, text=msg.text)
|
||||||
|
|
||||||
yield _message
|
yield _message
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue