From 420ca5a47034891fcd0d125f0a6ceceb504b0a7d Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 24 Oct 2017 12:26:36 -0700 Subject: [PATCH] tests: Test out-of-stream mentions. --- zerver/tests/test_messages.py | 84 +++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/zerver/tests/test_messages.py b/zerver/tests/test_messages.py index 2845fa260e..e7d99cb10f 100644 --- a/zerver/tests/test_messages.py +++ b/zerver/tests/test_messages.py @@ -602,6 +602,90 @@ class StreamMessagesTest(ZulipTestCase): message = most_recent_message(user_profile) assert(UserMessage.objects.get(user_profile=user_profile, message=message).flags.mentioned.is_set) + def test_unsub_mention(self): + # type: () -> None + cordelia = self.example_user('cordelia') + hamlet = self.example_user('hamlet') + + stream_name = 'Test Stream' + + self.subscribe(hamlet, stream_name) + + UserMessage.objects.filter( + user_profile=cordelia + ).delete() + + def mention_cordelia(): + # type: () -> None + content = 'test @**Cordelia Lear** rules' + + self.send_message( + hamlet.email, + stream_name, + Recipient.STREAM, + content=content + ) + + def num_cordelia_messages(): + # type: () -> int + return UserMessage.objects.filter( + user_profile=cordelia + ).count() + + mention_cordelia() + + self.assertEqual(0, num_cordelia_messages()) + + # Make sure test isn't too brittle-subscribing + # Cordelia and mentioning her should give her a + # message. + self.subscribe(cordelia, stream_name) + mention_cordelia() + self.assertEqual(1, num_cordelia_messages()) + + def test_message_bot_mentions(self): + # type: () -> None + cordelia = self.example_user('cordelia') + hamlet = self.example_user('hamlet') + realm = hamlet.realm + + stream_name = 'Test Stream' + + self.subscribe(hamlet, stream_name) + + normal_bot = do_create_user( + email='normal-bot@zulip.com', + password='', + realm=realm, + full_name='Normal Bot', + short_name='', + active=True, + bot_type=UserProfile.DEFAULT_BOT, + bot_owner=cordelia, + ) + + UserMessage.objects.filter( + user_profile=normal_bot + ).delete() + + content = 'test @**Normal Bot** rules' + + self.send_message( + hamlet.email, + stream_name, + Recipient.STREAM, + content=content + ) + + # As of now, we don't support mentioning + # bots who aren't subscribed. + self.assertEqual( + UserMessage.objects.filter( + user_profile=normal_bot + ).count(), + 0 + ) + def test_stream_message_mirroring(self): # type: () -> None from zerver.lib.actions import do_change_is_admin