def test_telegram_default_response(mocker):
""" Test that the Telegram bot correctly reply with the default response.
"""
mocker.patch('eddie.endpoints.telegram.Updater')
mock_messagehandler = mocker.patch(
'eddie.endpoints.telegram.MessageHandler')
reply_text_m = mocker.patch('telegram.Message.reply_text')
class MyBot(Bot):
"Uppering-reversing bot"
def default_response(self, in_message):
return in_message[::-1].upper()
bot = MyBot()
endpoint = TelegramEndpoint(
token='123:ABC'
)
bot.add_endpoint(endpoint)
bot.run()
handlers_added = [args for args,
kwargs in mock_messagehandler.call_args_list]
assert len(handlers_added) > 0
generic_handler = list(handler for filter_, handler in handlers_added)[-1]
message = 'this is the message'
generic_handler(bot, create_telegram_update(message))
reply_text_m.assert_called_with(
bot.default_response(message))
bot.stop()
评论列表
文章目录