Add unittests for receives_online_notifications function.

Fixes: #2645.
This commit is contained in:
Tomasz Kolek 2016-12-14 13:23:05 +01:00 committed by Tim Abbott
parent 92a72f7039
commit bec9ce755d
1 changed files with 27 additions and 1 deletions

View File

@ -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))