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.
This commit is contained in:
Steve Howell 2017-12-07 17:33:29 -08:00 committed by showell
parent c01fbe02e1
commit 011095018b

View file

@ -1,30 +1,20 @@
#!/usr/bin/env python #!/usr/bin/env python
from zulip_bots.test_lib import BotTestCase from zulip_bots.test_lib import StubBotTestCase
from typing import Any from typing import Any
class TestGoogleSearchBot(BotTestCase): class TestGoogleSearchBot(StubBotTestCase):
bot_name = 'googlesearch' bot_name = 'googlesearch'
# Simple query # Simple query
def test_normal(self: Any) -> None: def test_normal(self: Any) -> None:
with self.mock_http_conversation('test_normal'): 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: def test_bot_help(self: Any) -> None:
help_message = "To use this bot, start messages with @mentioned-bot, \ help_message = "To use this bot, start messages with @mentioned-bot, \
followed by what you want to search for. If \ followed by what you want to search for. If \
@ -34,8 +24,9 @@ class TestGoogleSearchBot(BotTestCase):
An example message that could be sent is:\ An example message that could be sent is:\
'@mentioned-bot zulip' or \ '@mentioned-bot zulip' or \
'@mentioned-bot how to create a chatbot'." '@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: def test_bot_no_results(self: Any) -> None:
with self.mock_http_conversation('test_no_result'): 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.')