Example #1
0
    async def send_document(
        cls,
        chat_id: typing.Union[base.Integer, base.String],
        document: typing.Union[base.InputFile, base.String],
        filename: str = 'document',
        thumb: typing.Union[base.InputFile, base.String, None] = None,
        caption: typing.Union[base.String, None] = None,
        parse_mode: typing.Union[base.String, None] = None,
        disable_notification: typing.Union[base.Boolean, None] = None,
        reply_to_message_id: typing.Union[base.Integer, None] = None,
        reply_markup: typing.Union[types.InlineKeyboardMarkup,
                                   types.ReplyKeyboardMarkup,
                                   types.ReplyKeyboardRemove, types.ForceReply,
                                   None] = None
    ) -> types.Message:
        reply_markup = prepare_arg(reply_markup)
        payload = generate_payload(**locals(), exclude=[filename])
        if cls.bot.parse_mode:
            payload.setdefault('parse_mode', cls.bot.parse_mode)

        files = {filename: document}
        prepare_file(payload, files, filename, document)

        result = await cls.bot.request(api.Methods.SEND_DOCUMENT, payload,
                                       files)
        return types.Message(**result)
Example #2
0
async def test_send_dice(bot: Bot, event_loop):
    """ sendDice method test """
    from .types.dataset import MESSAGE_WITH_DICE
    msg = types.Message(**MESSAGE_WITH_DICE)

    async with FakeTelegram(message_data=MESSAGE_WITH_DICE, loop=event_loop):
        result = await bot.send_dice(msg.chat.id, disable_notification=False)
        assert result == msg
Example #3
0
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):
        result = await bot.send_message(chat_id=msg.chat.id, text=msg.text)
        assert result == msg
Example #4
0
async def test_send_document(bot: Bot):
    """ sendDocument method test with file_id """
    from .types.dataset import MESSAGE_WITH_DOCUMENT
    msg = types.Message(**MESSAGE_WITH_DOCUMENT)

    async with FakeTelegram(message_data=MESSAGE_WITH_DOCUMENT):
        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
Example #5
0
async def test_forward_message(bot: Bot):
    """ forwardMessage method test """
    from .types.dataset import FORWARDED_MESSAGE
    msg = types.Message(**FORWARDED_MESSAGE)

    async with FakeTelegram(message_data=FORWARDED_MESSAGE):
        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
Example #6
0
async def test_stop_message_live_location_by_bot(bot: Bot):
    """ stopMessageLiveLocation method test """
    from .types.dataset import MESSAGE_WITH_LOCATION
    msg = types.Message(**MESSAGE_WITH_LOCATION)

    # stopping bot message
    async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION):
        result = await bot.stop_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id)
        assert result == msg
Example #7
0
async def test_edit_message_text_by_bot(bot: Bot):
    """ editMessageText method test """
    from .types.dataset import EDITED_MESSAGE
    msg = types.Message(**EDITED_MESSAGE)

    # message by bot
    async with FakeTelegram(message_data=EDITED_MESSAGE):
        result = await bot.edit_message_text(text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id)
        assert result == msg
Example #8
0
async def test_stop_message_live_location_by_user(bot: Bot):
    """ stopMessageLiveLocation method test """
    from .types.dataset import MESSAGE_WITH_LOCATION
    msg = types.Message(**MESSAGE_WITH_LOCATION)

    # stopping user's message
    async with FakeTelegram(message_data=True):
        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
Example #9
0
async def test_send_audio(bot: Bot):
    """ sendAudio method test with file_id """
    from .types.dataset import MESSAGE_WITH_AUDIO
    msg = types.Message(**MESSAGE_WITH_AUDIO)

    async with FakeTelegram(message_data=MESSAGE_WITH_AUDIO):
        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
Example #10
0
async def test_send_photo(bot: Bot):
    """ sendPhoto method test with file_id """
    from .types.dataset import MESSAGE_WITH_PHOTO, PHOTO
    msg = types.Message(**MESSAGE_WITH_PHOTO)
    photo = types.PhotoSize(**PHOTO)

    async with FakeTelegram(message_data=MESSAGE_WITH_PHOTO):
        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
Example #11
0
async def test_edit_message_text_by_user(bot: Bot):
    """ editMessageText method test """
    from .types.dataset import EDITED_MESSAGE
    msg = types.Message(**EDITED_MESSAGE)

    # message by user
    async with FakeTelegram(message_data=True):
        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
Example #12
0
async def test_pin_chat_message(bot: Bot):
    """ pinChatMessage method test """
    from .types.dataset import MESSAGE
    message = types.Message(**MESSAGE)

    async with FakeTelegram(message_data=True):
        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
Example #13
0
async def test_send_contact(bot: Bot):
    """ sendContact method test """
    from .types.dataset import MESSAGE_WITH_CONTACT, CONTACT
    msg = types.Message(**MESSAGE_WITH_CONTACT)
    contact = types.Contact(**CONTACT)

    async with FakeTelegram(message_data=MESSAGE_WITH_CONTACT):
        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
Example #14
0
async def test_send_location(bot: Bot):
    """ sendLocation method test """
    from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION
    msg = types.Message(**MESSAGE_WITH_LOCATION)
    location = types.Location(**LOCATION)

    async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION):
        result = await bot.send_location(msg.chat.id, latitude=location.latitude, longitude=location.longitude,
                                         live_period=10, disable_notification=False)
        assert result == msg
