From 3bf4399a4fabdfdb339b80b03addca21915792ae Mon Sep 17 00:00:00 2001 From: evgfilim1 Date: Tue, 20 Jun 2017 12:49:01 +0500 Subject: [PATCH] Fixed tests --- tests/test_filters.py | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) 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'