mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-02-16 18:31:45 +01:00
update tests
This commit is contained in:
parent
c1f194a310
commit
0006294f29
1 changed files with 14 additions and 3 deletions
|
@ -28,7 +28,7 @@ import re
|
||||||
sys.path.append('.')
|
sys.path.append('.')
|
||||||
|
|
||||||
from telegram import Update, Message, TelegramError
|
from telegram import Update, Message, TelegramError
|
||||||
from tests.base import BaseTest
|
from base import BaseTest
|
||||||
|
|
||||||
|
|
||||||
class BotEventHandlerTest(BaseTest, unittest.TestCase):
|
class BotEventHandlerTest(BaseTest, unittest.TestCase):
|
||||||
|
@ -41,6 +41,9 @@ class BotEventHandlerTest(BaseTest, unittest.TestCase):
|
||||||
self.received_message = None
|
self.received_message = None
|
||||||
self.message_count = 0
|
self.message_count = 0
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.beh.stop()
|
||||||
|
|
||||||
def telegramHandlerTest(self, bot, update):
|
def telegramHandlerTest(self, bot, update):
|
||||||
self.received_message = update.message.text
|
self.received_message = update.message.text
|
||||||
self.message_count += 1
|
self.message_count += 1
|
||||||
|
@ -49,6 +52,10 @@ class BotEventHandlerTest(BaseTest, unittest.TestCase):
|
||||||
self.received_message = update
|
self.received_message = update
|
||||||
self.message_count += 1
|
self.message_count += 1
|
||||||
|
|
||||||
|
def errorHandlerTest(self, bot, update, error):
|
||||||
|
self.received_message = error
|
||||||
|
self.message_count += 1
|
||||||
|
|
||||||
def test_addTelegramMessageHandler(self):
|
def test_addTelegramMessageHandler(self):
|
||||||
print('Testing addTelegramMessageHandler')
|
print('Testing addTelegramMessageHandler')
|
||||||
self.beh.bot = MockBot('Test')
|
self.beh.bot = MockBot('Test')
|
||||||
|
@ -129,7 +136,7 @@ class BotEventHandlerTest(BaseTest, unittest.TestCase):
|
||||||
def test_addErrorHandler(self):
|
def test_addErrorHandler(self):
|
||||||
print('Testing addErrorHandler')
|
print('Testing addErrorHandler')
|
||||||
self.beh.bot = MockBot('')
|
self.beh.bot = MockBot('')
|
||||||
self.beh.broadcaster.addErrorHandler(self.stringHandlerTest)
|
self.beh.broadcaster.addErrorHandler(self.errorHandlerTest)
|
||||||
queue = self.beh.start_polling(0.05)
|
queue = self.beh.start_polling(0.05)
|
||||||
error = TelegramError("Unauthorized.")
|
error = TelegramError("Unauthorized.")
|
||||||
queue.put(error)
|
queue.put(error)
|
||||||
|
@ -160,7 +167,11 @@ class MockBot:
|
||||||
update.message = message
|
update.message = message
|
||||||
return update
|
return update
|
||||||
|
|
||||||
def getUpdates(self, offset):
|
def getUpdates(self,
|
||||||
|
offset=None,
|
||||||
|
limit=100,
|
||||||
|
timeout=0,
|
||||||
|
network_delay=2.):
|
||||||
|
|
||||||
if self.send_messages >= 2:
|
if self.send_messages >= 2:
|
||||||
self.send_messages -= 2
|
self.send_messages -= 2
|
||||||
|
|
Loading…
Add table
Reference in a new issue