Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

message: Add test coverage for 'set_visibility_policy_possible'.

Prakhar Pratyushf67d7549de54
diff --git a/zerver/tests/test_user_topics.py b/zerver/tests/test_user_topics.py
index 9d316d6a876..e5c4a6c0359 100644
--- a/zerver/tests/test_user_topics.py
+++ b/zerver/tests/test_user_topics.py
@@ -5,14 +5,14 @@ import orjson
import time_machine
from django.utils.timezone import now as timezone_now
-from zerver.actions.reactions import check_add_reaction
+from zerver.actions.reactions import check_add_reaction, do_add_reaction
from zerver.actions.user_settings import do_change_user_setting
from zerver.actions.user_topics import do_set_user_topic_visibility_policy
from zerver.lib.stream_topic import StreamTopicTarget
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import get_subscription
from zerver.lib.user_topics import get_topic_mutes, topic_has_visibility_policy
-from zerver.models import UserProfile, UserTopic
+from zerver.models import Message, Reaction, UserProfile, UserTopic
from zerver.models.constants import MAX_TOPIC_NAME_LENGTH
from zerver.models.streams import get_stream
@@ -1025,6 +1025,28 @@ class AutomaticallyFollowTopicsTests(ZulipTestCase):
)
self.assertEqual(user_ids, {cordelia.id})
+ # Add test coverage for 'should_change_visibility_policy' when
+ # user from a different realm reacted to the message.
+ starnine_mit = self.mit_user("starnine")
+ do_change_user_setting(
+ starnine_mit,
+ "automatically_follow_topics_policy",
+ UserProfile.AUTOMATICALLY_CHANGE_VISIBILITY_POLICY_ON_PARTICIPATION,
+ acting_user=None,
+ )
+ do_add_reaction(
+ user_profile=starnine_mit,
+ message=Message.objects.get(id=message_id),
+ emoji_name="outbox",
+ emoji_code="1f4e4",
+ reaction_type=Reaction.UNICODE_EMOJI,
+ )
+
+ user_ids = stream_topic_target.user_ids_with_visibility_policy(
+ UserTopic.VisibilityPolicy.FOLLOWED
+ )
+ self.assertNotIn(starnine_mit.id, user_ids)
+
def test_automatically_follow_topic_on_participation_participate_in_poll(self) -> None:
iago = self.example_user("iago")
hamlet = self.example_user("hamlet")