コード例 #1
0
    def test_instance_method_send_document(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            return kwargs['chat_id'] == chat.id and kwargs[
                'document'] == 'test_document'

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

        monkeypatch.setattr(chat.bot, 'send_document', make_assertion)
        assert chat.send_document(document='test_document')
コード例 #2
0
    def test_instance_method_send_location(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            return kwargs['chat_id'] == chat.id and kwargs[
                'latitude'] == 'test_location'

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

        monkeypatch.setattr(chat.bot, 'send_location', make_assertion)
        assert chat.send_location(latitude='test_location')
コード例 #3
0
    def test_instance_method_send_media_group(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            return kwargs['chat_id'] == chat.id and kwargs[
                'media'] == 'test_media_group'

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

        monkeypatch.setattr(chat.bot, 'send_media_group', make_assertion)
        assert chat.send_media_group(media='test_media_group')
コード例 #4
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()
コード例 #5
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()
コード例 #6
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()
コード例 #7
0
    def test_instance_method_send_video_note(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            return kwargs['chat_id'] == chat.id and kwargs[
                'video_note'] == 'test_video_note'

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

        monkeypatch.setattr(chat.bot, 'send_video_note', make_assertion)
        assert chat.send_video_note(video_note='test_video_note')
コード例 #8
0
    def test_unban_chat(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            chat_id = kwargs['chat_id'] == 42
            sender_chat_id = kwargs['sender_chat_id'] == chat.id
            return chat_id and sender_chat_id

        assert check_shortcut_signature(
            Chat.unban_chat, Bot.ban_chat_sender_chat, ['sender_chat_id'], []
        )
        assert check_shortcut_call(chat.unban_chat, chat.bot, 'unban_chat_sender_chat')
        assert check_defaults_handling(chat.unban_chat, chat.bot)

        monkeypatch.setattr(chat.bot, 'unban_chat_sender_chat', make_assertion)
        assert chat.unban_chat(42)
コード例 #9
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)
コード例 #10
0
    def test_set_permissions(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            chat_id = kwargs['chat_id'] == chat.id
            permissions = kwargs['permissions'] == self.permissions
            return chat_id and permissions

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

        monkeypatch.setattr(chat.bot, 'set_chat_permissions', make_assertion)
        assert chat.set_permissions(permissions=self.permissions)
コード例 #11
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()
コード例 #12
0
    def test_get_member(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            chat_id = kwargs['chat_id'] == chat.id
            user_id = kwargs['user_id'] == 42
            return chat_id and user_id

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

        monkeypatch.setattr(chat.bot, 'get_chat_member', make_assertion)
        assert chat.get_member(user_id=42)
コード例 #13
0
    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()
コード例 #14
0
    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()
コード例 #15
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()
コード例 #16
0
    def test_decline_join_request(self, monkeypatch, chat):
        def make_assertion(*_, **kwargs):
            return kwargs['chat_id'] == chat.id and kwargs['user_id'] == 42

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

        monkeypatch.setattr(chat.bot, 'decline_chat_join_request', make_assertion)
        assert chat.decline_join_request(user_id=42)
コード例 #17
0
    def test_revoke_invite_link(self, monkeypatch, chat):
        link = "ThisIsALink"

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

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

        monkeypatch.setattr(chat.bot, 'revoke_chat_invite_link', make_assertion)
        assert chat.revoke_invite_link(invite_link=link)
コード例 #18
0
    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')
コード例 #19
0
    def test_answer(self, monkeypatch, callback_query):
        def make_assertion(*_, **kwargs):
            return kwargs['callback_query_id'] == callback_query.id

        assert check_shortcut_signature(
            CallbackQuery.answer, Bot.answer_callback_query, ['callback_query_id'], []
        )
        assert check_shortcut_call(
            callback_query.answer, callback_query.bot, 'answer_callback_query'
        )
        assert check_defaults_handling(callback_query.answer, callback_query.bot)

        monkeypatch.setattr(callback_query.bot, 'answer_callback_query', make_assertion)
        # TODO: PEP8
        assert callback_query.answer()
コード例 #20
0
    def test_answer(self, monkeypatch, inline_query):
        def make_assertion(*_, **kwargs):
            return kwargs['inline_query_id'] == inline_query.id

        assert check_shortcut_signature(InlineQuery.answer,
                                        Bot.answer_inline_query,
                                        ['inline_query_id'],
                                        ['auto_pagination'])
        assert check_shortcut_call(inline_query.answer, inline_query.bot,
                                   'answer_inline_query')
        assert check_defaults_handling(inline_query.answer, inline_query.bot)

        monkeypatch.setattr(inline_query.bot, 'answer_inline_query',
                            make_assertion)
        assert inline_query.answer(results=[])
コード例 #21
0
    def test_promote_member(self, monkeypatch, chat, is_anonymous):
        def make_assertion(*_, **kwargs):
            chat_id = kwargs['chat_id'] == chat.id
            user_id = kwargs['user_id'] == 42
            o_i_b = kwargs.get('is_anonymous') == is_anonymous
            return chat_id and user_id and o_i_b

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

        monkeypatch.setattr(chat.bot, 'promote_chat_member', make_assertion)
        assert chat.promote_member(user_id=42, is_anonymous=is_anonymous)
コード例 #22
0
    def test_answer(self, monkeypatch, shipping_query):
        def make_assertion(*_, **kwargs):
            return kwargs['shipping_query_id'] == shipping_query.id

        assert check_shortcut_signature(ShippingQuery.answer,
                                        Bot.answer_shipping_query,
                                        ['shipping_query_id'], [])
        assert check_shortcut_call(shipping_query.answer, shipping_query.bot,
                                   'answer_shipping_query')
        assert check_defaults_handling(shipping_query.answer,
                                       shipping_query.bot)

        monkeypatch.setattr(shipping_query.bot, 'answer_shipping_query',
                            make_assertion)
        assert shipping_query.answer(ok=True)
コード例 #23
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)
コード例 #24
0
    def test_get_file_instance_method(self, monkeypatch, passport_file):
        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 check_shortcut_call(passport_file.get_file, passport_file.bot,
                                   'get_file')
        assert check_defaults_handling(passport_file.get_file,
                                       passport_file.bot)

        monkeypatch.setattr(passport_file.bot, 'get_file', make_assertion)
        assert passport_file.get_file().file_id == 'True'
コード例 #25
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', None) == 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)
コード例 #26
0
    def test_instance_method_decline_join_request(self, monkeypatch, user):
        def make_assertion(*_, **kwargs):
            chat_id = kwargs['chat_id'] == 'chat_id'
            user_id = kwargs['user_id'] == user.id
            return chat_id and user_id

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

        monkeypatch.setattr(user.bot, 'decline_chat_join_request',
                            make_assertion)
        assert user.decline_join_request(chat_id='chat_id')
コード例 #27
0
    def test_answer(self, monkeypatch, pre_checkout_query):
        def make_assertion(*_, **kwargs):
            return kwargs['pre_checkout_query_id'] == pre_checkout_query.id

        assert check_shortcut_signature(
            PreCheckoutQuery.answer, Bot.answer_pre_checkout_query, ['pre_checkout_query_id'], []
        )
        assert check_shortcut_call(
            pre_checkout_query.answer,
            pre_checkout_query.bot,
            'answer_pre_checkout_query',
        )
        assert check_defaults_handling(pre_checkout_query.answer, pre_checkout_query.bot)

        monkeypatch.setattr(pre_checkout_query.bot, 'answer_pre_checkout_query', make_assertion)
        assert pre_checkout_query.answer(ok=True)
コード例 #28
0
    def test_restrict_member(self, monkeypatch, chat):
        permissions = ChatPermissions(True, False, True, False, True, False, True, False)

        def make_assertion(*_, **kwargs):
            chat_id = kwargs['chat_id'] == chat.id
            user_id = kwargs['user_id'] == 42
            o_i_b = kwargs.get('permissions') == permissions
            return chat_id and user_id and o_i_b

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

        monkeypatch.setattr(chat.bot, 'restrict_chat_member', make_assertion)
        assert chat.restrict_member(user_id=42, permissions=permissions)
コード例 #29
0
    def test_decline(self, monkeypatch, chat_join_request):
        def make_assertion(*_, **kwargs):
            chat_id_test = kwargs['chat_id'] == chat_join_request.chat.id
            user_id_test = kwargs['user_id'] == chat_join_request.from_user.id

            return chat_id_test and user_id_test

        assert check_shortcut_signature(
            ChatJoinRequest.decline, Bot.decline_chat_join_request, ['chat_id', 'user_id'], []
        )
        assert check_shortcut_call(
            chat_join_request.decline, chat_join_request.bot, 'decline_chat_join_request'
        )
        assert check_defaults_handling(chat_join_request.decline, chat_join_request.bot)

        monkeypatch.setattr(chat_join_request.bot, 'decline_chat_join_request', make_assertion)
        assert chat_join_request.decline()
コード例 #30
0
 def make_assertion(*_, **kwargs):
     title = kwargs['title'] == 'title'
     description = kwargs['description'] == 'description'
     payload = kwargs['payload'] == 'payload'
     provider_token = kwargs['provider_token'] == 'provider_token'
     start_parameter = kwargs['start_parameter'] == 'start_parameter'
     currency = kwargs['currency'] == 'currency'
     prices = kwargs['prices'] == 'prices'
     args = (
         title
         and description
         and payload
         and provider_token
         and start_parameter
         and currency
         and prices
     )
     return (
         kwargs['chat_id'] == user.id and args and check_shortcut_call(kwargs, send_invoice)
     )