From 59790f37fc8ebcf6a000097c809ba8f35e831df8 Mon Sep 17 00:00:00 2001 From: Vishnu Ks Date: Wed, 23 Aug 2017 22:36:29 +0000 Subject: [PATCH] models: Create get_notifications_stream method in class Realm. --- zerver/models.py | 6 ++++++ zerver/tests/test_realm.py | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/zerver/models.py b/zerver/models.py index e35463fa2a..c2bf80ea35 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -232,6 +232,12 @@ class Realm(ModelReprMixin, models.Model): return "%s.%s" % (self.string_id, external_host) return external_host + def get_notifications_stream(self): + # type: () -> Optional[Realm] + if self.notifications_stream is not None and not self.notifications_stream.deactivated: + return self.notifications_stream + return None + @property def subdomain(self): # type: () -> Optional[Text] diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py index 2d39780bb3..c176f1c2bb 100644 --- a/zerver/tests/test_realm.py +++ b/zerver/tests/test_realm.py @@ -12,12 +12,13 @@ from zerver.lib.actions import ( do_change_is_admin, do_set_realm_property, do_deactivate_realm, + do_deactivate_stream, ) from zerver.lib.send_email import send_future_email from zerver.lib.test_classes import ZulipTestCase from zerver.lib.test_helpers import tornado_redirected_to_list -from zerver.models import get_realm, Realm, UserProfile, ScheduledEmail +from zerver.models import get_realm, Realm, UserProfile, ScheduledEmail, get_stream class RealmTest(ZulipTestCase): def assert_user_profile_cache_gets_new_name(self, user_profile, new_realm_name): @@ -202,6 +203,18 @@ class RealmTest(ZulipTestCase): realm = get_realm('zulip') self.assertNotEqual(realm.notifications_stream.id, invalid_notif_stream_id) + def test_get_default_notifications_stream(self): + # type: () -> None + realm = get_realm("zulip") + verona = get_stream("verona", realm) + realm.notifications_stream = verona + realm.save() + + notifications_stream = realm.get_notifications_stream() + self.assertEqual(notifications_stream, verona) + do_deactivate_stream(notifications_stream) + self.assertIsNone(realm.get_notifications_stream()) + def test_change_realm_default_language(self): # type: () -> None new_lang = "de"