bots: Simplify test_link_shortener.py.

This commit is contained in:
neiljp (Neil Pilgrim) 2017-12-10 13:28:18 -08:00
parent f8cefc5352
commit c8824cb2e5

View file

@ -1,55 +1,34 @@
#!/usr/bin/env python from zulip_bots.test_lib import StubBotTestCase
from zulip_bots.test_lib import BotTestCase class TestLinkShortenerBot(StubBotTestCase):
class TestLinkShortenerBot(BotTestCase):
bot_name = "link_shortener" bot_name = "link_shortener"
def _test(self, message, response):
with self.mock_config_info({'key': 'qwertyuiop'}):
self.verify_reply(message, response)
def test_bot(self): def test_bot(self):
MESSAGE = 'Shorten https://www.github.com/zulip/zulip please.' message = 'Shorten https://www.github.com/zulip/zulip please.'
RESPONSE = 'https://www.github.com/zulip/zulip: https://goo.gl/6uoWKb' response = 'https://www.github.com/zulip/zulip: https://goo.gl/6uoWKb'
with self.mock_config_info({'key': 'qwertyuiop'}), \ with self.mock_http_conversation('test_normal'):
self.mock_http_conversation('test_normal'): self._test(message, response)
self.initialize_bot()
self.assert_bot_response(
message = {'content': MESSAGE},
response = {'content': RESPONSE},
expected_method='send_reply'
)
def test_bot_empty(self): def test_bot_empty(self):
MESSAGE = 'Shorten nothing please.' message = 'Shorten nothing please.'
RESPONSE = 'No links found. Send "help" to see usage instructions.' response = 'No links found. Send "help" to see usage instructions.'
# No `mock_http_conversation` is necessary because the bot will # No `mock_http_conversation` is necessary because the bot will
# recognize that no links are in the message and won't make any HTTP # recognize that no links are in the message and won't make any HTTP
# requests. # requests.
with self.mock_config_info({'key': 'qwertyuiop'}): self._test(message, response)
self.initialize_bot()
self.assert_bot_response(
message = {'content': MESSAGE},
response = {'content': RESPONSE},
expected_method='send_reply'
)
def test_bot_help(self): def test_bot_help(self):
MESSAGE = 'help' message = 'help'
RESPONSE = ( response = ('Mention the link shortener bot in a conversation and then '
'Mention the link shortener bot in a conversation and then enter ' 'enter any URLs you want to shorten in the body of the message.')
'any URLs you want to shorten in the body of the message.'
)
# No `mock_http_conversation` is necessary because the bot will # No `mock_http_conversation` is necessary because the bot will
# recognize that the message is 'help' and won't make any HTTP # recognize that the message is 'help' and won't make any HTTP
# requests. # requests.
with self.mock_config_info({'key': 'qwertyuiop'}): self._test(message, response)
self.initialize_bot()
self.assert_bot_response(
message = {'content': MESSAGE},
response = {'content': RESPONSE},
expected_method='send_reply'
)