diff --git a/tests/test_filters.py b/tests/test_filters.py index 674042de1..0911d0667 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -214,18 +214,43 @@ class FiltersTest(BaseTest, unittest.TestCase): self.assertTrue(Filters.group(self.message)) def test_filters_chat(self): - self.assertFalse(Filters.chat(-1)(self.message)) + with self.assertRaisesRegexp(ValueError, 'either chat_id or username'): + Filters.chat(chat_id=0, username='chat') + Filters.chat() + + def test_filters_chat_id(self): + self.assertFalse(Filters.chat(chat_id=-1)(self.message)) self.message.chat.id = -1 - self.assertTrue(Filters.chat(-1)(self.message)) + self.assertTrue(Filters.chat(chat_id=-1)(self.message)) self.message.chat.id = -2 - self.assertFalse(Filters.chat(-1)(self.message)) + self.assertFalse(Filters.chat(chat_id=-1)(self.message)) + + def test_filters_chat_username(self): + self.assertFalse(Filters.chat(username='chat')(self.message)) + self.message.chat.username = 'chat' + self.assertTrue(Filters.chat(username='@chat')(self.message)) + self.assertTrue(Filters.chat(username='chat')(self.message)) + self.assertFalse(Filters.chat(username='@chat_username')(self.message)) def test_filters_user(self): - self.assertFalse(Filters.user(1)(self.message)) + with self.assertRaisesRegexp(ValueError, 'either user_id or username'): + Filters.user(user_id=0, username='user') + Filters.user() + + def test_filters_user_id(self): + self.assertFalse(Filters.user(user_id=1)(self.message)) self.message.from_user.id = 1 - self.assertTrue(Filters.user(1)(self.message)) + self.assertTrue(Filters.user(user_id=1)(self.message)) self.message.from_user.id = 2 - self.assertFalse(Filters.user(1)(self.message)) + self.assertFalse(Filters.user(user_id=1)(self.message)) + + def test_filters_username(self): + self.assertFalse(Filters.user(username='user')(self.message)) + self.assertFalse(Filters.user(username='Testuser')(self.message)) + self.message.from_user.username = 'user' + self.assertTrue(Filters.user(username='@user')(self.message)) + self.assertTrue(Filters.user(username='user')(self.message)) + self.assertFalse(Filters.user(username='@username')(self.message)) def test_and_filters(self): self.message.text = 'test'