mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 15:33:30 +00:00
tests: Switch to using common_subscribe_to_streams.
(imported from commit f172e9e39d211b7f31d95d6aa83528f631808edb)
This commit is contained in:
@@ -792,7 +792,7 @@ class SubscriptionAPITest(AuthedTestCase):
|
|||||||
# also check that this matches the list of your subscriptions
|
# also check that this matches the list of your subscriptions
|
||||||
self.assertItemsEqual(list_streams, self.streams)
|
self.assertItemsEqual(list_streams, self.streams)
|
||||||
|
|
||||||
def helper_check_subs_before_and_after_add(self, url, subscriptions, other_params,
|
def helper_check_subs_before_and_after_add(self, subscriptions, other_params,
|
||||||
json_dict, email, new_subs):
|
json_dict, email, new_subs):
|
||||||
"""
|
"""
|
||||||
Check result of adding subscriptions.
|
Check result of adding subscriptions.
|
||||||
@@ -808,9 +808,7 @@ class SubscriptionAPITest(AuthedTestCase):
|
|||||||
"already_subscribed": {"iago@humbughq.com": ["Venice", "Verona"]},
|
"already_subscribed": {"iago@humbughq.com": ["Venice", "Verona"]},
|
||||||
"subscribed": {"iago@humbughq.com": ["Venice8"]}}
|
"subscribed": {"iago@humbughq.com": ["Venice8"]}}
|
||||||
"""
|
"""
|
||||||
data = {"subscriptions": ujson.dumps(subscriptions)}
|
result = self.common_subscribe_to_streams(self.test_email, subscriptions, other_params)
|
||||||
data.update(other_params)
|
|
||||||
result = self.client.post(url, data)
|
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
json = ujson.loads(result.content)
|
json = ujson.loads(result.content)
|
||||||
for subscription_status, val in json_dict.iteritems():
|
for subscription_status, val in json_dict.iteritems():
|
||||||
@@ -832,8 +830,7 @@ class SubscriptionAPITest(AuthedTestCase):
|
|||||||
self.assertNotEqual(len(self.streams), 0) # necessary for full test coverage
|
self.assertNotEqual(len(self.streams), 0) # necessary for full test coverage
|
||||||
add_streams = self.make_random_stream_names(self.streams)
|
add_streams = self.make_random_stream_names(self.streams)
|
||||||
self.assertNotEqual(len(add_streams), 0) # necessary for full test coverage
|
self.assertNotEqual(len(add_streams), 0) # necessary for full test coverage
|
||||||
self.helper_check_subs_before_and_after_add(
|
self.helper_check_subs_before_and_after_add(self.streams + add_streams, {},
|
||||||
"/json/subscriptions/add", self.streams + add_streams, {},
|
|
||||||
{"subscribed": {self.test_email: add_streams},
|
{"subscribed": {self.test_email: add_streams},
|
||||||
"already_subscribed": {self.test_email: self.streams}},
|
"already_subscribed": {self.test_email: self.streams}},
|
||||||
self.test_email, self.streams + add_streams)
|
self.test_email, self.streams + add_streams)
|
||||||
@@ -842,8 +839,7 @@ class SubscriptionAPITest(AuthedTestCase):
|
|||||||
"""
|
"""
|
||||||
Subscribing to a stream name with non-ASCII characters succeeds.
|
Subscribing to a stream name with non-ASCII characters succeeds.
|
||||||
"""
|
"""
|
||||||
self.helper_check_subs_before_and_after_add(
|
self.helper_check_subs_before_and_after_add(self.streams + [u"hümbüǵ"], {},
|
||||||
"/json/subscriptions/add", self.streams + [u"hümbüǵ"], {},
|
|
||||||
{"subscribed": {self.test_email: [u"hümbüǵ"]},
|
{"subscribed": {self.test_email: [u"hümbüǵ"]},
|
||||||
"already_subscribed": {self.test_email: self.streams}},
|
"already_subscribed": {self.test_email: self.streams}},
|
||||||
self.test_email, self.streams + [u"hümbüǵ"])
|
self.test_email, self.streams + [u"hümbüǵ"])
|
||||||
@@ -855,8 +851,7 @@ class SubscriptionAPITest(AuthedTestCase):
|
|||||||
"""
|
"""
|
||||||
# character limit is 30 characters
|
# character limit is 30 characters
|
||||||
long_stream_name = "a" * 31
|
long_stream_name = "a" * 31
|
||||||
result = self.client.post("/json/subscriptions/add",
|
result = self.common_subscribe_to_streams(self.test_email, [long_stream_name])
|
||||||
{"subscriptions": ujson.dumps([long_stream_name])})
|
|
||||||
self.assert_json_error(result,
|
self.assert_json_error(result,
|
||||||
"Stream name (%s) too long." % (long_stream_name,))
|
"Stream name (%s) too long." % (long_stream_name,))
|
||||||
|
|
||||||
@@ -868,8 +863,7 @@ class SubscriptionAPITest(AuthedTestCase):
|
|||||||
"""
|
"""
|
||||||
# currently, the only invalid name is the empty string
|
# currently, the only invalid name is the empty string
|
||||||
invalid_stream_name = ""
|
invalid_stream_name = ""
|
||||||
result = self.client.post("/json/subscriptions/add",
|
result = self.common_subscribe_to_streams(self.test_email, [invalid_stream_name])
|
||||||
{"subscriptions": ujson.dumps([invalid_stream_name])})
|
|
||||||
self.assert_json_error(result,
|
self.assert_json_error(result,
|
||||||
"Invalid stream name (%s)." % (invalid_stream_name,))
|
"Invalid stream name (%s)." % (invalid_stream_name,))
|
||||||
|
|
||||||
@@ -887,8 +881,7 @@ class SubscriptionAPITest(AuthedTestCase):
|
|||||||
self.assertNotEqual(len(streams), 0) # necessary for full test coverage
|
self.assertNotEqual(len(streams), 0) # necessary for full test coverage
|
||||||
streams_to_sub = streams[:1] # just add one, to make the message easier to check
|
streams_to_sub = streams[:1] # just add one, to make the message easier to check
|
||||||
streams_to_sub.extend(current_streams)
|
streams_to_sub.extend(current_streams)
|
||||||
self.helper_check_subs_before_and_after_add(
|
self.helper_check_subs_before_and_after_add(streams_to_sub,
|
||||||
"/json/subscriptions/add", streams_to_sub,
|
|
||||||
{"principals": ujson.dumps([invitee])},
|
{"principals": ujson.dumps([invitee])},
|
||||||
{"subscribed": {invitee: streams[:1]},
|
{"subscribed": {invitee: streams[:1]},
|
||||||
"already_subscribed": {invitee: current_streams}},
|
"already_subscribed": {invitee: current_streams}},
|
||||||
@@ -925,36 +918,34 @@ class SubscriptionAPITest(AuthedTestCase):
|
|||||||
|
|
||||||
def test_subscription_add_invalid_principal(self):
|
def test_subscription_add_invalid_principal(self):
|
||||||
"""
|
"""
|
||||||
Calling /json/subscriptions/add on behalf of a principal that does not
|
Calling subscribe on behalf of a principal that does not exist
|
||||||
exist should return a JSON error.
|
should return a JSON error.
|
||||||
"""
|
"""
|
||||||
invalid_principal = "rosencrantz-and-guildenstern@humbughq.com"
|
invalid_principal = "rosencrantz-and-guildenstern@humbughq.com"
|
||||||
# verify that invalid_principal actually doesn't exist
|
# verify that invalid_principal actually doesn't exist
|
||||||
with self.assertRaises(UserProfile.DoesNotExist):
|
with self.assertRaises(UserProfile.DoesNotExist):
|
||||||
self.get_user_profile(invalid_principal)
|
self.get_user_profile(invalid_principal)
|
||||||
result = self.client.post("/json/subscriptions/add",
|
result = self.common_subscribe_to_streams(self.test_email, self.streams,
|
||||||
{"subscriptions": ujson.dumps(self.streams),
|
{"principals": ujson.dumps([invalid_principal])})
|
||||||
"principals": ujson.dumps([invalid_principal])})
|
|
||||||
self.assert_json_error(result, "User not authorized to execute queries on behalf of '%s'"
|
self.assert_json_error(result, "User not authorized to execute queries on behalf of '%s'"
|
||||||
% (invalid_principal,))
|
% (invalid_principal,))
|
||||||
|
|
||||||
def test_subscription_add_principal_other_realm(self):
|
def test_subscription_add_principal_other_realm(self):
|
||||||
"""
|
"""
|
||||||
Calling /json/subscriptions/add on behalf of a principal in another
|
Calling subscribe on behalf of a principal in another realm
|
||||||
realm should return a JSON error.
|
should return a JSON error.
|
||||||
"""
|
"""
|
||||||
principal = "starnine@mit.edu"
|
principal = "starnine@mit.edu"
|
||||||
profile = self.get_user_profile(principal)
|
profile = self.get_user_profile(principal)
|
||||||
# verify that principal exists (thus, the reason for the error is the cross-realming)
|
# verify that principal exists (thus, the reason for the error is the cross-realming)
|
||||||
self.assertIsInstance(profile, UserProfile)
|
self.assertIsInstance(profile, UserProfile)
|
||||||
result = self.client.post("/json/subscriptions/add",
|
result = self.common_subscribe_to_streams(self.test_email, self.streams,
|
||||||
{"subscriptions": ujson.dumps(self.streams),
|
{"principals": ujson.dumps([principal])})
|
||||||
"principals": ujson.dumps([principal])})
|
|
||||||
self.assert_json_error(result, "User not authorized to execute queries on behalf of '%s'"
|
self.assert_json_error(result, "User not authorized to execute queries on behalf of '%s'"
|
||||||
% (principal,))
|
% (principal,))
|
||||||
|
|
||||||
def helper_check_subs_before_and_after_remove(self, url, subscriptions, other_params,
|
def helper_check_subs_before_and_after_remove(self, subscriptions, json_dict,
|
||||||
json_dict, email, new_subs):
|
email, new_subs):
|
||||||
"""
|
"""
|
||||||
Check result of removing subscriptions.
|
Check result of removing subscriptions.
|
||||||
|
|
||||||
@@ -965,9 +956,8 @@ class SubscriptionAPITest(AuthedTestCase):
|
|||||||
"removed": ["Denmark", "Scotland", "Verona"],
|
"removed": ["Denmark", "Scotland", "Verona"],
|
||||||
"not_subscribed": ["Rome"], "result": "success"}
|
"not_subscribed": ["Rome"], "result": "success"}
|
||||||
"""
|
"""
|
||||||
data = {"subscriptions": ujson.dumps(subscriptions)}
|
result = self.client.post("/json/subscriptions/remove",
|
||||||
data.update(other_params)
|
{"subscriptions": ujson.dumps(subscriptions)})
|
||||||
result = self.client.post(url, data)
|
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
json = ujson.loads(result.content)
|
json = ujson.loads(result.content)
|
||||||
for key, val in json_dict.iteritems():
|
for key, val in json_dict.iteritems():
|
||||||
@@ -993,8 +983,7 @@ class SubscriptionAPITest(AuthedTestCase):
|
|||||||
self.assertNotEqual(len(not_subbed), 0) # necessary for full test coverage
|
self.assertNotEqual(len(not_subbed), 0) # necessary for full test coverage
|
||||||
try_to_remove = not_subbed[:3] # attempt to remove up to 3 streams not already subbed to
|
try_to_remove = not_subbed[:3] # attempt to remove up to 3 streams not already subbed to
|
||||||
streams_to_remove.extend(try_to_remove)
|
streams_to_remove.extend(try_to_remove)
|
||||||
self.helper_check_subs_before_and_after_remove(
|
self.helper_check_subs_before_and_after_remove(streams_to_remove,
|
||||||
"/json/subscriptions/remove", streams_to_remove, {},
|
|
||||||
{"removed": self.streams[1:], "not_subscribed": try_to_remove},
|
{"removed": self.streams[1:], "not_subscribed": try_to_remove},
|
||||||
self.test_email, [self.streams[0]])
|
self.test_email, [self.streams[0]])
|
||||||
|
|
||||||
@@ -1824,8 +1813,7 @@ class GetSubscribersTest(AuthedTestCase):
|
|||||||
"""
|
"""
|
||||||
# Create a stream for which Hamlet is the only subscriber.
|
# Create a stream for which Hamlet is the only subscriber.
|
||||||
stream_name = "Saxony"
|
stream_name = "Saxony"
|
||||||
self.client.post("/json/subscriptions/add",
|
self.common_subscribe_to_streams(self.email, [stream_name])
|
||||||
{"subscriptions": ujson.dumps([stream_name])})
|
|
||||||
other_email = "othello@humbughq.com"
|
other_email = "othello@humbughq.com"
|
||||||
|
|
||||||
# Fetch the subscriber list as a non-member.
|
# Fetch the subscriber list as a non-member.
|
||||||
@@ -1837,9 +1825,8 @@ class GetSubscribersTest(AuthedTestCase):
|
|||||||
A subscriber to a private stream can query that stream's membership.
|
A subscriber to a private stream can query that stream's membership.
|
||||||
"""
|
"""
|
||||||
stream_name = "Saxony"
|
stream_name = "Saxony"
|
||||||
self.client.post("/json/subscriptions/add",
|
self.common_subscribe_to_streams(self.email, [stream_name],
|
||||||
{"subscriptions": ujson.dumps([stream_name]),
|
invite_only=True)
|
||||||
"invite_only": ujson.dumps(True)})
|
|
||||||
self.make_successful_subscriber_request(stream_name)
|
self.make_successful_subscriber_request(stream_name)
|
||||||
|
|
||||||
def test_nonsubscriber_private_stream(self):
|
def test_nonsubscriber_private_stream(self):
|
||||||
@@ -1848,9 +1835,8 @@ class GetSubscribersTest(AuthedTestCase):
|
|||||||
"""
|
"""
|
||||||
# Create a private stream for which Hamlet is the only subscriber.
|
# Create a private stream for which Hamlet is the only subscriber.
|
||||||
stream_name = "Saxony"
|
stream_name = "Saxony"
|
||||||
self.client.post("/json/subscriptions/add",
|
self.common_subscribe_to_streams(self.email, [stream_name],
|
||||||
{"subscriptions": ujson.dumps([stream_name]),
|
invite_only=True)
|
||||||
"invite_only": ujson.dumps(True)})
|
|
||||||
other_email = "othello@humbughq.com"
|
other_email = "othello@humbughq.com"
|
||||||
|
|
||||||
# Try to fetch the subscriber list as a non-member.
|
# Try to fetch the subscriber list as a non-member.
|
||||||
|
|||||||
Reference in New Issue
Block a user