diff --git a/examples/eventhandler_bot.py b/examples/updater_bot.py similarity index 98% rename from examples/eventhandler_bot.py rename to examples/updater_bot.py index 63c5e70e7..e2a2193c3 100644 --- a/examples/eventhandler_bot.py +++ b/examples/updater_bot.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """ -This Bot uses the BotEventHandler class to handle the bot. +This Bot uses the Updater class to handle the bot. First, a few handler functions are defined. Then, those functions are passed to the Dispatcher and registered at their respective places. @@ -34,6 +34,7 @@ last_chat_id = 0 logger = logging.getLogger(__name__) + # Command Handlers def start(bot, update): """ Answer in Telegram """ @@ -151,4 +152,3 @@ def main(): if __name__ == '__main__': main() - diff --git a/examples/eventhandler_simplebot.py b/examples/updater_simplebot.py similarity index 95% rename from examples/eventhandler_simplebot.py rename to examples/updater_simplebot.py index b05ec9a88..150cba8ea 100644 --- a/examples/eventhandler_simplebot.py +++ b/examples/updater_simplebot.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """ -This Bot uses the BotEventHandler class to handle the bot. +This Bot uses the Updater class to handle the bot. First, a few handler functions are defined. Then, those functions are passed to the Dispatcher and registered at their respective places. @@ -15,7 +15,6 @@ Type 'stop' on the command line to stop the bot. from telegram import Updater import logging import sys -from time import sleep # Enable logging root = logging.getLogger() @@ -30,6 +29,7 @@ root.addHandler(ch) logger = logging.getLogger(__name__) + # Command Handlers def start(bot, update): bot.sendMessage(update.message.chat_id, text='Hi!') @@ -73,4 +73,3 @@ def main(): if __name__ == '__main__': main() - diff --git a/tests/test_boteventhandler.py b/tests/test_updater.py similarity index 97% rename from tests/test_boteventhandler.py rename to tests/test_updater.py index 68cbfac7f..f083a639a 100644 --- a/tests/test_boteventhandler.py +++ b/tests/test_updater.py @@ -17,7 +17,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. -""" This module contains a object that represents Tests for BotEventHandler """ +""" +This module contains a object that represents Tests for Updater, Dispatcher, +WebhookServer and WebhookHandler +""" import logging import unittest import sys @@ -51,8 +54,11 @@ ch.setFormatter(formatter) root.addHandler(ch) -class BotEventHandlerTest(BaseTest, unittest.TestCase): - """This object represents Tests for Telegram Bot.""" +class UpdaterTest(BaseTest, unittest.TestCase): + """ + This object represents Tests for Updater, Dispatcher, WebhookServer and + WebhookHandler + """ def setUp(self): self.updater = Updater('', workers=2) @@ -117,7 +123,6 @@ class BotEventHandlerTest(BaseTest, unittest.TestCase): sleep(.1) self.assertTrue(None is self.received_message) - def test_addTelegramMessageHandlerMultipleMessages(self): print('Testing addTelegramMessageHandler and send 100 messages...') self.updater.bot = MockBot('Multiple', 100) @@ -345,8 +350,8 @@ class BotEventHandlerTest(BaseTest, unittest.TestCase): # Select random port for travis port = randrange(1024, 49152) self.updater.start_webhook('127.0.0.1', port, - './tests/test_boteventhandler.py', - './tests/test_boteventhandler.py', + './tests/test_updater.py', + './tests/test_updater.py', listen='127.0.0.1') sleep(0.5) # SSL-Wrapping will fail, so we start the server without SSL @@ -396,7 +401,6 @@ class BotEventHandlerTest(BaseTest, unittest.TestCase): self.updater.httpd.shutdown() self.assertTrue(True) - def signalsender(self): sleep(0.5) os.kill(os.getpid(), signal.SIGTERM) @@ -412,7 +416,6 @@ class BotEventHandlerTest(BaseTest, unittest.TestCase): self.updater.running = False - class MockBot: def __init__(self, text, messages=1, raise_error=False): @@ -422,7 +425,8 @@ class MockBot: self.token = "TOKEN" pass - def mockUpdate(self, text): + @staticmethod + def mockUpdate(text): message = Message(0, None, None, None) message.text = text update = Update(0)