mirror of https://github.com/zulip/zulip.git
tests: Add and use new self.subscribe.
This new method cleans up the API for subscribing to something from a test case.
This commit is contained in:
parent
4069b166ea
commit
eb720485c5
|
@ -495,6 +495,17 @@ class ZulipTestCase(TestCase):
|
|||
bulk_add_subscriptions([stream], [user_profile], from_stream_creation=from_stream_creation)
|
||||
return stream
|
||||
|
||||
# Subscribe to a stream directly
|
||||
def subscribe(self, user_profile, stream_name):
|
||||
# type: (UserProfile, Text) -> Stream
|
||||
try:
|
||||
stream = get_stream(stream_name, user_profile.realm)
|
||||
from_stream_creation = False
|
||||
except Stream.DoesNotExist:
|
||||
stream, from_stream_creation = create_stream_if_needed(user_profile.realm, stream_name)
|
||||
bulk_add_subscriptions([stream], [user_profile], from_stream_creation=from_stream_creation)
|
||||
return stream
|
||||
|
||||
def unsubscribe_from_stream(self, email, stream_name, realm):
|
||||
# type: (Text, Text, Realm) -> None
|
||||
user_profile = get_user(email, realm)
|
||||
|
|
|
@ -260,7 +260,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
|
|||
self.login(self.example_email('hamlet'))
|
||||
user_profile = self.example_user('hamlet')
|
||||
stream = get_stream("Denmark", user_profile.realm)
|
||||
self.subscribe_to_stream(user_profile.email, stream.name)
|
||||
self.subscribe(user_profile, stream.name)
|
||||
do_change_stream_invite_only(stream, True)
|
||||
|
||||
self.assert_num_bots_equal(0)
|
||||
|
@ -330,7 +330,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
|
|||
# type: () -> None
|
||||
self.login(self.example_email('hamlet'))
|
||||
user_profile = self.example_user('hamlet')
|
||||
stream = self.subscribe_to_stream(user_profile.email, 'Denmark')
|
||||
stream = self.subscribe(user_profile, 'Denmark')
|
||||
do_change_stream_invite_only(stream, True)
|
||||
|
||||
self.assert_num_bots_equal(0)
|
||||
|
@ -682,7 +682,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
|
|||
# type: () -> None
|
||||
self.login(self.example_email('hamlet'))
|
||||
user_profile = self.example_user('hamlet')
|
||||
stream = self.subscribe_to_stream(user_profile.email, "Denmark")
|
||||
stream = self.subscribe(user_profile, "Denmark")
|
||||
do_change_stream_invite_only(stream, True)
|
||||
|
||||
bot_info = {
|
||||
|
@ -763,7 +763,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
|
|||
# type: () -> None
|
||||
self.login(self.example_email('hamlet'))
|
||||
user_profile = self.example_user('hamlet')
|
||||
stream = self.subscribe_to_stream(user_profile.email, "Denmark")
|
||||
stream = self.subscribe(user_profile, "Denmark")
|
||||
do_change_stream_invite_only(stream, True)
|
||||
|
||||
bot_info = {
|
||||
|
|
|
@ -89,7 +89,7 @@ class TestStreamEmailMessagesSuccess(ZulipTestCase):
|
|||
# test valid incoming stream message is processed properly
|
||||
user_profile = self.example_user('hamlet')
|
||||
self.login(user_profile.email)
|
||||
self.subscribe_to_stream(user_profile.email, "Denmark")
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
stream = get_stream("Denmark", user_profile.realm)
|
||||
|
||||
stream_to_address = encode_email_address(stream)
|
||||
|
@ -118,7 +118,7 @@ class TestStreamEmailMessagesEmptyBody(ZulipTestCase):
|
|||
# test message with empty body is not sent
|
||||
user_profile = self.example_user('hamlet')
|
||||
self.login(user_profile.email)
|
||||
self.subscribe_to_stream(user_profile.email, "Denmark")
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
stream = get_stream("Denmark", user_profile.realm)
|
||||
|
||||
stream_to_address = encode_email_address(stream)
|
||||
|
@ -296,7 +296,7 @@ class TestReplyExtraction(ZulipTestCase):
|
|||
email = self.example_email('hamlet')
|
||||
self.login(email)
|
||||
user_profile = self.example_user('hamlet')
|
||||
self.subscribe_to_stream(user_profile.email, "Denmark")
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
stream = get_stream("Denmark", user_profile.realm)
|
||||
|
||||
stream_to_address = encode_email_address(stream)
|
||||
|
@ -328,7 +328,7 @@ class TestReplyExtraction(ZulipTestCase):
|
|||
email = self.example_email('hamlet')
|
||||
self.login(email)
|
||||
user_profile = self.example_user('hamlet')
|
||||
self.subscribe_to_stream(user_profile.email, "Denmark")
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
stream = get_stream("Denmark", user_profile.realm)
|
||||
|
||||
stream_to_address = encode_email_address(stream)
|
||||
|
|
|
@ -1394,7 +1394,7 @@ class EventsRegisterTest(ZulipTestCase):
|
|||
# type: () -> None
|
||||
stream = self.make_stream('old_name')
|
||||
new_name = u'stream with a brand new name'
|
||||
self.subscribe_to_stream(self.user_profile.email, stream.name)
|
||||
self.subscribe(self.user_profile, stream.name)
|
||||
|
||||
action = lambda: do_rename_stream(stream, new_name)
|
||||
events = self.do_test(action, num_events=2)
|
||||
|
@ -1437,7 +1437,7 @@ class EventsRegisterTest(ZulipTestCase):
|
|||
|
||||
def test_subscribe_other_user_never_subscribed(self):
|
||||
# type: () -> None
|
||||
action = lambda: self.subscribe_to_stream(self.example_email("othello"), u"test_stream")
|
||||
action = lambda: self.subscribe(self.example_user("othello"), u"test_stream")
|
||||
events = self.do_test(action, num_events=2)
|
||||
peer_add_schema_checker = self.check_events_dict([
|
||||
('type', equals('subscription')),
|
||||
|
@ -1521,14 +1521,14 @@ class EventsRegisterTest(ZulipTestCase):
|
|||
])
|
||||
|
||||
# Subscribe to a totally new stream, so it's just Hamlet on it
|
||||
action = lambda: self.subscribe_to_stream(self.example_email("hamlet"), "test_stream") # type: Callable
|
||||
action = lambda: self.subscribe(self.example_user("hamlet"), "test_stream") # type: Callable
|
||||
events = self.do_test(action, event_types=["subscription", "realm_user"],
|
||||
include_subscribers=include_subscribers)
|
||||
error = add_schema_checker('events[0]', events[0])
|
||||
self.assert_on_error(error)
|
||||
|
||||
# Add another user to that totally new stream
|
||||
action = lambda: self.subscribe_to_stream(self.example_email("othello"), "test_stream")
|
||||
action = lambda: self.subscribe(self.example_user("othello"), "test_stream")
|
||||
events = self.do_test(action,
|
||||
include_subscribers=include_subscribers,
|
||||
state_change_expected=include_subscribers,
|
||||
|
@ -1560,7 +1560,7 @@ class EventsRegisterTest(ZulipTestCase):
|
|||
self.assert_on_error(error)
|
||||
|
||||
# Now resubscribe a user, to make sure that works on a vacated stream
|
||||
action = lambda: self.subscribe_to_stream(self.example_email("hamlet"), "test_stream")
|
||||
action = lambda: self.subscribe(self.example_user("hamlet"), "test_stream")
|
||||
events = self.do_test(action,
|
||||
include_subscribers=include_subscribers,
|
||||
num_events=2)
|
||||
|
@ -1669,7 +1669,7 @@ class FetchInitialStateDataTest(ZulipTestCase):
|
|||
pm1_message_id = self.send_message(sender_email, user_profile.email, Recipient.PERSONAL, "hello1")
|
||||
pm2_message_id = self.send_message(sender_email, user_profile.email, Recipient.PERSONAL, "hello2")
|
||||
|
||||
muted_stream = self.subscribe_to_stream(user_profile.email, 'Muted Stream')
|
||||
muted_stream = self.subscribe(user_profile, 'Muted Stream')
|
||||
mute_stream(user_profile, muted_stream)
|
||||
stream_message_id = self.send_message(sender_email, "Denmark", Recipient.STREAM, "hello")
|
||||
muted_stream_message_id = self.send_message(sender_email, "Muted Stream", Recipient.STREAM, "hello")
|
||||
|
|
|
@ -363,10 +363,10 @@ class HomeTest(ZulipTestCase):
|
|||
|
||||
def test_new_stream(self):
|
||||
# type: () -> None
|
||||
email = self.example_email("hamlet")
|
||||
user_profile = self.example_user("hamlet")
|
||||
stream_name = 'New stream'
|
||||
self.subscribe_to_stream(email, stream_name)
|
||||
self.login(email)
|
||||
self.subscribe(user_profile, stream_name)
|
||||
self.login(user_profile.email)
|
||||
result = self._get_home_page(stream=stream_name)
|
||||
page_params = self._get_page_params(result)
|
||||
self.assertEqual(page_params['narrow_stream'], stream_name)
|
||||
|
|
|
@ -481,9 +481,10 @@ class StreamMessagesTest(ZulipTestCase):
|
|||
|
||||
def test_not_too_many_queries(self):
|
||||
# type: () -> None
|
||||
recipient_list = [self.example_email("hamlet"), self.example_email("iago"), self.example_email("cordelia"), self.example_email("othello")]
|
||||
for email in recipient_list:
|
||||
self.subscribe_to_stream(email, "Denmark")
|
||||
recipient_list = [self.example_user("hamlet"), self.example_user("iago"),
|
||||
self.example_user("cordelia"), self.example_user("othello")]
|
||||
for user_profile in recipient_list:
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
|
||||
sender = self.example_user('hamlet')
|
||||
message_type_name = "stream"
|
||||
|
@ -513,7 +514,7 @@ class StreamMessagesTest(ZulipTestCase):
|
|||
def test_stream_message_dict(self):
|
||||
# type: () -> None
|
||||
user_profile = self.example_user('iago')
|
||||
self.subscribe_to_stream(user_profile.email, "Denmark")
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM,
|
||||
content="whatever", subject="my topic")
|
||||
message = most_recent_message(user_profile)
|
||||
|
@ -527,7 +528,7 @@ class StreamMessagesTest(ZulipTestCase):
|
|||
def test_stream_message_unicode(self):
|
||||
# type: () -> None
|
||||
user_profile = self.example_user('iago')
|
||||
self.subscribe_to_stream(user_profile.email, "Denmark")
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM,
|
||||
content="whatever", subject="my topic")
|
||||
message = most_recent_message(user_profile)
|
||||
|
@ -538,7 +539,7 @@ class StreamMessagesTest(ZulipTestCase):
|
|||
def test_message_mentions(self):
|
||||
# type: () -> None
|
||||
user_profile = self.example_user('iago')
|
||||
self.subscribe_to_stream(user_profile.email, "Denmark")
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM,
|
||||
content="test @**Iago** rules")
|
||||
message = most_recent_message(user_profile)
|
||||
|
@ -594,7 +595,7 @@ class StreamMessagesTest(ZulipTestCase):
|
|||
realm = get_realm("zulip")
|
||||
stream = self.make_stream(non_ascii_stream_name)
|
||||
for user_profile in UserProfile.objects.filter(realm=realm):
|
||||
self.subscribe_to_stream(user_profile.email, stream.name)
|
||||
self.subscribe(user_profile, stream.name)
|
||||
|
||||
self.assert_stream_message(non_ascii_stream_name, subject=u"hümbüǵ",
|
||||
content=u"hümbüǵ")
|
||||
|
@ -1161,7 +1162,7 @@ class MessagePOSTTest(ZulipTestCase):
|
|||
user.is_api_super_user = True
|
||||
user.save()
|
||||
user = get_user(email, get_realm('zulip'))
|
||||
self.subscribe_to_stream(email, "#IRCland", realm=user.realm)
|
||||
self.subscribe(user, "#IRCland")
|
||||
result = self.client_post("/api/v1/messages",
|
||||
{"type": "stream",
|
||||
"forged": "true",
|
||||
|
@ -1240,11 +1241,11 @@ class EditMessageTest(ZulipTestCase):
|
|||
|
||||
def test_fetch_raw_message_stream_wrong_realm(self):
|
||||
# type: () -> None
|
||||
email = self.example_email("hamlet")
|
||||
self.login(email)
|
||||
user_profile = self.example_user("hamlet")
|
||||
self.login(user_profile.email)
|
||||
stream = self.make_stream('public_stream')
|
||||
self.subscribe_to_stream(email, stream.name)
|
||||
msg_id = self.send_message(email, stream.name, Recipient.STREAM,
|
||||
self.subscribe(user_profile, stream.name)
|
||||
msg_id = self.send_message(user_profile.email, stream.name, Recipient.STREAM,
|
||||
subject="test", content="test")
|
||||
result = self.client_get('/json/messages/' + str(msg_id))
|
||||
self.assert_json_success(result)
|
||||
|
@ -1255,11 +1256,11 @@ class EditMessageTest(ZulipTestCase):
|
|||
|
||||
def test_fetch_raw_message_private_stream(self):
|
||||
# type: () -> None
|
||||
email = self.example_email("hamlet")
|
||||
self.login(email)
|
||||
user_profile = self.example_user("hamlet")
|
||||
self.login(user_profile.email)
|
||||
stream = self.make_stream('private_stream', invite_only=True)
|
||||
self.subscribe_to_stream(email, stream.name)
|
||||
msg_id = self.send_message(email, stream.name, Recipient.STREAM,
|
||||
self.subscribe(user_profile, stream.name)
|
||||
msg_id = self.send_message(user_profile.email, stream.name, Recipient.STREAM,
|
||||
subject="test", content="test")
|
||||
result = self.client_get('/json/messages/' + str(msg_id))
|
||||
self.assert_json_success(result)
|
||||
|
@ -1873,7 +1874,7 @@ class StarTests(ZulipTestCase):
|
|||
POST /json/messages/flags.
|
||||
"""
|
||||
stream_name = "new_stream"
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), stream_name)
|
||||
self.subscribe(self.example_user("hamlet"), stream_name)
|
||||
self.login(self.example_email("hamlet"))
|
||||
message_ids = [self.send_message(self.example_email("hamlet"), stream_name,
|
||||
Recipient.STREAM, "test")]
|
||||
|
@ -1944,7 +1945,7 @@ class StarTests(ZulipTestCase):
|
|||
# type: () -> None
|
||||
stream_name = "private_stream"
|
||||
self.make_stream(stream_name, invite_only=True)
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), stream_name)
|
||||
self.subscribe(self.example_user("hamlet"), stream_name)
|
||||
self.login(self.example_email("hamlet"))
|
||||
message_ids = [self.send_message(self.example_email("hamlet"), stream_name,
|
||||
Recipient.STREAM, "test")]
|
||||
|
@ -2000,7 +2001,6 @@ class AttachmentTest(ZulipTestCase):
|
|||
|
||||
# Create dummy DB entry
|
||||
user_profile = self.example_user('hamlet')
|
||||
sender_email = user_profile.email
|
||||
sample_size = 10
|
||||
dummy_files = [
|
||||
('zulip.txt', '1/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt', sample_size),
|
||||
|
@ -2012,13 +2012,13 @@ class AttachmentTest(ZulipTestCase):
|
|||
create_attachment(file_name, path_id, user_profile, size)
|
||||
|
||||
# Send message referring the attachment
|
||||
self.subscribe_to_stream(sender_email, "Denmark")
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
|
||||
body = "Some files here ...[zulip.txt](http://localhost:9991/user_uploads/1/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt)" + \
|
||||
"http://localhost:9991/user_uploads/1/31/4CBjtTLYZhk66pZrF8hnYGwc/temp_file.py.... Some more...." + \
|
||||
"http://localhost:9991/user_uploads/1/31/4CBjtTLYZhk66pZrF8hnYGwc/abc.py"
|
||||
|
||||
self.send_message(sender_email, "Denmark", Recipient.STREAM, body, "test")
|
||||
self.send_message(user_profile.email, "Denmark", Recipient.STREAM, body, "test")
|
||||
|
||||
for file_name, path_id, size in dummy_files:
|
||||
attachment = Attachment.objects.get(path_id=path_id)
|
||||
|
@ -2150,9 +2150,9 @@ class SoftDeactivationMessageTest(ZulipTestCase):
|
|||
|
||||
def test_maybe_catch_up_soft_deactivated_user(self):
|
||||
# type: () -> None
|
||||
recipient_list = [self.example_email("hamlet"), self.example_email("iago")]
|
||||
for email in recipient_list:
|
||||
self.subscribe_to_stream(email, "Denmark")
|
||||
recipient_list = [self.example_user("hamlet"), self.example_user("iago")]
|
||||
for user_profile in recipient_list:
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
|
||||
sender = self.example_email('iago')
|
||||
stream_name = 'Denmark'
|
||||
|
@ -2189,9 +2189,9 @@ class SoftDeactivationMessageTest(ZulipTestCase):
|
|||
|
||||
def test_add_missing_messages(self):
|
||||
# type: () -> None
|
||||
recipient_list = [self.example_email("hamlet"), self.example_email("iago")]
|
||||
for email in recipient_list:
|
||||
self.subscribe_to_stream(email, "Denmark")
|
||||
recipient_list = [self.example_user("hamlet"), self.example_user("iago")]
|
||||
for user_profile in recipient_list:
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
|
||||
sender = self.example_user('iago')
|
||||
realm = sender.realm
|
||||
|
@ -2252,7 +2252,7 @@ class SoftDeactivationMessageTest(ZulipTestCase):
|
|||
# Alter subscription to stream.
|
||||
self.unsubscribe_from_stream(long_term_idle_user.email, stream_name, realm)
|
||||
send_fake_message('Test Message 4', stream)
|
||||
self.subscribe_to_stream(long_term_idle_user.email, stream_name, realm)
|
||||
self.subscribe(long_term_idle_user, stream_name)
|
||||
sent_message_list.append(send_fake_message('Test Message 5', stream))
|
||||
sent_message_list.reverse()
|
||||
idle_user_msg_list = get_user_messages(long_term_idle_user)
|
||||
|
@ -2273,7 +2273,7 @@ class SoftDeactivationMessageTest(ZulipTestCase):
|
|||
sent_message_list.append(send_fake_message('Test Message 6', stream))
|
||||
# Unsubscribe from stream and then immediately subscribe back again.
|
||||
self.unsubscribe_from_stream(long_term_idle_user.email, stream_name, realm)
|
||||
self.subscribe_to_stream(long_term_idle_user.email, stream_name, realm)
|
||||
self.subscribe(long_term_idle_user, stream_name)
|
||||
sent_message_list.append(send_fake_message('Test Message 7', stream))
|
||||
# Again unsubscribe from stream and send a message.
|
||||
# This will make sure that if initially in a unsubscribed state
|
||||
|
@ -2281,7 +2281,7 @@ class SoftDeactivationMessageTest(ZulipTestCase):
|
|||
self.unsubscribe_from_stream(long_term_idle_user.email, stream_name, realm)
|
||||
send_fake_message('Test Message 8', stream)
|
||||
# Do a subscribe and unsubscribe immediately.
|
||||
self.subscribe_to_stream(long_term_idle_user.email, stream_name, realm)
|
||||
self.subscribe(long_term_idle_user, stream_name)
|
||||
self.unsubscribe_from_stream(long_term_idle_user.email, stream_name, realm)
|
||||
|
||||
sent_message_list.reverse()
|
||||
|
@ -2302,14 +2302,14 @@ class SoftDeactivationMessageTest(ZulipTestCase):
|
|||
# Test for a Private Stream.
|
||||
stream_name = "Core"
|
||||
private_stream = self.make_stream('Core', invite_only=True)
|
||||
self.subscribe_to_stream(self.example_email("iago"), stream_name)
|
||||
self.subscribe(self.example_user("iago"), stream_name)
|
||||
sent_message_list = []
|
||||
send_fake_message('Test Message 9', private_stream)
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), stream_name)
|
||||
self.subscribe(self.example_user("hamlet"), stream_name)
|
||||
sent_message_list.append(send_fake_message('Test Message 10', private_stream))
|
||||
self.unsubscribe_from_stream(long_term_idle_user.email, stream_name, realm)
|
||||
send_fake_message('Test Message 11', private_stream)
|
||||
self.subscribe_to_stream(long_term_idle_user.email, stream_name, realm)
|
||||
self.subscribe(long_term_idle_user, stream_name)
|
||||
sent_message_list.append(send_fake_message('Test Message 12', private_stream))
|
||||
sent_message_list.reverse()
|
||||
idle_user_msg_list = get_user_messages(long_term_idle_user)
|
||||
|
@ -2330,12 +2330,12 @@ class SoftDeactivationMessageTest(ZulipTestCase):
|
|||
# do_send_messages() in action.py for filtering the messages for which
|
||||
# UserMessage rows should be created for a soft-deactivated user.
|
||||
recipient_list = [
|
||||
self.example_email("hamlet"),
|
||||
self.example_email("iago"),
|
||||
self.example_email('cordelia')
|
||||
self.example_user("hamlet"),
|
||||
self.example_user("iago"),
|
||||
self.example_user('cordelia')
|
||||
]
|
||||
for email in recipient_list:
|
||||
self.subscribe_to_stream(email, "Denmark")
|
||||
for user_profile in recipient_list:
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
|
||||
cordelia = self.example_user('cordelia')
|
||||
sender = self.example_email('iago')
|
||||
|
|
|
@ -584,7 +584,7 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
# We need to subscribe to a stream and then send a message to
|
||||
# it to ensure that we actually have a stream message in this
|
||||
# narrow view.
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), 'Scotland')
|
||||
self.subscribe(self.example_user("hamlet"), 'Scotland')
|
||||
self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM)
|
||||
messages = get_user_messages(self.example_user('hamlet'))
|
||||
stream_messages = [msg for msg in messages if msg.recipient.type == Recipient.STREAM]
|
||||
|
@ -609,10 +609,10 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
# it to ensure that we actually have a stream message in this
|
||||
# narrow view.
|
||||
lambda_stream_name = u"\u03bb-stream"
|
||||
self.subscribe_to_stream(self.mit_email("starnine"), lambda_stream_name)
|
||||
self.subscribe(self.mit_user("starnine"), lambda_stream_name)
|
||||
|
||||
lambda_stream_d_name = u"\u03bb-stream.d"
|
||||
self.subscribe_to_stream(self.mit_email("starnine"), lambda_stream_d_name)
|
||||
self.subscribe(self.mit_user("starnine"), lambda_stream_d_name)
|
||||
|
||||
self.send_message(self.mit_email("starnine"), u"\u03bb-stream", Recipient.STREAM)
|
||||
self.send_message(self.mit_email("starnine"), u"\u03bb-stream.d", Recipient.STREAM)
|
||||
|
@ -642,7 +642,7 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
# We need to susbcribe to a stream and then send a message to
|
||||
# it to ensure that we actually have a stream message in this
|
||||
# narrow view.
|
||||
self.subscribe_to_stream(email, "Scotland")
|
||||
self.subscribe(mit_user_profile, "Scotland")
|
||||
|
||||
self.send_message(email, "Scotland", Recipient.STREAM,
|
||||
subject=u"\u03bb-topic")
|
||||
|
@ -678,7 +678,7 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
self.login(email) # We need to susbcribe to a stream and then send a message to
|
||||
# it to ensure that we actually have a stream message in this
|
||||
# narrow view.
|
||||
self.subscribe_to_stream(email, "Scotland")
|
||||
self.subscribe(mit_user_profile, "Scotland")
|
||||
|
||||
self.send_message(email, "Scotland", Recipient.STREAM,
|
||||
subject=u".d.d")
|
||||
|
@ -865,7 +865,7 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
def test_get_messages_with_search_not_subscribed(self):
|
||||
# type: () -> None
|
||||
"""Verify support for searching a stream you're not subscribed to"""
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), "newstream")
|
||||
self.subscribe(self.example_user("hamlet"), "newstream")
|
||||
self.send_message(
|
||||
sender_name=self.example_email("hamlet"),
|
||||
raw_recipients="newstream",
|
||||
|
|
|
@ -83,9 +83,8 @@ class ReactionEmojiTest(ZulipTestCase):
|
|||
"""
|
||||
Reacting with valid emoji on a historical message succeeds
|
||||
"""
|
||||
realm = get_realm("zulip")
|
||||
stream_name = "Saxony"
|
||||
self.subscribe_to_stream(self.example_email("cordelia"), stream_name, realm=realm)
|
||||
self.subscribe(self.example_user("cordelia"), stream_name)
|
||||
message_id = self.send_message(self.example_email("cordelia"), stream_name, Recipient.STREAM)
|
||||
|
||||
user_profile = self.example_user('hamlet')
|
||||
|
|
|
@ -39,7 +39,7 @@ class TestServiceBotEventTriggers(ZulipTestCase):
|
|||
bot_owner=self.user_profile)
|
||||
|
||||
# TODO: In future versions this won't be required
|
||||
self.subscribe_to_stream(self.bot_profile.email, 'Denmark')
|
||||
self.subscribe(self.bot_profile, 'Denmark')
|
||||
|
||||
@mock.patch('zerver.lib.actions.queue_json_publish')
|
||||
def test_trigger_on_stream_mention_from_user(self, mock_queue_json_publish):
|
||||
|
|
|
@ -493,7 +493,7 @@ class InviteUserTest(ZulipTestCase):
|
|||
user_profile = self.example_user('hamlet')
|
||||
private_stream_name = "Secret"
|
||||
self.make_stream(private_stream_name, invite_only=True)
|
||||
self.subscribe_to_stream(user_profile.email, private_stream_name)
|
||||
self.subscribe(user_profile, private_stream_name)
|
||||
public_msg_id = self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM,
|
||||
"Public topic", "Public message")
|
||||
secret_msg_id = self.send_message(self.example_email("hamlet"), private_stream_name, Recipient.STREAM,
|
||||
|
@ -678,7 +678,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
|
|||
stream_name = u"hümbüǵ"
|
||||
|
||||
# Make sure we're subscribed before inviting someone.
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), stream_name)
|
||||
self.subscribe(self.example_user("hamlet"), stream_name)
|
||||
|
||||
self.assert_json_success(self.invite(invitee, [stream_name]))
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
result = self.client_patch("/json/streams/%d" % (stream_id,), params)
|
||||
self.assert_json_error(result, 'Invalid stream id')
|
||||
|
||||
self.subscribe_to_stream(email, 'private_stream')
|
||||
self.subscribe(user_profile, 'private_stream')
|
||||
|
||||
do_change_is_admin(user_profile, True)
|
||||
params = {
|
||||
|
@ -197,7 +197,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
email = user_profile.email
|
||||
self.login(email)
|
||||
stream = self.make_stream('new_stream')
|
||||
self.subscribe_to_stream(user_profile.email, stream.name)
|
||||
self.subscribe(user_profile, stream.name)
|
||||
do_change_is_admin(user_profile, True)
|
||||
|
||||
result = self.client_delete('/json/streams/%d' % (stream.id,))
|
||||
|
@ -222,7 +222,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
# type: () -> None
|
||||
stream = self.make_stream('new_stream', invite_only=True)
|
||||
realm = self.example_user("hamlet").realm
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), stream.name)
|
||||
self.subscribe(self.example_user("hamlet"), stream.name)
|
||||
do_add_default_stream(stream)
|
||||
self.assertEqual(1, DefaultStream.objects.filter(stream=stream).count())
|
||||
self.unsubscribe_from_stream(self.example_email("hamlet"), stream.name, realm)
|
||||
|
@ -245,9 +245,8 @@ class StreamAdminTest(ZulipTestCase):
|
|||
def test_deactivate_stream_backend_requires_realm_admin(self):
|
||||
# type: () -> None
|
||||
user_profile = self.example_user('hamlet')
|
||||
email = user_profile.email
|
||||
self.login(email)
|
||||
self.subscribe_to_stream(email, 'new_stream')
|
||||
self.login(user_profile.email)
|
||||
self.subscribe(user_profile, 'new_stream')
|
||||
|
||||
stream_id = get_stream('new_stream', user_profile.realm).id
|
||||
result = self.client_delete('/json/streams/%d' % (stream_id,))
|
||||
|
@ -256,14 +255,13 @@ class StreamAdminTest(ZulipTestCase):
|
|||
def test_private_stream_live_updates(self):
|
||||
# type: () -> None
|
||||
user_profile = self.example_user('hamlet')
|
||||
email = user_profile.email
|
||||
self.login(email)
|
||||
self.login(user_profile.email)
|
||||
|
||||
do_change_is_admin(user_profile, True)
|
||||
|
||||
self.make_stream('private_stream', invite_only=True)
|
||||
self.subscribe_to_stream(email, 'private_stream')
|
||||
self.subscribe_to_stream(self.example_email("cordelia"), 'private_stream')
|
||||
self.subscribe(user_profile, 'private_stream')
|
||||
self.subscribe(self.example_user("cordelia"), 'private_stream')
|
||||
|
||||
events = [] # type: List[Mapping[str, Any]]
|
||||
with tornado_redirected_to_list(events):
|
||||
|
@ -302,7 +300,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
email = user_profile.email
|
||||
self.login(email)
|
||||
realm = user_profile.realm
|
||||
stream = self.subscribe_to_stream(email, 'stream_name1')
|
||||
stream = self.subscribe(user_profile, 'stream_name1')
|
||||
do_change_is_admin(user_profile, True)
|
||||
|
||||
result = self.client_patch('/json/streams/%d' % (stream.id,),
|
||||
|
@ -410,7 +408,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
email = user_profile.email
|
||||
self.login(email)
|
||||
realm = user_profile.realm
|
||||
self.subscribe_to_stream(email, 'stream_name1')
|
||||
self.subscribe(user_profile, 'stream_name1')
|
||||
do_change_is_admin(user_profile, True)
|
||||
|
||||
events = [] # type: List[Mapping[str, Any]]
|
||||
|
@ -446,7 +444,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
email = user_profile.email
|
||||
self.login(email)
|
||||
|
||||
self.subscribe_to_stream(email, 'stream_name1')
|
||||
self.subscribe(user_profile, 'stream_name1')
|
||||
do_change_is_admin(user_profile, False)
|
||||
|
||||
stream_id = get_stream('stream_name1', user_profile.realm).id
|
||||
|
@ -467,7 +465,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
|
||||
# For testing deleting streams you aren't on.
|
||||
if subscribed:
|
||||
self.subscribe_to_stream(email, stream_name)
|
||||
self.subscribe(user_profile, stream_name)
|
||||
|
||||
do_change_is_admin(user_profile, True)
|
||||
|
||||
|
@ -578,9 +576,9 @@ class StreamAdminTest(ZulipTestCase):
|
|||
|
||||
# Subscribe the admin and/or principal as specified in the flags.
|
||||
if is_subbed:
|
||||
self.subscribe_to_stream(user_profile.email, stream_name)
|
||||
self.subscribe(user_profile, stream_name)
|
||||
if other_user_subbed:
|
||||
self.subscribe_to_stream(other_user_profile.email, stream_name)
|
||||
self.subscribe(other_user_profile, stream_name)
|
||||
|
||||
result = self.client_delete(
|
||||
"/json/users/me/subscriptions",
|
||||
|
@ -1760,30 +1758,24 @@ class SubscriptionAPITest(ZulipTestCase):
|
|||
"""
|
||||
Check users getting add_peer_event is correct
|
||||
"""
|
||||
email1 = self.example_email("othello")
|
||||
email2 = self.example_email("cordelia")
|
||||
email3 = self.example_email('hamlet')
|
||||
email4 = self.example_email("iago")
|
||||
realm = get_realm('zulip')
|
||||
user1 = self.example_user("othello")
|
||||
user2 = self.example_user("cordelia")
|
||||
user3 = self.example_user("hamlet")
|
||||
user4 = self.example_user("iago")
|
||||
|
||||
stream1 = self.make_stream('stream1')
|
||||
stream2 = self.make_stream('stream2')
|
||||
private = self.make_stream('private_stream', invite_only=True)
|
||||
|
||||
self.subscribe_to_stream(email1, 'stream1')
|
||||
self.subscribe_to_stream(email2, 'stream1')
|
||||
self.subscribe_to_stream(email3, 'stream1')
|
||||
self.subscribe(user1, 'stream1')
|
||||
self.subscribe(user2, 'stream1')
|
||||
self.subscribe(user3, 'stream1')
|
||||
|
||||
self.subscribe_to_stream(email2, 'stream2')
|
||||
self.subscribe(user2, 'stream2')
|
||||
|
||||
self.subscribe_to_stream(email1, 'private_stream')
|
||||
self.subscribe_to_stream(email2, 'private_stream')
|
||||
self.subscribe_to_stream(email3, 'private_stream')
|
||||
|
||||
user1 = get_user(email1, realm)
|
||||
user2 = get_user(email2, realm)
|
||||
user3 = get_user(email3, realm)
|
||||
user4 = get_user(email4, realm)
|
||||
self.subscribe(user1, 'private_stream')
|
||||
self.subscribe(user2, 'private_stream')
|
||||
self.subscribe(user3, 'private_stream')
|
||||
|
||||
events = [] # type: List[Mapping[str, Any]]
|
||||
with tornado_redirected_to_list(events):
|
||||
|
@ -2489,7 +2481,7 @@ class GetSubscribersTest(ZulipTestCase):
|
|||
email = mit_user_profile.email
|
||||
users_to_subscribe = [email, self.mit_email("espuser")]
|
||||
for email in users_to_subscribe:
|
||||
self.subscribe_to_stream(email, "mit_stream")
|
||||
self.subscribe(get_user(email, mit_user_profile.realm), "mit_stream")
|
||||
|
||||
ret = self.common_subscribe_to_streams(
|
||||
email,
|
||||
|
|
|
@ -213,8 +213,8 @@ class UnreadCountTests(ZulipTestCase):
|
|||
# type: () -> None
|
||||
self.login(self.example_email("hamlet"))
|
||||
user_profile = self.example_user('hamlet')
|
||||
stream = self.subscribe_to_stream(user_profile.email, "test_stream", user_profile.realm)
|
||||
self.subscribe_to_stream(self.example_email("cordelia"), "test_stream", user_profile.realm)
|
||||
stream = self.subscribe(user_profile, "test_stream")
|
||||
self.subscribe(self.example_user("cordelia"), "test_stream")
|
||||
|
||||
message_id = self.send_message(self.example_email("hamlet"), "test_stream", Recipient.STREAM, "hello")
|
||||
unrelated_message_id = self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, "hello")
|
||||
|
@ -273,7 +273,7 @@ class UnreadCountTests(ZulipTestCase):
|
|||
# type: () -> None
|
||||
self.login(self.example_email("hamlet"))
|
||||
user_profile = self.example_user('hamlet')
|
||||
self.subscribe_to_stream(user_profile.email, "test_stream", user_profile.realm)
|
||||
self.subscribe(user_profile, "test_stream")
|
||||
|
||||
message_id = self.send_message(self.example_email("hamlet"), "test_stream", Recipient.STREAM, "hello", "test_topic")
|
||||
unrelated_message_id = self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, "hello", "Denmark2")
|
||||
|
|
|
@ -199,7 +199,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
|
|||
entry = Attachment.objects.get(file_name='zulip.txt')
|
||||
self.assertEqual(entry.is_claimed(), False)
|
||||
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), "Denmark")
|
||||
self.subscribe(self.example_user("hamlet"), "Denmark")
|
||||
body = "First message ...[zulip.txt](http://localhost:9991" + uri + ")"
|
||||
self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, body, "test")
|
||||
self.assertIn('title="zulip.txt"', self.get_last_message().rendered_content)
|
||||
|
@ -266,7 +266,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
|
|||
d2_attachment.save()
|
||||
|
||||
# Send message refering only dummy_1
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), "Denmark")
|
||||
self.subscribe(self.example_user("hamlet"), "Denmark")
|
||||
body = "Some files here ...[zulip.txt](http://localhost:9991/user_uploads/" + d1_path_id + ")"
|
||||
self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, body, "test")
|
||||
|
||||
|
@ -294,7 +294,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
|
|||
result = self.client_post("/json/user_uploads", {'file': d1})
|
||||
d1_path_id = re.sub('/user_uploads/', '', result.json()['uri'])
|
||||
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), "Denmark")
|
||||
self.subscribe(self.example_user("hamlet"), "Denmark")
|
||||
body = "First message ...[zulip.txt](http://localhost:9991/user_uploads/" + d1_path_id + ")"
|
||||
self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, body, "test")
|
||||
body = "Second message ...[zulip.txt](http://localhost:9991/user_uploads/" + d1_path_id + ")"
|
||||
|
@ -313,7 +313,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
|
|||
d1_path_id = re.sub('/user_uploads/', '', result.json()['uri'])
|
||||
|
||||
self.make_stream("private_stream", invite_only=True)
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), "private_stream")
|
||||
self.subscribe(self.example_user("hamlet"), "private_stream")
|
||||
|
||||
# First, send the mesasge to the new private stream.
|
||||
body = "First message ...[zulip.txt](http://localhost:9991/user_uploads/" + d1_path_id + ")"
|
||||
|
@ -355,7 +355,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
|
|||
result = self.client_post("/json/user_uploads", {'file': f2})
|
||||
f2_path_id = re.sub('/user_uploads/', '', result.json()['uri'])
|
||||
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), "test")
|
||||
self.subscribe(self.example_user("hamlet"), "test")
|
||||
body = ("[f1.txt](http://localhost:9991/user_uploads/" + f1_path_id + ")"
|
||||
"[f2.txt](http://localhost:9991/user_uploads/" + f2_path_id + ")")
|
||||
msg_id = self.send_message(self.example_email("hamlet"), "test", Recipient.STREAM, body, "test")
|
||||
|
@ -502,8 +502,9 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
|
|||
# type: () -> None
|
||||
subscribed_users = [self.example_email("hamlet"), self.example_email("iago")]
|
||||
unsubscribed_users = [self.example_email("othello"), self.example_email("prospero")]
|
||||
for user in subscribed_users:
|
||||
self.subscribe_to_stream(user, "test-subscribe")
|
||||
realm = get_realm("zulip")
|
||||
for email in subscribed_users:
|
||||
self.subscribe(get_user(email, realm), "test-subscribe")
|
||||
|
||||
# Make the stream private
|
||||
stream = Stream.objects.get(name='test-subscribe')
|
||||
|
@ -541,8 +542,9 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
|
|||
# type: () -> None
|
||||
subscribed_users = [self.example_email("hamlet"), self.example_email("iago")]
|
||||
unsubscribed_users = [self.example_email("othello"), self.example_email("prospero")]
|
||||
for user in subscribed_users:
|
||||
self.subscribe_to_stream(user, "test-subscribe")
|
||||
realm = get_realm("zulip")
|
||||
for email in subscribed_users:
|
||||
self.subscribe(get_user(email, realm), "test-subscribe")
|
||||
|
||||
self.login(self.example_email("hamlet"))
|
||||
fp = StringIO("zulip!")
|
||||
|
@ -972,7 +974,7 @@ class S3Test(ZulipTestCase):
|
|||
uploaded_file = Attachment.objects.get(owner=user_profile, path_id=path_id)
|
||||
self.assertEqual(len(b"zulip!"), uploaded_file.size)
|
||||
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), "Denmark")
|
||||
self.subscribe(self.example_user("hamlet"), "Denmark")
|
||||
body = "First message ...[zulip.txt](http://localhost:9991" + uri + ")"
|
||||
self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, body, "test")
|
||||
self.assertIn('title="dummy.txt"', self.get_last_message().rendered_content)
|
||||
|
@ -1014,7 +1016,7 @@ class S3Test(ZulipTestCase):
|
|||
|
||||
self.assertEqual(b"zulip!", urllib.request.urlopen(redirect_url).read().strip())
|
||||
|
||||
self.subscribe_to_stream(self.example_email("hamlet"), "Denmark")
|
||||
self.subscribe(self.example_user("hamlet"), "Denmark")
|
||||
body = "First message ...[zulip.txt](http://localhost:9991" + uri + ")"
|
||||
self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, body, "test")
|
||||
self.assertIn('title="zulip.txt"', self.get_last_message().rendered_content)
|
||||
|
|
Loading…
Reference in New Issue