From 011095018b1d1e60216c1eb0ea78aa309fdc9db2 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 7 Dec 2017 17:33:29 -0800 Subject: [PATCH] Simplify TestGoogleSearchBot. We use verify_reply() for all the tests and de-duplicate help_message by just having a single test validate both the '' and 'help' inputs. --- .../bots/googlesearch/test_googlesearch.py | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/googlesearch/test_googlesearch.py b/zulip_bots/zulip_bots/bots/googlesearch/test_googlesearch.py index e7cf711..020c7ee 100644 --- a/zulip_bots/zulip_bots/bots/googlesearch/test_googlesearch.py +++ b/zulip_bots/zulip_bots/bots/googlesearch/test_googlesearch.py @@ -1,30 +1,20 @@ #!/usr/bin/env python -from zulip_bots.test_lib import BotTestCase +from zulip_bots.test_lib import StubBotTestCase from typing import Any -class TestGoogleSearchBot(BotTestCase): +class TestGoogleSearchBot(StubBotTestCase): bot_name = 'googlesearch' # Simple query def test_normal(self: Any) -> None: with self.mock_http_conversation('test_normal'): - self.assert_bot_response({'content': 'zulip'}, {'content': 'Found Result: [Zulip](https://www.google.com/url?url=https%3A%2F%2Fzulipchat.com%2F)'}, 'send_reply') + self.verify_reply( + 'zulip', + 'Found Result: [Zulip](https://www.google.com/url?url=https%3A%2F%2Fzulipchat.com%2F)' + ) - # Help without typing anything - def test_bot_help_none(self: Any) -> None: - help_message = "To use this bot, start messages with @mentioned-bot, \ - followed by what you want to search for. If \ - found, Zulip will return the first search result \ - on Google.\ - \ - An example message that could be sent is:\ - '@mentioned-bot zulip' or \ - '@mentioned-bot how to create a chatbot'." - self.assert_bot_response({'content': ''}, {'content': help_message}, 'send_reply') - - # Help from typing 'help' def test_bot_help(self: Any) -> None: help_message = "To use this bot, start messages with @mentioned-bot, \ followed by what you want to search for. If \ @@ -34,8 +24,9 @@ class TestGoogleSearchBot(BotTestCase): An example message that could be sent is:\ '@mentioned-bot zulip' or \ '@mentioned-bot how to create a chatbot'." - self.assert_bot_response({'content': 'help'}, {'content': help_message}, 'send_reply') + self.verify_reply('', help_message) + self.verify_reply('help', help_message) def test_bot_no_results(self: Any) -> None: with self.mock_http_conversation('test_no_result'): - self.assert_bot_response({'content': 'no res'}, {'content': 'Found no results.'}, 'send_reply') + self.verify_reply('no res', 'Found no results.')