From e81942421e675be0da76e8078635815676feb23e Mon Sep 17 00:00:00 2001 From: novokrest Date: Fri, 4 May 2018 00:51:43 +0300 Subject: [PATCH] link_shortener: Print `help` when no links found. --- .../bots/link_shortener/link_shortener.py | 14 ++++++++------ .../bots/link_shortener/test_link_shortener.py | 11 +++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py b/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py index 250606f..243e552 100644 --- a/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py +++ b/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py @@ -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'] if content.strip() == 'help': bot_handler.send_reply( message, - ( - 'Mention the link shortener bot in a conversation and ' - 'then enter any URLs you want to shorten in the body of ' - 'the message.' - ) + HELP_STR ) return @@ -67,7 +69,7 @@ class LinkShortenerHandler(object): if final_response == '': bot_handler.send_reply( message, - 'No links found. Send "help" to see usage instructions.' + 'No links found. ' + HELP_STR ) return diff --git a/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py b/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py index 0073f74..0eb5d2c 100644 --- a/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py +++ b/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py @@ -13,7 +13,11 @@ class TestLinkShortenerBot(BotTestCase): def test_bot_responds_to_empty_message(self) -> None: 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: with self.mock_http_conversation('test_normal'): @@ -26,7 +30,10 @@ class TestLinkShortenerBot(BotTestCase): # requests. with patch('requests.get'): 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: # No `mock_http_conversation` is necessary because the bot will