link_shortener: Print help when no links found.

This commit is contained in:
novokrest 2018-05-04 00:51:43 +03:00 committed by Rohitt Vashishtha
parent 3db070b99e
commit e81942421e
2 changed files with 17 additions and 8 deletions

View file

@ -40,16 +40,18 @@ class LinkShortenerHandler(object):
')' ')'
) )
HELP_STR = (
'Mention the link shortener bot in a conversation and '
'then enter any URLs you want to shorten in the body of '
'the message.'
)
content = message['content'] content = message['content']
if content.strip() == 'help': if content.strip() == 'help':
bot_handler.send_reply( bot_handler.send_reply(
message, message,
( HELP_STR
'Mention the link shortener bot in a conversation and '
'then enter any URLs you want to shorten in the body of '
'the message.'
)
) )
return return
@ -67,7 +69,7 @@ class LinkShortenerHandler(object):
if final_response == '': if final_response == '':
bot_handler.send_reply( bot_handler.send_reply(
message, message,
'No links found. Send "help" to see usage instructions.' 'No links found. ' + HELP_STR
) )
return return

View file

@ -13,7 +13,11 @@ class TestLinkShortenerBot(BotTestCase):
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with patch('requests.get'): with patch('requests.get'):
self._test('', 'No links found. Send "help" to see usage instructions.') self._test('',
('No links found. '
'Mention the link shortener bot in a conversation and '
'then enter any URLs you want to shorten in the body of '
'the message.'))
def test_normal(self) -> None: def test_normal(self) -> None:
with self.mock_http_conversation('test_normal'): with self.mock_http_conversation('test_normal'):
@ -26,7 +30,10 @@ class TestLinkShortenerBot(BotTestCase):
# requests. # requests.
with patch('requests.get'): with patch('requests.get'):
self._test('Shorten nothing please.', self._test('Shorten nothing please.',
'No links found. Send "help" to see usage instructions.') ('No links found. '
'Mention the link shortener bot in a conversation and '
'then enter any URLs you want to shorten in the body of '
'the message.'))
def test_help(self) -> None: def test_help(self) -> None:
# No `mock_http_conversation` is necessary because the bot will # No `mock_http_conversation` is necessary because the bot will