refactor: Move receives_email_notifications tests to designated file.

This commit is contained in:
Abhijeet Prasad Bodas 2021-05-31 16:48:06 +05:30 committed by Tim Abbott
parent 3990b183ce
commit 44534ca47e
2 changed files with 41 additions and 18 deletions

View File

@ -21,7 +21,13 @@ from zerver.lib.email_notifications import (
)
from zerver.lib.send_email import FromAddress, send_custom_email
from zerver.lib.test_classes import ZulipTestCase
from zerver.models import ScheduledEmail, UserProfile, get_realm, get_stream
from zerver.models import (
ScheduledEmail,
UserProfile,
get_realm,
get_stream,
receives_offline_email_notifications,
)
class TestCustomEmails(ZulipTestCase):
@ -1212,3 +1218,37 @@ class TestMissedMessages(ZulipTestCase):
+ 'title="cloud with lightning and rain" style="height: 20px;">.</p>'
)
self.assertEqual(actual_output, expected_output)
class TestReceivesNotificationsFunctions(ZulipTestCase):
def test_receivers_offline_notifications_when_user_is_a_bot(self) -> None:
hamlet = self.example_user("hamlet")
hamlet.is_bot = True
hamlet.enable_offline_email_notifications = True
self.assertFalse(receives_offline_email_notifications(hamlet))
hamlet.enable_offline_email_notifications = False
self.assertFalse(receives_offline_email_notifications(hamlet))
hamlet.enable_offline_email_notifications = True
self.assertFalse(receives_offline_email_notifications(hamlet))
hamlet.enable_offline_email_notifications = False
self.assertFalse(receives_offline_email_notifications(hamlet))
def test_receivers_offline_notifications_when_user_is_not_a_bot(self) -> None:
hamlet = self.example_user("hamlet")
hamlet.is_bot = False
hamlet.enable_offline_email_notifications = True
self.assertTrue(receives_offline_email_notifications(hamlet))
hamlet.enable_offline_email_notifications = False
self.assertFalse(receives_offline_email_notifications(hamlet))
hamlet.enable_offline_email_notifications = True
self.assertTrue(receives_offline_email_notifications(hamlet))
hamlet.enable_offline_email_notifications = False
self.assertFalse(receives_offline_email_notifications(hamlet))

View File

@ -70,7 +70,6 @@ from zerver.models import (
get_client,
get_realm,
get_stream,
receives_offline_email_notifications,
receives_offline_push_notifications,
receives_online_push_notifications,
)
@ -2213,48 +2212,32 @@ class TestReceivesNotificationsFunctions(ZulipTestCase):
def test_receivers_offline_notifications_when_user_is_a_bot(self) -> None:
self.user.is_bot = True
self.user.enable_offline_email_notifications = True
self.user.enable_offline_push_notifications = True
self.assertFalse(receives_offline_push_notifications(self.user))
self.assertFalse(receives_offline_email_notifications(self.user))
self.user.enable_offline_email_notifications = False
self.user.enable_offline_push_notifications = False
self.assertFalse(receives_offline_push_notifications(self.user))
self.assertFalse(receives_offline_email_notifications(self.user))
self.user.enable_offline_email_notifications = True
self.user.enable_offline_push_notifications = False
self.assertFalse(receives_offline_push_notifications(self.user))
self.assertFalse(receives_offline_email_notifications(self.user))
self.user.enable_offline_email_notifications = False
self.user.enable_offline_push_notifications = True
self.assertFalse(receives_offline_push_notifications(self.user))
self.assertFalse(receives_offline_email_notifications(self.user))
def test_receivers_offline_notifications_when_user_is_not_a_bot(self) -> None:
self.user.is_bot = False
self.user.enable_offline_email_notifications = True
self.user.enable_offline_push_notifications = True
self.assertTrue(receives_offline_push_notifications(self.user))
self.assertTrue(receives_offline_email_notifications(self.user))
self.user.enable_offline_email_notifications = False
self.user.enable_offline_push_notifications = False
self.assertFalse(receives_offline_push_notifications(self.user))
self.assertFalse(receives_offline_email_notifications(self.user))
self.user.enable_offline_email_notifications = True
self.user.enable_offline_push_notifications = False
self.assertFalse(receives_offline_push_notifications(self.user))
self.assertTrue(receives_offline_email_notifications(self.user))
self.user.enable_offline_email_notifications = False
self.user.enable_offline_push_notifications = True
self.assertTrue(receives_offline_push_notifications(self.user))
self.assertFalse(receives_offline_email_notifications(self.user))
class TestPushNotificationsContent(ZulipTestCase):