def test_help(self):
# this tests the help handler. So first insert the handler
def help(bot, update):
update.message.reply_text('Help!')
# Then register the handler with he updater's dispatcher and start polling
self.updater.dispatcher.add_handler(CommandHandler("help", help))
self.updater.start_polling()
# We want to simulate a message. Since we don't care wich user sends it we let the MessageGenerator
# create random ones
update = self.mg.get_message(text="/help")
# We insert the update with the bot so the updater can retrieve it.
self.bot.insertUpdate(update)
# sent_messages is the list with calls to the bot's outbound actions. Since we hope the message we inserted
# only triggered one sendMessage action it's length should be 1.
self.assertEqual(len(self.bot.sent_messages), 1)
sent = self.bot.sent_messages[0]
self.assertEqual(sent['method'], "sendMessage")
self.assertEqual(sent['text'], "Help!")
# Always stop the updater at the end of a testcase so it won't hang.
self.updater.stop()
评论列表
文章目录