mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
test_subs: Add tests for unsubscribing multiple users from stream.
This commit adds tests for unsusbcribing multiple users from a
stream and fixes the missing coverage issue introduced in 2187c84.
This commit is contained in:
@@ -974,6 +974,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||||||
def attempt_unsubscribe_of_principal(self, query_count: int, is_admin: bool=False,
|
def attempt_unsubscribe_of_principal(self, query_count: int, is_admin: bool=False,
|
||||||
is_subbed: bool=True, invite_only: bool=False,
|
is_subbed: bool=True, invite_only: bool=False,
|
||||||
other_user_subbed: bool=True, using_legacy_emails: bool=False,
|
other_user_subbed: bool=True, using_legacy_emails: bool=False,
|
||||||
|
unsubscribe_multiple_users: bool=False,
|
||||||
other_sub_users: Optional[List[UserProfile]]=None) -> HttpResponse:
|
other_sub_users: Optional[List[UserProfile]]=None) -> HttpResponse:
|
||||||
|
|
||||||
# Set up the main user, who is in most cases an admin.
|
# Set up the main user, who is in most cases an admin.
|
||||||
@@ -991,15 +992,24 @@ class StreamAdminTest(ZulipTestCase):
|
|||||||
# Set up the principal to be unsubscribed.
|
# Set up the principal to be unsubscribed.
|
||||||
other_user_profile = self.example_user('cordelia')
|
other_user_profile = self.example_user('cordelia')
|
||||||
if using_legacy_emails:
|
if using_legacy_emails:
|
||||||
principal = other_user_profile.email
|
principals = [other_user_profile.email]
|
||||||
else:
|
else:
|
||||||
principal = other_user_profile.id
|
principals = [other_user_profile.id]
|
||||||
|
|
||||||
|
if unsubscribe_multiple_users:
|
||||||
|
second_user_to_unsubscribe = self.example_user('prospero')
|
||||||
|
if using_legacy_emails:
|
||||||
|
principals.append(second_user_to_unsubscribe.email)
|
||||||
|
else:
|
||||||
|
principals.append(second_user_to_unsubscribe.id)
|
||||||
|
|
||||||
# Subscribe the admin and/or principal as specified in the flags.
|
# Subscribe the admin and/or principal as specified in the flags.
|
||||||
if is_subbed:
|
if is_subbed:
|
||||||
self.subscribe(user_profile, stream_name)
|
self.subscribe(user_profile, stream_name)
|
||||||
if other_user_subbed:
|
if other_user_subbed:
|
||||||
self.subscribe(other_user_profile, stream_name)
|
self.subscribe(other_user_profile, stream_name)
|
||||||
|
if unsubscribe_multiple_users:
|
||||||
|
self.subscribe(second_user_to_unsubscribe, stream_name)
|
||||||
if other_sub_users:
|
if other_sub_users:
|
||||||
for user in other_sub_users:
|
for user in other_sub_users:
|
||||||
self.subscribe(user, stream_name)
|
self.subscribe(user, stream_name)
|
||||||
@@ -1008,7 +1018,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||||||
result = self.client_delete(
|
result = self.client_delete(
|
||||||
"/json/users/me/subscriptions",
|
"/json/users/me/subscriptions",
|
||||||
{"subscriptions": ujson.dumps([stream_name]),
|
{"subscriptions": ujson.dumps([stream_name]),
|
||||||
"principals": ujson.dumps([principal])})
|
"principals": ujson.dumps(principals)})
|
||||||
self.assert_length(queries, query_count)
|
self.assert_length(queries, query_count)
|
||||||
|
|
||||||
# If the removal succeeded, then assert that Cordelia is no longer subscribed.
|
# If the removal succeeded, then assert that Cordelia is no longer subscribed.
|
||||||
@@ -1040,6 +1050,17 @@ class StreamAdminTest(ZulipTestCase):
|
|||||||
self.assertEqual(len(json["removed"]), 1)
|
self.assertEqual(len(json["removed"]), 1)
|
||||||
self.assertEqual(len(json["not_removed"]), 0)
|
self.assertEqual(len(json["not_removed"]), 0)
|
||||||
|
|
||||||
|
def test_admin_remove_multiple_users_from_stream(self) -> None:
|
||||||
|
"""
|
||||||
|
If you're an admin, you can remove multiple users from a stream,
|
||||||
|
"""
|
||||||
|
result = self.attempt_unsubscribe_of_principal(
|
||||||
|
query_count=30, is_admin=True, is_subbed=True, invite_only=False,
|
||||||
|
other_user_subbed=True, unsubscribe_multiple_users=True)
|
||||||
|
json = self.assert_json_success(result)
|
||||||
|
self.assertEqual(len(json["removed"]), 2)
|
||||||
|
self.assertEqual(len(json["not_removed"]), 0)
|
||||||
|
|
||||||
def test_admin_remove_others_from_subbed_private_stream(self) -> None:
|
def test_admin_remove_others_from_subbed_private_stream(self) -> None:
|
||||||
"""
|
"""
|
||||||
If you're an admin, you can remove other people from private streams you
|
If you're an admin, you can remove other people from private streams you
|
||||||
@@ -1079,6 +1100,14 @@ class StreamAdminTest(ZulipTestCase):
|
|||||||
self.assertEqual(len(json["removed"]), 1)
|
self.assertEqual(len(json["removed"]), 1)
|
||||||
self.assertEqual(len(json["not_removed"]), 0)
|
self.assertEqual(len(json["not_removed"]), 0)
|
||||||
|
|
||||||
|
def test_admin_remove_multiple_users_from_stream_legacy_emails(self) -> None:
|
||||||
|
result = self.attempt_unsubscribe_of_principal(
|
||||||
|
query_count=30, is_admin=True, is_subbed=True, invite_only=False,
|
||||||
|
other_user_subbed=True, unsubscribe_multiple_users=True, using_legacy_emails=True)
|
||||||
|
json = self.assert_json_success(result)
|
||||||
|
self.assertEqual(len(json["removed"]), 2)
|
||||||
|
self.assertEqual(len(json["not_removed"]), 0)
|
||||||
|
|
||||||
def test_create_stream_policy_setting(self) -> None:
|
def test_create_stream_policy_setting(self) -> None:
|
||||||
"""
|
"""
|
||||||
When realm.create_stream_policy setting is Realm.POLICY_MEMBERS_ONLY then
|
When realm.create_stream_policy setting is Realm.POLICY_MEMBERS_ONLY then
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ def remove_subscriptions_backend(
|
|||||||
removing_someone_else = principals[0] != user_profile.id
|
removing_someone_else = principals[0] != user_profile.id
|
||||||
else:
|
else:
|
||||||
removing_someone_else = principals[0] != user_profile.email
|
removing_someone_else = principals[0] != user_profile.email
|
||||||
else: # nocoverage # TODO: Fix me.
|
else:
|
||||||
removing_someone_else = True
|
removing_someone_else = True
|
||||||
|
|
||||||
if removing_someone_else and not user_profile.is_realm_admin:
|
if removing_someone_else and not user_profile.is_realm_admin:
|
||||||
|
|||||||
Reference in New Issue
Block a user