mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-16 12:25:45 +01:00
improve unitest coverage
This commit is contained in:
parent
1c8bb21790
commit
5d168bd479
2 changed files with 23 additions and 1 deletions
|
@ -155,6 +155,20 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
def testInvalidToken3(self):
|
||||
self._test_invalid_token('12:')
|
||||
|
||||
def testUnauthToken(self):
|
||||
print('Testing unauthorized token')
|
||||
with self.assertRaisesRegexp(telegram.TelegramError, 'Unauthorized'):
|
||||
bot = telegram.Bot('1234:abcd1234')
|
||||
bot.getMe()
|
||||
|
||||
def testInvalidSrvResp(self):
|
||||
print('Testing invalid server response')
|
||||
with self.assertRaisesRegexp(telegram.TelegramError, 'Invalid server response'):
|
||||
# bypass the valid token check
|
||||
bot_cls = type('bot_cls', (telegram.Bot, ), {'_valid_token': lambda self, token: token})
|
||||
bot = bot_cls('12')
|
||||
bot.getMe()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -22,7 +22,6 @@ This module contains a object that represents Tests for Updater, Dispatcher,
|
|||
WebhookServer and WebhookHandler
|
||||
"""
|
||||
import logging
|
||||
import unittest
|
||||
import sys
|
||||
import re
|
||||
import os
|
||||
|
@ -31,6 +30,11 @@ from random import randrange
|
|||
from time import sleep
|
||||
from datetime import datetime
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from urllib2 import urlopen, Request
|
||||
except ImportError:
|
||||
|
@ -481,6 +485,9 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
sleep(1)
|
||||
self.updater.running = False
|
||||
|
||||
def test_createBot(self):
|
||||
updater = Updater('123:abcd')
|
||||
self.assertIsNotNone(updater.bot)
|
||||
|
||||
def test_mutualExclusiveTokenBot(self):
|
||||
bot = Bot('123:zyxw')
|
||||
|
@ -489,6 +496,7 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
def test_noTokenOrBot(self):
|
||||
self.assertRaises(ValueError, Updater)
|
||||
|
||||
|
||||
class MockBot:
|
||||
|
||||
def __init__(self, text, messages=1, raise_error=False):
|
||||
|
|
Loading…
Add table
Reference in a new issue