def test_channel_post(self, message):
        handler = MessageHandler(None, self.callback_basic, edited_updates=False,
                                 message_updates=False, channel_post_updates=True)

        assert not handler.check_update(Update(0, edited_message=message))
        assert not handler.check_update(Update(0, message=message))
        assert handler.check_update(Update(0, channel_post=message))
        assert not handler.check_update(Update(0, edited_channel_post=message))
    def test_with_filter(self, message):
        handler = MessageHandler(filters.ChatType.GROUP, self.callback)

        message.chat.type = "group"
        assert handler.check_update(Update(0, message))

        message.chat.type = "private"
        assert not handler.check_update(Update(0, message))
    def test_multiple_flags_deprecated(self, message):
        handler = MessageHandler(None, self.callback_basic, edited_updates=True,
                                 message_updates=True, channel_post_updates=True)

        assert handler.check_update(Update(0, edited_message=message))
        assert handler.check_update(Update(0, message=message))
        assert handler.check_update(Update(0, channel_post=message))
        assert handler.check_update(Update(0, edited_channel_post=message))
Exemplo n.º 4
0
    def test_channel_post(self, message):
        handler = MessageHandler(None, self.callback_basic, edited_updates=False,
                                 message_updates=False, channel_post_updates=True)

        assert not handler.check_update(Update(0, edited_message=message))
        assert not handler.check_update(Update(0, message=message))
        assert handler.check_update(Update(0, channel_post=message))
        assert not handler.check_update(Update(0, edited_channel_post=message))
Exemplo n.º 5
0
    def test_with_filter(self, message):
        handler = MessageHandler(Filters.command, self.callback_basic)

        message.text = '/test'
        assert handler.check_update(Update(0, message))

        message.text = 'test'
        assert not handler.check_update(Update(0, message))
Exemplo n.º 6
0
    def test_with_filter(self, message):
        handler = MessageHandler(Filters.command, self.callback_basic)

        message.text = '/test'
        assert handler.check_update(Update(0, message))

        message.text = 'test'
        assert not handler.check_update(Update(0, message))
Exemplo n.º 7
0
    def test_with_filter(self, message):
        handler = MessageHandler(Filters.group, self.callback_basic)

        message.chat.type = 'group'
        assert handler.check_update(Update(0, message))

        message.chat.type = 'private'
        assert not handler.check_update(Update(0, message))
Exemplo n.º 8
0
    def test_allow_edited(self, message):
        with pytest.warns(UserWarning):
            handler = MessageHandler(None, self.callback_basic, message_updates=True,
                                     allow_edited=True, channel_post_updates=False)

        assert handler.check_update(Update(0, edited_message=message))
        assert handler.check_update(Update(0, message=message))
        assert not handler.check_update(Update(0, channel_post=message))
        assert handler.check_update(Update(0, edited_channel_post=message))
    def test_allow_edited(self, message):
        with pytest.warns(UserWarning):
            handler = MessageHandler(None, self.callback_basic, message_updates=True,
                                     allow_edited=True, channel_post_updates=False)

        assert handler.check_update(Update(0, edited_message=message))
        assert handler.check_update(Update(0, message=message))
        assert not handler.check_update(Update(0, channel_post=message))
        assert handler.check_update(Update(0, edited_channel_post=message))
Exemplo n.º 10
0
    def test_specific_filters(self, message):
        f = (~Filters.update.messages
             & ~Filters.update.channel_post
             & Filters.update.edited_channel_post)
        handler = MessageHandler(f, self.callback_basic)

        assert not handler.check_update(Update(0, edited_message=message))
        assert not handler.check_update(Update(0, message=message))
        assert not handler.check_update(Update(0, channel_post=message))
        assert handler.check_update(Update(0, edited_channel_post=message))
    def test_specific_filters(self, message):
        f = (~filters.UpdateType.MESSAGES
             & ~filters.UpdateType.CHANNEL_POST
             & filters.UpdateType.EDITED_CHANNEL_POST)
        handler = MessageHandler(f, self.callback)

        assert not handler.check_update(Update(0, edited_message=message))
        assert not handler.check_update(Update(0, message=message))
        assert not handler.check_update(Update(0, channel_post=message))
        assert handler.check_update(Update(0, edited_channel_post=message))
Exemplo n.º 12
0
    def test_multiple_flags(self, message):
        handler = MessageHandler(None,
                                 self.mh_basic_handler,
                                 edited_updates=True,
                                 message_updates=True,
                                 channel_post_updates=True)

        assert handler.check_update(Update(0, edited_message=message))
        assert handler.check_update(Update(0, message=message))
        assert handler.check_update(Update(0, channel_post=message))
        assert not handler.check_update(Update(0, edited_channel_post=message))
Exemplo n.º 13
0
    def test_basic(self, dp, message):
        handler = MessageHandler(None, self.callback_basic)
        dp.add_handler(handler)

        assert handler.check_update(Update(0, message))
        dp.process_update(Update(0, message))
        assert self.test_flag
Exemplo n.º 14
0
    def test_basic(self, dp, message):
        handler = MessageHandler(None, self.callback_basic)
        dp.add_handler(handler)

        assert handler.check_update(Update(0, message))
        dp.process_update(Update(0, message))
        assert self.test_flag
    def test_filters_returns_empty_dict(self):
        class DataFilter(MessageFilter):
            data_filter = True

            def filter(self, msg: Message):
                return {}

        handler = MessageHandler(DataFilter(), self.callback)
        assert handler.check_update(Update(0, message)) is False
Exemplo n.º 16
0
    def test_callback_query_with_filter(self, message):
        class TestFilter(UpdateFilter):
            flag = False

            def filter(self, u):
                self.flag = True

        test_filter = TestFilter()
        handler = MessageHandler(test_filter, self.callback_basic)

        update = Update(1, callback_query=CallbackQuery(1, None, None, message=message))

        assert update.effective_message
        assert not handler.check_update(update)
        assert not test_filter.flag
Exemplo n.º 17
0
 def test_other_update_types(self, false_update):
     handler = MessageHandler(None, self.callback_basic, edited_updates=True)
     assert not handler.check_update(false_update)
Exemplo n.º 18
0
 def test_other_update_types(self, false_update):
     handler = MessageHandler(None,
                              self.callback_basic,
                              edited_updates=True)
     assert not handler.check_update(false_update)
 def test_other_update_types(self, false_update):
     handler = MessageHandler(None, self.callback)
     assert not handler.check_update(false_update)
     assert not handler.check_update("string")