From 142cc6e6ada0279853882a09e023289d553e78c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannes=20H=C3=B6ke?= Date: Fri, 29 Jan 2016 23:54:07 +0100 Subject: [PATCH] add test for dispatching inline queries/results --- tests/test_updater.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/test_updater.py b/tests/test_updater.py index 3c1472a43..4a3e89f09 100644 --- a/tests/test_updater.py +++ b/tests/test_updater.py @@ -87,6 +87,11 @@ class UpdaterTest(BaseTest, unittest.TestCase): self.received_message = update.message.text self.message_count += 1 + def telegramInlineHandlerTest(self, bot, update): + self.received_message = (update.inline_query, + update.chosen_inline_result) + self.message_count += 1 + @run_async def asyncHandlerTest(self, bot, update, **kwargs): sleep(1) @@ -294,8 +299,7 @@ class UpdaterTest(BaseTest, unittest.TestCase): print('Testing error in Handler') self._setup_updater('', messages=0) d = self.updater.dispatcher - d.addStringRegexHandler('.*', - self.errorRaisingHandlerTest) + d.addStringRegexHandler('.*', self.errorRaisingHandlerTest) self.updater.dispatcher.addErrorHandler(self.errorHandlerTest) queue = self.updater.start_polling(0.01) @@ -331,6 +335,30 @@ class UpdaterTest(BaseTest, unittest.TestCase): sleep(.1) self.assertTrue(None is self.received_message) + def test_addRemoveInlineHandlerQuery(self): + print('Testing add/removeInlineHandler') + self._setup_updater('', messages=0) + d = self.updater.dispatcher + d.addTelegramInlineHandler(self.telegramInlineHandlerTest) + queue = self.updater.start_polling(0.01) + update = Update(update_id=0, inline_query="testquery") + update2 = Update(update_id=0, chosen_inline_result="testresult") + queue.put(update) + sleep(.1) + self.assertEqual(self.received_message[0], "testquery") + + queue.put(update2) + sleep(.1) + self.assertEqual(self.received_message[1], "testresult") + + # Remove handler + d.removeTelegramInlineHandler(self.telegramInlineHandlerTest) + self.reset() + + queue.put(update) + sleep(.1) + self.assertTrue(None is self.received_message) + def test_runAsync(self): print('Testing @run_async') self._setup_updater('Test5', messages=2) @@ -503,7 +531,7 @@ class UpdaterTest(BaseTest, unittest.TestCase): self.updater.idle() # If we get this far, idle() ran through sleep(1) - self.updater.running = False + self.assertFalse(self.updater.running) def test_createBot(self): updater = Updater('123:abcd')