From bec9ce755d659e8596b6fe70111839426af6e6eb Mon Sep 17 00:00:00 2001 From: Tomasz Kolek Date: Wed, 14 Dec 2016 13:23:05 +0100 Subject: [PATCH] Add unittests for receives_online_notifications function. Fixes: #2645. --- zerver/tests/test_push_notifications.py | 28 ++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index 8d7368da54..ecdfd86bcd 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -9,7 +9,7 @@ from django.test import TestCase from django.conf import settings from zerver.models import PushDeviceToken, UserProfile, Message -from zerver.models import get_user_profile_by_email +from zerver.models import get_user_profile_by_email, receives_online_notifications from zerver.lib import push_notifications as apn from zerver.lib.test_classes import ( ZulipTestCase, @@ -387,3 +387,29 @@ class GCMFailureTest(GCMTest): c1 = call("GCM: Delivery to %s failed: 1" % (token,)) c2 = call("GCM: delivery needs a retry but ignoring") mock_warn.assert_has_calls([c1, c2], any_order=True) + +class TestReceivesOnlineNotificationsFunction(ZulipTestCase): + def setUp(self): + # type: () -> None + email = "cordelia@zulip.com" + self.user = get_user_profile_by_email(email) + + def test_receivers_online_notifications_when_user_is_a_bot(self): + # type: () -> None + self.user.is_bot = True + + self.user.enable_online_push_notifications = True + self.assertFalse(receives_online_notifications(self.user)) + + self.user.enable_online_push_notifications = False + self.assertFalse(receives_online_notifications(self.user)) + + def test_receivers_online_notifications_when_user_is_not_a_bot(self): + # type: () -> None + self.user.is_bot = False + + self.user.enable_online_push_notifications = True + self.assertTrue(receives_online_notifications(self.user)) + + self.user.enable_online_push_notifications = False + self.assertFalse(receives_online_notifications(self.user))