def test_pattern(self, message): handler = RegexHandler('.*est.*', self.callback_basic) assert handler.check_update(Update(0, message)) handler = RegexHandler('.*not in here.*', self.callback_basic) assert not handler.check_update(Update(0, message))
def test_pattern(self, message): handler = RegexHandler('.*est.*', self.callback_basic) assert handler.check_update(Update(0, message)) handler = RegexHandler('.*not in here.*', self.callback_basic) assert not handler.check_update(Update(0, message))
def test_multiple_flags(self, message): handler = RegexHandler('.*', 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))
def test_multiple_flags(self, message): handler = RegexHandler('.*', 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))
def test_allow_edited(self, message): with pytest.warns(UserWarning): handler = RegexHandler('.*', self.callback_basic, message_updates=True, allow_edited=True) 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_channel_post(self, message): handler = RegexHandler( '.*', 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_basic(self, dp, message): handler = RegexHandler('.*', 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_basic(self, dp, message): handler = RegexHandler('.*', 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 check_update(self, update): if RegexHandler.check_update(self, update): if not self.filters: res = True else: message = update.effective_message if isinstance(self.filters, list): res = any(func(message) for func in self.filters) else: res = self.filters(message) else: res = False return res
def test_other_update_types(self, false_update): handler = RegexHandler('.*', self.callback_basic, edited_updates=True) assert not handler.check_update(false_update)
def test_other_update_types(self, false_update): handler = RegexHandler('.*', self.callback_basic, edited_updates=True) assert not handler.check_update(false_update)
def test_handler_regex_back(self): rh = RegexHandler(HIGHLIGHTS_PATTERN, None) message = _Any() message.text = 'test #highlights' self.assertTrue(rh.check_update(Update(1234, message=message)))