From 7ab007d8d48f995cb1cf4a1372083ec81381b9b3 Mon Sep 17 00:00:00 2001 From: Jacob Bom Date: Tue, 13 Sep 2016 20:47:43 +0200 Subject: [PATCH] Add Filters.entities test. --- tests/test_filters.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/test_filters.py b/tests/test_filters.py index b023700af..9dadac440 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -23,10 +23,11 @@ This module contains a object that represents Tests for MessageHandler.Filters import sys import unittest from datetime import datetime +import functools sys.path.append('.') -from telegram import Message, User, Chat +from telegram import Message, User, Chat, MessageEntity from telegram.ext import Filters from tests.base import BaseTest @@ -150,6 +151,27 @@ class FiltersTest(BaseTest, unittest.TestCase): self.assertTrue(Filters.status_update(self.message)) self.message.pinned_message = None + def test_entities_filter(self): + e = functools.partial(MessageEntity, offset=0, length=0) + + self.message.entities = [e(MessageEntity.MENTION)] + self.assertTrue(Filters.entities([MessageEntity.MENTION])(self.message)) + + self.message.entities = [] + self.assertFalse(Filters.entities([MessageEntity.MENTION])(self.message)) + + self.message.entities = [e(MessageEntity.BOLD)] + self.assertFalse(Filters.entities([MessageEntity.MENTION])(self.message)) + + self.message.entities = [e(MessageEntity.MENTION)] + self.assertTrue( + Filters.entities([MessageEntity.MENTION, MessageEntity.BOLD])(self.message)) + self.message.entities = [e(MessageEntity.BOLD)] + self.assertTrue( + Filters.entities([MessageEntity.MENTION, MessageEntity.BOLD])(self.message)) + self.assertFalse( + Filters.entities([MessageEntity.MENTION, MessageEntity.TEXT_MENTION])(self.message)) + if __name__ == '__main__': unittest.main()