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.

test_notifications: Update tests to cover the corner case properly.

Prakhar Pratyush3f6b41e4beef
diff --git a/zerver/tests/test_email_notifications.py b/zerver/tests/test_email_notifications.py
index 79e4d37f6ab..bace47ecd9c 100644
--- a/zerver/tests/test_email_notifications.py
+++ b/zerver/tests/test_email_notifications.py
@@ -21,6 +21,7 @@ from django_stubs_ext import StrPromise
from zerver.actions.create_user import do_create_user
from zerver.actions.user_groups import check_add_user_group
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.users import do_change_user_role
from zerver.lib.email_notifications import (
enqueue_welcome_emails,
@@ -34,7 +35,15 @@ from zerver.lib.email_notifications import (
)
from zerver.lib.send_email import FromAddress, deliver_scheduled_emails, send_custom_email
from zerver.lib.test_classes import ZulipTestCase
-from zerver.models import Realm, ScheduledEmail, UserMessage, UserProfile, get_realm, get_stream
+from zerver.models import (
+ Realm,
+ ScheduledEmail,
+ UserMessage,
+ UserProfile,
+ UserTopic,
+ get_realm,
+ get_stream,
+)
class TestCustomEmails(ZulipTestCase):
@@ -1960,6 +1969,17 @@ class TestMissedMessages(ZulipTestCase):
[{"message_id": personal_message_id, "trigger": "private_message"}],
)
+ # Hamlet FOLLOWS the topic.
+ # 'wildcard_mentions_notify' is disabled to verify the corner case when only
+ # 'enable_followed_topic_wildcard_mentions_notify' is enabled (True by default).
+ do_set_user_topic_visibility_policy(
+ hamlet,
+ get_stream("Denmark", hamlet.realm),
+ "test",
+ visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED,
+ )
+ do_change_user_setting(hamlet, "wildcard_mentions_notify", False, acting_user=None)
+
# Stream wildcard mention in followed topic should NOT soft reactivate the user
with self.soft_deactivate_and_check_long_term_idle(hamlet, expected=True):
mention = "@**all**"
@@ -1974,6 +1994,15 @@ class TestMissedMessages(ZulipTestCase):
],
)
+ # Reset
+ do_set_user_topic_visibility_policy(
+ hamlet,
+ get_stream("Denmark", hamlet.realm),
+ "test",
+ visibility_policy=UserTopic.VisibilityPolicy.INHERIT,
+ )
+ do_change_user_setting(hamlet, "wildcard_mentions_notify", True, acting_user=None)
+
# Stream Wildcard mention should NOT soft reactivate the user
with self.soft_deactivate_and_check_long_term_idle(hamlet, expected=True):
mention = "@**all**"
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index f46c4ad985d..346f88cf617 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -26,7 +26,8 @@ from analytics.models import InstallationCount, RealmCount
from zerver.actions.message_delete import do_delete_messages
from zerver.actions.message_flags import do_mark_stream_messages_as_read, do_update_message_flags
from zerver.actions.user_groups import check_add_user_group
-from zerver.actions.user_settings import do_regenerate_api_key
+from zerver.actions.user_settings import do_change_user_setting, do_regenerate_api_key
+from zerver.actions.user_topics import do_set_user_topic_visibility_policy
from zerver.lib.avatar import absolute_avatar_url
from zerver.lib.exceptions import JsonableError
from zerver.lib.push_notifications import (
@@ -71,6 +72,7 @@ from zerver.models import (
Stream,
Subscription,
UserMessage,
+ UserTopic,
get_client,
get_display_recipient,
get_realm,
@@ -1675,6 +1677,19 @@ class HandlePushNotificationTest(PushNotificationTest):
{"message_id": personal_message_id, "trigger": "private_message"},
)
+ # User FOLLOWS the topic.
+ # 'wildcard_mentions_notify' is disabled to verify the corner case when only
+ # 'enable_followed_topic_wildcard_mentions_notify' is enabled (True by default).
+ do_set_user_topic_visibility_policy(
+ self.user_profile,
+ get_stream("Denmark", self.user_profile.realm),
+ "test",
+ visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED,
+ )
+ do_change_user_setting(
+ self.user_profile, "wildcard_mentions_notify", False, acting_user=None
+ )
+
# Stream wildcard mention in followed topic should NOT soft reactivate the user
with self.soft_deactivate_and_check_long_term_idle(self.user_profile, expected=True):
mention = "@**all**"
@@ -1687,6 +1702,17 @@ class HandlePushNotificationTest(PushNotificationTest):
},
)
+ # Reset
+ do_set_user_topic_visibility_policy(
+ self.user_profile,
+ get_stream("Denmark", self.user_profile.realm),
+ "test",
+ visibility_policy=UserTopic.VisibilityPolicy.INHERIT,
+ )
+ do_change_user_setting(
+ self.user_profile, "wildcard_mentions_notify", True, acting_user=None
+ )
+
# Stream Wildcard mention should NOT soft reactivate the user
with self.soft_deactivate_and_check_long_term_idle(self.user_profile, expected=True):
mention = "@**all**"