message: Add test coverage for 'set_visibility_policy_possible'.

This commit adds test coverage for the
'if user_profile.realm != message.get_realm():' block in
'set_visibility_policy_possible' function.

Currently, 'test_command_with_consented_message_id' adds the
test coverage for this code block. But we plan to remove that
test in the next commit as a part of removing 'react on consent
message' approach.

So, this commit explicitly adds code for the test coverage of
the concerned code block.
This commit is contained in:
Prakhar Pratyush 2024-09-24 14:18:39 +05:30 committed by Tim Abbott
parent 9d74abee0b
commit f67d7549de
1 changed files with 24 additions and 2 deletions

View File

@ -5,14 +5,14 @@ import orjson
import time_machine import time_machine
from django.utils.timezone import now as timezone_now 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_settings import do_change_user_setting
from zerver.actions.user_topics import do_set_user_topic_visibility_policy from zerver.actions.user_topics import do_set_user_topic_visibility_policy
from zerver.lib.stream_topic import StreamTopicTarget from zerver.lib.stream_topic import StreamTopicTarget
from zerver.lib.test_classes import ZulipTestCase from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import get_subscription from zerver.lib.test_helpers import get_subscription
from zerver.lib.user_topics import get_topic_mutes, topic_has_visibility_policy 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.constants import MAX_TOPIC_NAME_LENGTH
from zerver.models.streams import get_stream from zerver.models.streams import get_stream
@ -1025,6 +1025,28 @@ class AutomaticallyFollowTopicsTests(ZulipTestCase):
) )
self.assertEqual(user_ids, {cordelia.id}) 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: def test_automatically_follow_topic_on_participation_participate_in_poll(self) -> None:
iago = self.example_user("iago") iago = self.example_user("iago")
hamlet = self.example_user("hamlet") hamlet = self.example_user("hamlet")