Simplify test_wikipedia.py.
We now use StubBotTestCase.verify_reply().
This commit is contained in:
parent
16e50e991b
commit
fab9d46f93
|
@ -1,64 +1,43 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
from zulip_bots.test_lib import StubBotTestCase
|
||||
|
||||
from zulip_bots.test_lib import BotTestCase
|
||||
|
||||
class TestWikipediaBot(BotTestCase):
|
||||
class TestWikipediaBot(StubBotTestCase):
|
||||
bot_name = "wikipedia"
|
||||
|
||||
def test_bot(self):
|
||||
|
||||
# Single-word query
|
||||
bot_request = 'happy'
|
||||
bot_response = "For search term \"happy\", https://en.wikipedia.org/wiki/Happiness"
|
||||
with self.mock_http_conversation('test_single_word'):
|
||||
self.assert_bot_response(
|
||||
message = {'content': 'happy'},
|
||||
response = {'content': bot_response},
|
||||
expected_method='send_reply'
|
||||
)
|
||||
self.verify_reply(bot_request, bot_response)
|
||||
|
||||
# Multi-word query
|
||||
bot_request = 'The sky is blue'
|
||||
bot_response = "For search term \"The sky is blue\", https://en.wikipedia.org/wiki/Sky_blue"
|
||||
with self.mock_http_conversation('test_multi_word'):
|
||||
self.assert_bot_response(
|
||||
message = {'content': 'The sky is blue'},
|
||||
response = {'content': bot_response},
|
||||
expected_method='send_reply'
|
||||
)
|
||||
self.verify_reply(bot_request, bot_response)
|
||||
|
||||
# Number query
|
||||
bot_request = '123'
|
||||
bot_response = "For search term \"123\", https://en.wikipedia.org/wiki/123"
|
||||
with self.mock_http_conversation('test_number_query'):
|
||||
self.assert_bot_response(
|
||||
message = {'content': '123'},
|
||||
response = {'content': bot_response},
|
||||
expected_method='send_reply'
|
||||
)
|
||||
self.verify_reply(bot_request, bot_response)
|
||||
|
||||
# Hash query
|
||||
bot_request = '#'
|
||||
bot_response = "For search term \"#\", https://en.wikipedia.org/wiki/Number_sign"
|
||||
with self.mock_http_conversation('test_hash_query'):
|
||||
self.assert_bot_response(
|
||||
message = {'content': '#'},
|
||||
response = {'content': bot_response},
|
||||
expected_method='send_reply'
|
||||
)
|
||||
self.verify_reply(bot_request, bot_response)
|
||||
|
||||
# Incorrect word
|
||||
bot_request = 'sssssss kkkkk'
|
||||
bot_response = "I am sorry. The search term you provided is not found :slightly_frowning_face:"
|
||||
with self.mock_http_conversation('test_incorrect_query'):
|
||||
self.assert_bot_response(
|
||||
message = {'content': 'sssssss kkkkk'},
|
||||
response = {'content': bot_response},
|
||||
expected_method='send_reply'
|
||||
)
|
||||
self.verify_reply(bot_request, bot_response)
|
||||
|
||||
# Empty query, no request made to the Internet.
|
||||
bot_request = ''
|
||||
bot_response = "Please enter your message after @mention-bot"
|
||||
self.assert_bot_response(
|
||||
message = {'content': ''},
|
||||
response = {'content': bot_response},
|
||||
expected_method='send_reply'
|
||||
)
|
||||
self.verify_reply(bot_request, bot_response)
|
||||
|
|
Loading…
Reference in a new issue