Example #15
0
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_data=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)
        assert result == msg
Example #16
0
async def test_send_voice(bot: Bot):
    """ sendVoice method test with file_id """
    from .types.dataset import MESSAGE_WITH_VOICE, VOICE
    msg = types.Message(**MESSAGE_WITH_VOICE)
    voice = types.Voice(**VOICE)

    async with FakeTelegram(message_data=MESSAGE_WITH_VOICE):
        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
Example #17
0
async def test_send_video_note(bot: Bot):
    """ sendVideoNote method test with file_id """
    from .types.dataset import MESSAGE_WITH_VIDEO_NOTE, VIDEO_NOTE
    msg = types.Message(**MESSAGE_WITH_VIDEO_NOTE)
    video_note = types.VideoNote(**VIDEO_NOTE)

    async with FakeTelegram(message_data=MESSAGE_WITH_VIDEO_NOTE):
        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
Example #18
0
async def test_edit_message_live_location_by_user(bot: Bot):
    """ editMessageLiveLocation method test """
    from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION
    msg = types.Message(**MESSAGE_WITH_LOCATION)
    location = types.Location(**LOCATION)

    # editing user's message
    async with FakeTelegram(message_data=True):
        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
Example #19
0
async def test_send_media_group(bot: Bot):
    """ sendMediaGroup method test with file_id """
    from .types.dataset import MESSAGE_WITH_MEDIA_GROUP, PHOTO
    msg = types.Message(**MESSAGE_WITH_MEDIA_GROUP)
    photo = types.PhotoSize(**PHOTO)
    media = [types.InputMediaPhoto(media=photo.file_id), types.InputMediaPhoto(media=photo.file_id)]

    async with FakeTelegram(message_data=[MESSAGE_WITH_MEDIA_GROUP, MESSAGE_WITH_MEDIA_GROUP]):
        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
Example #20
0
async def send_all_yes(query: types.CallbackQuery, state: FSMContext):
    await query.answer()
    await query.message.delete_reply_markup()

    sending_message_id = await services.admin.get_sending_message_id(state)
    sending_message = types.Message(message_id=sending_message_id,
                                    chat=types.Chat(id=query.from_user.id))
    count_alive_users = await services.admin.send_all(
        sending_message=sending_message, user_model=User)
    await query.message.answer(
        config.MSG_SUCCESFUL_SEND_ALL.format(count_alive_users))
Example #21
0
async def test_send_video(bot: Bot):
    """ sendVideo method test with file_id """
    from .types.dataset import MESSAGE_WITH_VIDEO, VIDEO
    msg = types.Message(**MESSAGE_WITH_VIDEO)
    video = types.Video(**VIDEO)

    async with FakeTelegram(message_data=MESSAGE_WITH_VIDEO):
        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
Example #22
0
async def test_send_venue(bot: Bot):
    """ sendVenue method test """
    from .types.dataset import MESSAGE_WITH_VENUE, VENUE, LOCATION
    msg = types.Message(**MESSAGE_WITH_VENUE)
    location = types.Location(**LOCATION)
    venue = types.Venue(**VENUE)

    async with FakeTelegram(message_data=MESSAGE_WITH_VENUE):
        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
Example #23
0
async def message(bot):
    """
    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_data=MESSAGE):
        _message = await bot.send_message(chat_id=msg.chat.id, text=msg.text)

    yield _message
Example #24
0
async def scheduler():
    if RSS:
        for feed in RSS_FEEDS:
            aioschedule.every(DELAY).seconds.do(rss_task, feed["url"],
                                                feed["feed_id"],
                                                feed["chat_id"])

    if VK:
        aioschedule.every(DELAY).seconds.do(vk_timer)

    if KATZ_BOTS:
        aioschedule.every(DELAY).seconds.do(Poll.close_old)

    if BLOODYKNIGHT:
        message = types.Message(chat=types.Chat(id=-1001410092459))
        aioschedule.every().day.at("8:00").do(monobank, message)

    while True:
        await aioschedule.run_pending()
        await asyncio.sleep(5)
Example #25
0
 def setUp(self):
     self.message = types.Message(**MESSAGE)
Example #26
0
import datetime

from aiogram import types
from .dataset import MESSAGE

message = types.Message(**MESSAGE)


def test_export():
    exported_chat = message.to_python()
    assert isinstance(exported_chat, dict)
    assert exported_chat == MESSAGE


def test_message_id():
    # assert hash(message) == MESSAGE['message_id']
    assert message.message_id == MESSAGE['message_id']
    assert message['message_id'] == MESSAGE['message_id']


def test_from():
    assert isinstance(message.from_user, types.User)
    assert message.from_user == message['from']


def test_chat():
    assert isinstance(message.chat, types.Chat)
    assert message.chat == message['chat']


def test_date():
Example #27
0
def booking_message():
    MESSAGE["text"] = "/book 1:00 1"
    return types.Message(**MESSAGE)
Example #28
0
def non_booking_message():
    return types.Message(**MESSAGE)
Example #29
0
def get_message_with_text(text: str) -> types.Message:
    return types.Message(**{
        'text': text,
    })