test_telegram.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:eddie 作者: greenkey 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号