mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-22 23:27:49 +01:00
Fixed tests
This commit is contained in:
parent
9bccbdab2a
commit
3bf4399a4f
1 changed files with 31 additions and 6 deletions
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue