tests: Move TestAddressee to test_message_send.py.

This commit is contained in:
Mohit Gupta
2020-07-08 03:17:32 +05:30
committed by Tim Abbott
parent 329265b1bf
commit 228fb9f80d
2 changed files with 56 additions and 56 deletions

View File

@@ -28,6 +28,7 @@ from zerver.lib.actions import (
internal_send_stream_message, internal_send_stream_message,
internal_send_stream_message_by_name, internal_send_stream_message_by_name,
) )
from zerver.lib.addressee import Addressee
from zerver.lib.cache import cache_delete, get_stream_cache_key from zerver.lib.cache import cache_delete, get_stream_cache_key
from zerver.lib.message import MessageDict, get_raw_unread_data, get_recent_private_conversations from zerver.lib.message import MessageDict, get_raw_unread_data, get_recent_private_conversations
from zerver.lib.test_classes import ZulipTestCase from zerver.lib.test_classes import ZulipTestCase
@@ -1822,3 +1823,58 @@ class TestCrossRealmPMs(ZulipTestCase):
# Users on three different realms cannot PM each other # Users on three different realms cannot PM each other
with assert_invalid_user(): with assert_invalid_user():
self.send_huddle_message(user1, [user2, user3]) self.send_huddle_message(user1, [user2, user3])
class TestAddressee(ZulipTestCase):
def test_addressee_for_user_ids(self) -> None:
realm = get_realm('zulip')
user_ids = [self.example_user('cordelia').id,
self.example_user('hamlet').id,
self.example_user('othello').id]
result = Addressee.for_user_ids(user_ids=user_ids, realm=realm)
user_profiles = result.user_profiles()
result_user_ids = [user_profiles[0].id, user_profiles[1].id,
user_profiles[2].id]
self.assertEqual(set(result_user_ids), set(user_ids))
def test_addressee_for_user_ids_nonexistent_id(self) -> None:
def assert_invalid_user_id() -> Any:
return self.assertRaisesRegex(
JsonableError,
'Invalid user ID ')
with assert_invalid_user_id():
Addressee.for_user_ids(user_ids=[779], realm=get_realm('zulip'))
def test_addressee_legacy_build_for_user_ids(self) -> None:
realm = get_realm('zulip')
self.login('hamlet')
user_ids = [self.example_user('cordelia').id,
self.example_user('othello').id]
result = Addressee.legacy_build(
sender=self.example_user('hamlet'), message_type_name='private',
message_to=user_ids, topic_name='random_topic',
realm=realm,
)
user_profiles = result.user_profiles()
result_user_ids = [user_profiles[0].id, user_profiles[1].id]
self.assertEqual(set(result_user_ids), set(user_ids))
def test_addressee_legacy_build_for_stream_id(self) -> None:
realm = get_realm('zulip')
self.login('iago')
sender = self.example_user('iago')
self.subscribe(sender, "Denmark")
stream = get_stream('Denmark', realm)
result = Addressee.legacy_build(
sender=sender, message_type_name='stream',
message_to=[stream.id], topic_name='random_topic',
realm=realm,
)
stream_id = result.stream_id()
self.assertEqual(stream.id, stream_id)

View File

@@ -53,7 +53,6 @@ from zerver.models import (
bulk_get_huddle_user_ids, bulk_get_huddle_user_ids,
get_huddle_user_ids, get_huddle_user_ids,
get_realm, get_realm,
get_stream,
) )
@@ -68,61 +67,6 @@ class MiscMessageTest(ZulipTestCase):
self.assertEqual(get_last_message_id(), -1) self.assertEqual(get_last_message_id(), -1)
class TestAddressee(ZulipTestCase):
def test_addressee_for_user_ids(self) -> None:
realm = get_realm('zulip')
user_ids = [self.example_user('cordelia').id,
self.example_user('hamlet').id,
self.example_user('othello').id]
result = Addressee.for_user_ids(user_ids=user_ids, realm=realm)
user_profiles = result.user_profiles()
result_user_ids = [user_profiles[0].id, user_profiles[1].id,
user_profiles[2].id]
self.assertEqual(set(result_user_ids), set(user_ids))
def test_addressee_for_user_ids_nonexistent_id(self) -> None:
def assert_invalid_user_id() -> Any:
return self.assertRaisesRegex(
JsonableError,
'Invalid user ID ')
with assert_invalid_user_id():
Addressee.for_user_ids(user_ids=[779], realm=get_realm('zulip'))
def test_addressee_legacy_build_for_user_ids(self) -> None:
realm = get_realm('zulip')
self.login('hamlet')
user_ids = [self.example_user('cordelia').id,
self.example_user('othello').id]
result = Addressee.legacy_build(
sender=self.example_user('hamlet'), message_type_name='private',
message_to=user_ids, topic_name='random_topic',
realm=realm,
)
user_profiles = result.user_profiles()
result_user_ids = [user_profiles[0].id, user_profiles[1].id]
self.assertEqual(set(result_user_ids), set(user_ids))
def test_addressee_legacy_build_for_stream_id(self) -> None:
realm = get_realm('zulip')
self.login('iago')
sender = self.example_user('iago')
self.subscribe(sender, "Denmark")
stream = get_stream('Denmark', realm)
result = Addressee.legacy_build(
sender=sender, message_type_name='stream',
message_to=[stream.id], topic_name='random_topic',
realm=realm,
)
stream_id = result.stream_id()
self.assertEqual(stream.id, stream_id)
class PersonalMessagesTest(ZulipTestCase): class PersonalMessagesTest(ZulipTestCase):
def test_near_pm_message_url(self) -> None: def test_near_pm_message_url(self) -> None: