mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
tests: Improve tests for checking permissions to update channel privacy.
This commit updates check_channel_privacy_update to use do_change_stream_permission for setting the stream privacy to its old state so that we do that in a reliable way and can avoid bugs in future.
This commit is contained in:
@@ -934,12 +934,18 @@ class ChannelAdministerPermissionTest(ZulipTestCase):
|
|||||||
) -> None:
|
) -> None:
|
||||||
stream = get_stream("test_stream", user.realm)
|
stream = get_stream("test_stream", user.realm)
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
|
old_values = {
|
||||||
|
"invite_only": stream.invite_only,
|
||||||
|
"is_web_public": stream.is_web_public,
|
||||||
|
"history_public_to_subscribers": stream.history_public_to_subscribers,
|
||||||
|
}
|
||||||
|
|
||||||
if property_name == "invite_only":
|
if property_name == "invite_only":
|
||||||
data["is_private"] = orjson.dumps(new_value).decode()
|
data["is_private"] = orjson.dumps(new_value).decode()
|
||||||
else:
|
else:
|
||||||
data[property_name] = orjson.dumps(new_value).decode()
|
data[property_name] = orjson.dumps(new_value).decode()
|
||||||
|
|
||||||
old_value = getattr(stream, property_name)
|
|
||||||
result = self.api_patch(user, f"/api/v1/streams/{stream.id}", info=data)
|
result = self.api_patch(user, f"/api/v1/streams/{stream.id}", info=data)
|
||||||
|
|
||||||
if error_msg is not None:
|
if error_msg is not None:
|
||||||
@@ -951,14 +957,11 @@ class ChannelAdministerPermissionTest(ZulipTestCase):
|
|||||||
self.assertEqual(getattr(stream, property_name), new_value)
|
self.assertEqual(getattr(stream, property_name), new_value)
|
||||||
|
|
||||||
# Reset to original value.
|
# Reset to original value.
|
||||||
setattr(stream, property_name, old_value)
|
do_change_stream_permission(
|
||||||
stream.save(update_fields=[property_name])
|
stream,
|
||||||
|
**old_values,
|
||||||
# Reset history_public_to_subscribers field when stream
|
acting_user=self.admin,
|
||||||
# is changed from private to public.
|
)
|
||||||
if not stream.invite_only and not stream.history_public_to_subscribers:
|
|
||||||
stream.history_public_to_subscribers = True
|
|
||||||
stream.save(update_fields=["history_public_to_subscribers"])
|
|
||||||
|
|
||||||
def do_test_updating_channel_privacy(self, property_name: str, new_value: bool) -> None:
|
def do_test_updating_channel_privacy(self, property_name: str, new_value: bool) -> None:
|
||||||
hamlet = self.example_user("hamlet")
|
hamlet = self.example_user("hamlet")
|
||||||
|
|||||||
Reference in New Issue
Block a user