notification bot: Update error messages in send_pm_if_empty_stream.

This commit is contained in:
Rishi Gupta 2019-07-10 16:22:32 -07:00 committed by Tim Abbott
parent b92f936dad
commit 628d9ad67d
3 changed files with 14 additions and 21 deletions

View File

@ -2121,23 +2121,18 @@ def send_pm_if_empty_stream(sender: UserProfile,
return
if stream is None:
error_msg = "that stream does not yet exist. To create it, "
if stream_id is not None:
content = _("Your bot `%s` tried to send a message to stream ID %s, but there "
"is no stream with that ID." % (sender.delivery_email, stream_id))
else:
content = _("Your bot `%s` tried to send a message to stream #**%s**, but that "
"stream does not exist. Click [here](#streams/new) to create it.") % (
sender.delivery_email, stream_name)
else:
if num_subscribers_for_stream_id(stream.id) > 0:
return
error_msg = "there are no subscribers to that stream. To join it, "
if stream_id is not None:
stream_info = "with ID {stream_id}".format(stream_id=stream_id)
else:
stream_info = "`{stream_name}`".format(stream_name=stream_name)
content = ("Hi there! We thought you'd like to know that your bot **{sender}** just "
"tried to send a message to stream {stream_info}, but {error_msg}"
"click the gear in the left-side stream list.")
content = content.format(sender=sender.full_name,
stream_info=stream_info,
error_msg=error_msg)
content = _("Your bot `%s` tried to send a message to stream #**%s**. The stream exists but "
"does not have any subscribers.") % (sender.delivery_email, stream.name)
send_rate_limited_pm_notification_to_bot_owner(sender, realm, content)

View File

@ -1399,10 +1399,8 @@ class MessagePOSTTest(ZulipTestCase):
self.assert_json_error(result, "Stream with ID '99999' does not exist")
msg = self.get_last_message()
expected = ("Hi there! We thought you'd like to know that your bot **{sender}** just "
"tried to send a message to stream {stream_info}, but that stream does not "
"yet exist. To create it, click the gear in the left-side stream list.")
expected = expected.format(sender=bot.full_name, stream_info='with ID 99999')
expected = ("Your bot `whatever-bot@zulip.testserver` tried to send a message to "
"stream ID 99999, but there is no stream with that ID.")
self.assertEqual(msg.content, expected)
def test_message_to_stream_by_id(self) -> None:
@ -3636,7 +3634,7 @@ class CheckMessageTest(ZulipTestCase):
new_count = message_stream_count(parent)
self.assertEqual(new_count, old_count + 1)
self.assertIn("that stream does not yet exist.", most_recent_message(parent).content)
self.assertIn("that stream does not exist.", most_recent_message(parent).content)
# Try sending to stream that exists with no subscribers soon
# after; due to rate-limiting, this should send nothing.
@ -3656,7 +3654,7 @@ class CheckMessageTest(ZulipTestCase):
new_count = message_stream_count(parent)
self.assertEqual(new_count, old_count + 2)
self.assertEqual(ret['message'].sender.email, 'othello-bot@zulip.com')
self.assertIn("there are no subscribers to that stream", most_recent_message(parent).content)
self.assertIn("does not have any subscribers", most_recent_message(parent).content)
def test_bot_pm_error_handling(self) -> None:
# This just test some defensive code.

View File

@ -41,7 +41,7 @@ class HelloWorldHookTests(WebhookTestCase):
self.STREAM_NAME = 'nonexistent'
self.url = self.build_webhook_url()
notification_bot = get_system_bot(settings.NOTIFICATION_BOT)
expected_message = "Hi there! We thought you'd like to know that your bot **Zulip Webhook Bot** just tried to send a message to stream `nonexistent`, but that stream does not yet exist. To create it, click the gear in the left-side stream list."
expected_message = "Your bot `webhook-bot@zulip.com` tried to send a message to stream #**nonexistent**, but that stream does not exist. Click [here](#streams/new) to create it."
self.send_and_test_private_message('goodbye', expected_message=expected_message,
content_type='application/x-www-form-urlencoded',
sender=notification_bot)