Esempio n. 1
0
    def test_get_members_count(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            return kwargs['chat_id'] == chat.id

        assert check_shortcut_signature(Chat.get_members_count,
                                        Bot.get_chat_members_count,
                                        ['chat_id'], [])
        assert check_shortcut_call(chat.get_members_count, chat.bot,
                                   'get_chat_members_count')
        assert check_defaults_handling(chat.get_members_count, chat.bot)

        monkeypatch.setattr(chat.bot, 'get_chat_members_count', make_assertion)
        assert chat.get_members_count()
Esempio n. 2
0
    def test_instance_method_send_contact(self, monkeypatch, chat):
        send_contact = chat.bot.send_contact

        def make_assertion(*_, **kwargs):
            return (kwargs['chat_id'] == chat.id
                    and kwargs['phone_number'] == 'test_contact'
                    and check_shortcut_call(kwargs, send_contact))

        assert check_shortcut_signature(Chat.send_contact, Bot.send_contact,
                                        ['chat_id'], [])

        monkeypatch.setattr(chat.bot, 'send_contact', make_assertion)
        assert chat.send_contact(phone_number='test_contact')
Esempio n. 3
0
    def test_instance_method_send_audio(self, monkeypatch, chat):
        send_audio = chat.bot.send_audio

        def make_assertion(*_, **kwargs):
            return (kwargs['chat_id'] == chat.id
                    and kwargs['audio'] == 'test_audio'
                    and check_shortcut_call(kwargs, send_audio))

        assert check_shortcut_signature(Chat.send_audio, Bot.send_audio,
                                        ['chat_id'], [])

        monkeypatch.setattr(chat.bot, 'send_audio', make_assertion)
        assert chat.send_audio(audio='test_audio')
Esempio n. 4
0
    def test_unpin_message(self, monkeypatch, chat):
        unpin_chat_message = chat.bot.unpin_chat_message

        def make_assertion(*_, **kwargs):
            return kwargs['chat_id'] == chat.id and check_shortcut_call(
                kwargs, unpin_chat_message)

        assert check_shortcut_signature(Chat.unpin_message,
                                        Bot.unpin_chat_message, ['chat_id'],
                                        [])

        monkeypatch.setattr(chat.bot, 'unpin_chat_message', make_assertion)
        assert chat.unpin_message()
Esempio n. 5
0
    def test_instance_method_send_media_group(self, monkeypatch, chat):
        send_media_group = chat.bot.send_media_group

        def make_assertion(*_, **kwargs):
            return (kwargs['chat_id'] == chat.id
                    and kwargs['media'] == 'test_media_group'
                    and check_shortcut_call(kwargs, send_media_group))

        assert check_shortcut_signature(Chat.send_media_group,
                                        Bot.send_media_group, ['chat_id'], [])

        monkeypatch.setattr(chat.bot, 'send_media_group', make_assertion)
        assert chat.send_media_group(media='test_media_group')
Esempio n. 6
0
    def test_instance_method_send_video_note(self, monkeypatch, chat):
        send_video_note = chat.bot.send_video_note

        def make_assertion(*_, **kwargs):
            return (kwargs['chat_id'] == chat.id
                    and kwargs['video_note'] == 'test_video_note'
                    and check_shortcut_call(kwargs, send_video_note))

        assert check_shortcut_signature(Chat.send_video_note,
                                        Bot.send_video_note, ['chat_id'], [])

        monkeypatch.setattr(chat.bot, 'send_video_note', make_assertion)
        assert chat.send_video_note(video_note='test_video_note')
Esempio n. 7
0
    def test_get_members_count(self, monkeypatch, chat):
        get_chat_members_count = chat.bot.get_chat_members_count

        def make_assertion(*_, **kwargs):
            return kwargs['chat_id'] == chat.id and check_shortcut_call(
                kwargs, get_chat_members_count)

        assert check_shortcut_signature(Chat.get_members_count,
                                        Bot.get_chat_members_count,
                                        ['chat_id'], [])

        monkeypatch.setattr(chat.bot, 'get_chat_members_count', make_assertion)
        assert chat.get_members_count()
Esempio n. 8
0
    def test_instance_method_copy_message(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            from_chat_id = kwargs['from_chat_id'] == chat.id
            message_id = kwargs['message_id'] == 42
            chat_id = kwargs['chat_id'] == 'test_copy'
            return from_chat_id and message_id and chat_id

        assert check_shortcut_signature(Chat.copy_message, Bot.copy_message, ['from_chat_id'], [])
        assert check_shortcut_call(chat.copy_message, chat.bot, 'copy_message')
        assert check_defaults_handling(chat.copy_message, chat.bot)

        monkeypatch.setattr(chat.bot, 'copy_message', make_assertion)
        assert chat.copy_message(chat_id='test_copy', message_id=42)
    async def test_get_file_instance_method(self, monkeypatch, sticker):
        async def make_assertion(*_, **kwargs):
            return kwargs["file_id"] == sticker.file_id

        assert check_shortcut_signature(Sticker.get_file, Bot.get_file,
                                        ["file_id"], [])
        assert await check_shortcut_call(sticker.get_file, sticker.get_bot(),
                                         "get_file")
        assert await check_defaults_handling(sticker.get_file,
                                             sticker.get_bot())

        monkeypatch.setattr(sticker.get_bot(), "get_file", make_assertion)
        assert await sticker.get_file()
Esempio n. 10
0
    def test_ban_member(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            chat_id = kwargs['chat_id'] == chat.id
            user_id = kwargs['user_id'] == 42
            until = kwargs['until_date'] == 43
            return chat_id and user_id and until

        assert check_shortcut_signature(Chat.ban_member, Bot.ban_chat_member, ['chat_id'], [])
        assert check_shortcut_call(chat.ban_member, chat.bot, 'ban_chat_member')
        assert check_defaults_handling(chat.ban_member, chat.bot)

        monkeypatch.setattr(chat.bot, 'ban_chat_member', make_assertion)
        assert chat.ban_member(user_id=42, until_date=43)
Esempio n. 11
0
    def test_unban_member(self, monkeypatch, chat, only_if_banned):
        def make_assertion(*_, **kwargs):
            chat_id = kwargs['chat_id'] == chat.id
            user_id = kwargs['user_id'] == 42
            o_i_b = kwargs.get('only_if_banned') == only_if_banned
            return chat_id and user_id and o_i_b

        assert check_shortcut_signature(Chat.unban_member, Bot.unban_chat_member, ['chat_id'], [])
        assert check_shortcut_call(chat.unban_member, chat.bot, 'unban_chat_member')
        assert check_defaults_handling(chat.unban_member, chat.bot)

        monkeypatch.setattr(chat.bot, 'unban_chat_member', make_assertion)
        assert chat.unban_member(user_id=42, only_if_banned=only_if_banned)
Esempio n. 12
0
    def test_send_action(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            id_ = kwargs['chat_id'] == chat.id
            action = kwargs['action'] == ChatAction.TYPING
            return id_ and action

        assert check_shortcut_signature(chat.send_action, Bot.send_chat_action, ['chat_id'], [])
        assert check_shortcut_call(chat.send_action, chat.bot, 'send_chat_action')
        assert check_defaults_handling(chat.send_action, chat.bot)

        monkeypatch.setattr(chat.bot, 'send_chat_action', make_assertion)
        assert chat.send_action(action=ChatAction.TYPING)
        assert chat.send_action(action=ChatAction.TYPING)
Esempio n. 13
0
    def test_instance_method_send_animation(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            return kwargs['chat_id'] == chat.id and kwargs[
                'animation'] == 'test_animation'

        assert check_shortcut_signature(Chat.send_animation,
                                        Bot.send_animation, ['chat_id'], [])
        assert check_shortcut_call(chat.send_animation, chat.bot,
                                   'send_animation')
        assert check_defaults_handling(chat.send_animation, chat.bot)

        monkeypatch.setattr(chat.bot, 'send_animation', make_assertion)
        assert chat.send_animation(animation='test_animation')
Esempio n. 14
0
    def test_unpin_message(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            return kwargs['chat_id'] == chat.id

        assert check_shortcut_signature(Chat.unpin_message,
                                        Bot.unpin_chat_message, ['chat_id'],
                                        [])
        assert check_shortcut_call(chat.unpin_message, chat.bot,
                                   'unpin_chat_message')
        assert check_defaults_handling(chat.unpin_message, chat.bot)

        monkeypatch.setattr(chat.bot, 'unpin_chat_message', make_assertion)
        assert chat.unpin_message()
Esempio n. 15
0
    def test_instance_method_send_location(self, monkeypatch, chat):
        send_location = chat.bot.send_location

        def make_assertion(*_, **kwargs):
            return (kwargs['chat_id'] == chat.id
                    and kwargs['latitude'] == 'test_location'
                    and check_shortcut_call(kwargs, send_location))

        assert check_shortcut_signature(Chat.send_location, Bot.send_location,
                                        ['chat_id'], [])

        monkeypatch.setattr(chat.bot, 'send_location', make_assertion)
        assert chat.send_location(latitude='test_location')
Esempio n. 16
0
    def test_get_file_instance_method(self, monkeypatch, video_note):
        get_file = video_note.bot.get_file

        def make_assertion(*_, **kwargs):
            return kwargs[
                'file_id'] == video_note.file_id and check_shortcut_call(
                    kwargs, get_file)

        assert check_shortcut_signature(VideoNote.get_file, Bot.get_file,
                                        ['file_id'], [])

        monkeypatch.setattr('telegram.Bot.get_file', make_assertion)
        assert video_note.get_file()
Esempio n. 17
0
    def test_instance_method_send_sticker(self, monkeypatch, chat):
        send_sticker = chat.bot.send_sticker

        def make_assertion(*_, **kwargs):
            return (kwargs['chat_id'] == chat.id
                    and kwargs['sticker'] == 'test_sticker'
                    and check_shortcut_call(kwargs, send_sticker))

        assert check_shortcut_signature(Chat.send_sticker, Bot.send_sticker,
                                        ['chat_id'], [])

        monkeypatch.setattr(chat.bot, 'send_sticker', make_assertion)
        assert chat.send_sticker(sticker='test_sticker')
Esempio n. 18
0
    def test_instance_method_send_document(self, monkeypatch, chat):
        send_document = chat.bot.send_document

        def make_assertion(*_, **kwargs):
            return (kwargs['chat_id'] == chat.id
                    and kwargs['document'] == 'test_document'
                    and check_shortcut_call(kwargs, send_document))

        assert check_shortcut_signature(Chat.send_document, Bot.send_document,
                                        ['chat_id'], [])

        monkeypatch.setattr(chat.bot, 'send_document', make_assertion)
        assert chat.send_document(document='test_document')
Esempio n. 19
0
    def test_get_small_file_instance_method(self, monkeypatch, chat_photo):
        def make_assertion(*_, **kwargs):
            return kwargs['file_id'] == chat_photo.small_file_id

        assert check_shortcut_signature(ChatPhoto.get_small_file, Bot.get_file,
                                        ['file_id'], [])
        assert check_shortcut_call(chat_photo.get_small_file, chat_photo.bot,
                                   'get_file')
        assert check_defaults_handling(chat_photo.get_small_file,
                                       chat_photo.bot)

        monkeypatch.setattr(chat_photo.bot, 'get_file', make_assertion)
        assert chat_photo.get_small_file()
Esempio n. 20
0
    def test_instance_method_send_animation(self, monkeypatch, user):
        send_animation = user.bot.send_animation

        def make_assertion(*_, **kwargs):
            return (
                kwargs['chat_id'] == user.id
                and kwargs['animation'] == 'test_animation'
                and check_shortcut_call(kwargs, send_animation)
            )

        assert check_shortcut_signature(User.send_animation, Bot.send_animation, ['chat_id'], [])

        monkeypatch.setattr(user.bot, 'send_animation', make_assertion)
        assert user.send_animation('test_animation')
Esempio n. 21
0
    def test_instance_method_send_poll(self, monkeypatch, user):
        send_poll = user.bot.send_poll

        def make_assertion(*_, **kwargs):
            return (
                kwargs['chat_id'] == user.id
                and kwargs['question'] == 'test_poll'
                and check_shortcut_call(kwargs, send_poll)
            )

        assert check_shortcut_signature(User.send_poll, Bot.send_poll, ['chat_id'], [])

        monkeypatch.setattr(user.bot, 'send_poll', make_assertion)
        assert user.send_poll(question='test_poll', options=[1, 2])
Esempio n. 22
0
    def test_instance_method_send_photo(self, monkeypatch, user):
        send_photo = user.bot.send_photo

        def make_assertion(*_, **kwargs):
            return (
                kwargs['chat_id'] == user.id
                and kwargs['photo'] == 'test_photo'
                and check_shortcut_call(kwargs, send_photo)
            )

        assert check_shortcut_signature(User.send_photo, Bot.send_photo, ['chat_id'], [])

        monkeypatch.setattr(user.bot, 'send_photo', make_assertion)
        assert user.send_photo('test_photo')
Esempio n. 23
0
    def test_instance_method_send_voice(self, monkeypatch, user):
        send_voice = user.bot.send_voice

        def make_assertion(*_, **kwargs):
            return (
                kwargs['chat_id'] == user.id
                and kwargs['voice'] == 'test_voice'
                and check_shortcut_call(kwargs, send_voice)
            )

        assert check_shortcut_signature(User.send_voice, Bot.send_voice, ['chat_id'], [])

        monkeypatch.setattr(user.bot, 'send_voice', make_assertion)
        assert user.send_voice('test_voice')
Esempio n. 24
0
    def test_get_administrators(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            return kwargs['chat_id'] == chat.id

        assert check_shortcut_signature(Chat.get_administrators,
                                        Bot.get_chat_administrators,
                                        ['chat_id'], [])
        assert check_shortcut_call(chat.get_administrators, chat.bot,
                                   'get_chat_administrators')
        assert check_defaults_handling(chat.get_administrators, chat.bot)

        monkeypatch.setattr(chat.bot, 'get_chat_administrators',
                            make_assertion)
        assert chat.get_administrators()
Esempio n. 25
0
    def test_create_invite_link(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            return kwargs['chat_id'] == chat.id

        assert check_shortcut_signature(Chat.create_invite_link,
                                        Bot.create_chat_invite_link,
                                        ['chat_id'], [])
        assert check_shortcut_call(chat.create_invite_link, chat.bot,
                                   'create_chat_invite_link')
        assert check_defaults_handling(chat.create_invite_link, chat.bot)

        monkeypatch.setattr(chat.bot, 'create_chat_invite_link',
                            make_assertion)
        assert chat.create_invite_link()
Esempio n. 26
0
    async def test_get_file_instance_method(self, monkeypatch, passport_file):
        async def make_assertion(*_, **kwargs):
            result = kwargs["file_id"] == passport_file.file_id
            # we need to be a bit hacky here, b/c PF.get_file needs Bot.get_file to return a File
            return File(file_id=result, file_unique_id=result)

        assert check_shortcut_signature(PassportFile.get_file, Bot.get_file, ["file_id"], [])
        assert await check_shortcut_call(
            passport_file.get_file, passport_file.get_bot(), "get_file"
        )
        assert await check_defaults_handling(passport_file.get_file, passport_file.get_bot())

        monkeypatch.setattr(passport_file.get_bot(), "get_file", make_assertion)
        assert (await passport_file.get_file()).file_id == "True"
    def test_instance_method_copy_message(self, monkeypatch, user):
        def make_assertion(*_, **kwargs):
            chat_id = kwargs['chat_id'] == 'chat_id'
            message_id = kwargs['message_id'] == 'message_id'
            user_id = kwargs['from_chat_id'] == user.id
            return chat_id and message_id and user_id

        assert check_shortcut_signature(User.copy_message, Bot.copy_message,
                                        ['from_chat_id'], [])
        assert check_shortcut_call(user.copy_message, user.bot, 'copy_message')
        assert check_defaults_handling(user.copy_message, user.bot)

        monkeypatch.setattr(user.bot, 'copy_message', make_assertion)
        assert user.copy_message(chat_id='chat_id', message_id='message_id')
    def test_instance_method_unpin_all_messages(self, monkeypatch, user):
        def make_assertion(*_, **kwargs):
            return kwargs['chat_id'] == user.id

        assert check_shortcut_signature(User.unpin_all_messages,
                                        Bot.unpin_all_chat_messages,
                                        ['chat_id'], [])
        assert check_shortcut_call(user.unpin_all_messages, user.bot,
                                   'unpin_all_chat_messages')
        assert check_defaults_handling(user.unpin_all_messages, user.bot)

        monkeypatch.setattr(user.bot, 'unpin_all_chat_messages',
                            make_assertion)
        assert user.unpin_all_messages()
    def test_instance_method_get_profile_photos(self, monkeypatch, user):
        def make_assertion(*_, **kwargs):
            return kwargs['user_id'] == user.id

        assert check_shortcut_signature(User.get_profile_photos,
                                        Bot.get_user_profile_photos,
                                        ['user_id'], [])
        assert check_shortcut_call(user.get_profile_photos, user.bot,
                                   'get_user_profile_photos')
        assert check_defaults_handling(user.get_profile_photos, user.bot)

        monkeypatch.setattr(user.bot, 'get_user_profile_photos',
                            make_assertion)
        assert user.get_profile_photos()
    async def test_get_small_file_instance_method(self, monkeypatch,
                                                  chat_photo):
        async def make_assertion(*_, **kwargs):
            return kwargs["file_id"] == chat_photo.small_file_id

        assert check_shortcut_signature(ChatPhoto.get_small_file, Bot.get_file,
                                        ["file_id"], [])
        assert await check_shortcut_call(chat_photo.get_small_file,
                                         chat_photo.get_bot(), "get_file")
        assert await check_defaults_handling(chat_photo.get_small_file,
                                             chat_photo.get_bot())

        monkeypatch.setattr(chat_photo.get_bot(), "get_file", make_assertion)
        assert await chat_photo.get_small_file()