message-send: Update translated errors for stream to channel rename.

In zerver/actions/message_send.py, updates translated error strings
to use channel instead of stream.

Also, updates the messages sent to bot owners when a stream doesn't
exist or has no subscribers.

Part of stream to channel rename project.
This commit is contained in:
Lauryn Menard 2024-04-16 17:58:08 +02:00 committed by Tim Abbott
parent acb54a8bc5
commit c1f1dc4b25
4 changed files with 16 additions and 16 deletions

View File

@ -1260,7 +1260,7 @@ def extract_stream_indicator(s: str) -> Union[str, int]:
# once we improve our documentation.
if isinstance(data, list):
if len(data) != 1: # nocoverage
raise JsonableError(_("Expected exactly one stream"))
raise JsonableError(_("Expected exactly one channel"))
data = data[0]
if isinstance(data, str):
@ -1271,7 +1271,7 @@ def extract_stream_indicator(s: str) -> Union[str, int]:
# We had a stream id.
return data
raise JsonableError(_("Invalid data type for stream"))
raise JsonableError(_("Invalid data type for channel"))
def extract_private_recipients(s: str) -> Union[List[str], List[int]]:
@ -1463,8 +1463,8 @@ def send_pm_if_empty_stream(
"channel_id": stream_id,
}
content = _(
"Your bot {bot_identity} tried to send a message to stream ID "
"{channel_id}, but there is no stream with that ID."
"Your bot {bot_identity} tried to send a message to channel ID "
"{channel_id}, but there is no channel with that ID."
).format(**arg_dict)
else:
assert stream_name is not None
@ -1474,8 +1474,8 @@ def send_pm_if_empty_stream(
"new_channel_link": "#streams/new",
}
content = _(
"Your bot {bot_identity} tried to send a message to stream "
"{channel_name}, but that stream does not exist. "
"Your bot {bot_identity} tried to send a message to channel "
"{channel_name}, but that channel does not exist. "
"Click [here]({new_channel_link}) to create it."
).format(**arg_dict)
else:
@ -1487,7 +1487,7 @@ def send_pm_if_empty_stream(
}
content = _(
"Your bot {bot_identity} tried to send a message to "
"stream {channel_name}. The stream exists but "
"channel {channel_name}. The channel exists but "
"does not have any subscribers."
).format(**arg_dict)

View File

@ -140,7 +140,7 @@ class MessagePOSTTest(ZulipTestCase):
msg = self.get_last_message()
expected = (
"Your bot `whatever-bot@zulip.testserver` tried to send a message to "
"stream ID 99999, but there is no stream with that ID."
"channel ID 99999, but there is no channel with that ID."
)
self.assertEqual(msg.content, expected)
@ -175,7 +175,7 @@ class MessagePOSTTest(ZulipTestCase):
msg = self.get_second_to_last_message()
expected = (
"Your bot `whatever-bot@zulip.testserver` tried to send a message to "
"stream #**Acropolis**. The stream exists but does not have any subscribers."
"channel #**Acropolis**. The channel exists but does not have any subscribers."
)
self.assertEqual(msg.content, expected)
@ -210,7 +210,7 @@ class MessagePOSTTest(ZulipTestCase):
msg = self.get_second_to_last_message()
expected = (
"Your bot `whatever-bot@zulip.testserver` tried to send a message to "
"stream #**Acropolis**. The stream exists but does not have any subscribers."
"channel #**Acropolis**. The channel exists but does not have any subscribers."
)
self.assertEqual(msg.content, expected)
@ -2428,13 +2428,13 @@ class ExtractTest(ZulipTestCase):
123,
)
with self.assertRaisesRegex(JsonableError, "Invalid data type for stream"):
with self.assertRaisesRegex(JsonableError, "Invalid data type for channel"):
extract_stream_indicator("{}")
with self.assertRaisesRegex(JsonableError, "Invalid data type for stream"):
with self.assertRaisesRegex(JsonableError, "Invalid data type for channel"):
extract_stream_indicator("[{}]")
with self.assertRaisesRegex(JsonableError, "Expected exactly one stream"):
with self.assertRaisesRegex(JsonableError, "Expected exactly one channel"):
extract_stream_indicator('[1,2,"general"]')
def test_extract_private_recipients_emails(self) -> None:
@ -3053,7 +3053,7 @@ class CheckMessageTest(ZulipTestCase):
new_count = message_stream_count(parent)
self.assertEqual(new_count, old_count + 1)
self.assertIn("that stream does not exist.", most_recent_message(parent).content)
self.assertIn("that channel 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.

View File

@ -635,7 +635,7 @@ class TestOutgoingWebhookMessaging(ZulipTestCase):
prev_message = self.get_second_to_last_message()
self.assertIn(
"tried to send a message to stream #**Denmark**, but that stream does not exist",
"tried to send a message to channel #**Denmark**, but that channel does not exist",
prev_message.content,
)

View File

@ -54,7 +54,7 @@ class HelloWorldHookTests(WebhookTestCase):
self.url = self.build_webhook_url()
realm = get_realm("zulip")
notification_bot = get_system_bot(settings.NOTIFICATION_BOT, realm.id)
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."
expected_message = "Your bot `webhook-bot@zulip.com` tried to send a message to channel #**nonexistent**, but that channel does not exist. Click [here](#streams/new) to create it."
self.send_and_test_private_message(
"goodbye",
expected_message=expected_message,