2023-10-07 10:22:37 +02:00
|
|
|
from zerver.lib.exceptions import JsonableError
|
|
|
|
from zerver.lib.recipient_parsing import extract_direct_message_recipient_ids, extract_stream_id
|
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
|
|
|
|
|
|
|
|
|
|
|
class TestRecipientParsing(ZulipTestCase):
|
|
|
|
def test_extract_stream_id(self) -> None:
|
|
|
|
# stream message recipient = single stream ID.
|
2024-08-18 14:16:43 +02:00
|
|
|
stream_id = extract_stream_id(1)
|
2023-10-07 10:22:37 +02:00
|
|
|
self.assertEqual(stream_id, 1)
|
|
|
|
|
2024-04-16 15:52:21 +02:00
|
|
|
with self.assertRaisesRegex(JsonableError, "Invalid data type for channel ID"):
|
2024-08-18 14:16:43 +02:00
|
|
|
extract_stream_id([1, 2])
|
2023-10-07 10:22:37 +02:00
|
|
|
|
2024-04-16 15:52:21 +02:00
|
|
|
with self.assertRaisesRegex(JsonableError, "Invalid data type for channel ID"):
|
2024-08-18 14:16:43 +02:00
|
|
|
extract_stream_id([1])
|
2023-10-07 10:22:37 +02:00
|
|
|
|
|
|
|
def test_extract_recipient_ids(self) -> None:
|
|
|
|
# direct message recipients = user IDs.
|
2024-08-18 14:16:43 +02:00
|
|
|
user_ids = [3, 2, 1]
|
2023-10-07 10:22:37 +02:00
|
|
|
result = sorted(extract_direct_message_recipient_ids(user_ids))
|
|
|
|
self.assertEqual(result, [1, 2, 3])
|
|
|
|
|
2024-08-18 14:16:43 +02:00
|
|
|
# list w/duplicates
|
|
|
|
user_ids = [3, 3, 12]
|
2023-10-07 10:22:37 +02:00
|
|
|
result = sorted(extract_direct_message_recipient_ids(user_ids))
|
|
|
|
self.assertEqual(result, [3, 12])
|
|
|
|
|
|
|
|
with self.assertRaisesRegex(JsonableError, "Invalid data type for recipients"):
|
2024-08-18 14:16:43 +02:00
|
|
|
extract_direct_message_recipient_ids(1)
|