bots: Simplify test_define.py.

This commit is contained in:
Steve Howell 2017-12-07 19:44:38 -08:00 committed by showell
parent 2c42b0e42e
commit 7285affbc4

View file

@ -1,11 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import absolute_import from zulip_bots.test_lib import StubBotTestCase
from __future__ import print_function
from zulip_bots.test_lib import BotTestCase class TestDefineBot(StubBotTestCase):
class TestDefineBot(BotTestCase):
bot_name = "define" bot_name = "define"
def test_bot(self): def test_bot(self):
@ -16,11 +13,7 @@ class TestDefineBot(BotTestCase):
"kept as a pet or for catching mice, and many breeds have been " "kept as a pet or for catching mice, and many breeds have been "
"developed.\n  their pet cat\n\n") "developed.\n  their pet cat\n\n")
with self.mock_http_conversation('test_single_type_word'): with self.mock_http_conversation('test_single_type_word'):
self.assert_bot_response( self.verify_reply('cat', bot_response)
message = {'content': 'cat'},
response = {'content': bot_response},
expected_method='send_reply'
)
# Multi-type word. # Multi-type word.
bot_response = ("**help**:\n\n" bot_response = ("**help**:\n\n"
@ -35,41 +28,21 @@ class TestDefineBot(BotTestCase):
"* (**exclamation**) used as an appeal for urgent assistance.\n" "* (**exclamation**) used as an appeal for urgent assistance.\n"
"  Help! I'm drowning!\n\n") "  Help! I'm drowning!\n\n")
with self.mock_http_conversation('test_multi_type_word'): with self.mock_http_conversation('test_multi_type_word'):
self.assert_bot_response( self.verify_reply('help', bot_response)
message = {'content': 'help'},
response = {'content': bot_response},
expected_method='send_reply'
)
# Incorrect word. # Incorrect word.
bot_response = "**foo**:\nCould not load definition." bot_response = "**foo**:\nCould not load definition."
with self.mock_http_conversation('test_incorrect_word'): with self.mock_http_conversation('test_incorrect_word'):
self.assert_bot_response( self.verify_reply('foo', bot_response)
message = {'content': 'foo'},
response = {'content': bot_response},
expected_method='send_reply'
)
# Phrases are not defined. No request is sent to the Internet. # Phrases are not defined. No request is sent to the Internet.
bot_response = "Definitions for phrases are not available." bot_response = "Definitions for phrases are not available."
self.assert_bot_response( self.verify_reply('The sky is blue', bot_response)
message = {'content': 'The sky is blue'},
response = {'content': bot_response},
expected_method='send_reply'
)
# Symbols are considered invalid for words # Symbols are considered invalid for words
bot_response = "Definitions of words with symbols are not possible." bot_response = "Definitions of words with symbols are not possible."
self.assert_bot_response( self.verify_reply('#', bot_response)
message = {'content': '#'},
response = {'content': bot_response},
expected_method='send_reply'
)
# Empty messages are returned with a prompt to reply. No request is sent to the Internet. # Empty messages are returned with a prompt to reply. No request is sent to the Internet.
bot_response = "Please enter a word to define." bot_response = "Please enter a word to define."
self.assert_bot_response( self.verify_reply('', bot_response)
message = {'content': ''},
response = {'content': bot_response},
expected_method='send_reply'
)