Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tests: Use do_set_realm_property instead of direct database updates.
omkarrr2533f579a0be64fb
diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.pyindex 5d2971998eb..b4cd614f78c 100644--- a/zerver/tests/test_docs.py+++ b/zerver/tests/test_docs.py@@ -13,6 +13,7 @@ from django.utils.timezone import now as timezone_nowfrom corporate.models.customers import Customerfrom corporate.models.plans import CustomerPlan+from zerver.actions.realm_settings import do_set_realm_propertyfrom zerver.context_processors import get_apps_page_urlfrom zerver.lib.integrations import BOT_INTEGRATIONS, CATEGORIES, INTEGRATIONS, META_CATEGORYfrom zerver.lib.test_classes import ZulipTestCase@@ -360,14 +361,12 @@ class DocPageTest(ZulipTestCase):realm.want_advertise_in_communities_directory = Truerealm.save()- realm.description = ""- realm.save()+ do_set_realm_property(realm, "description", "", acting_user=None)result = self.client_get("/communities/")# Not shown because the realm has default description set.self.assert_not_in_success_response(["Zulip Dev"], result)- realm.description = "Some description"- realm.save()+ do_set_realm_property(realm, "description", "Some description", acting_user=None)self._test("/communities/", ["Open communities directory", "Zulip Dev", "Some description"])# No org with research type so research category not displayed.diff --git a/zerver/tests/test_invite.py b/zerver/tests/test_invite.pyindex 88b7a301bd6..9b4fc635550 100644--- a/zerver/tests/test_invite.py+++ b/zerver/tests/test_invite.py@@ -502,9 +502,9 @@ class InviteUserTest(InviteUserBase):# Remove some more warning flagsdo_change_realm_subdomain(realm, "reasonable", acting_user=None)- realm.description = "A real place"+ do_set_realm_property(realm, "description", "A real place", acting_user=None)realm.date_created = timezone_now() - timedelta(hours=2)- realm.save()+ realm.save(update_fields=["date_created"])# This is now more allowable (5x current 2 users)with self.assertLogs(level="INFO") as m:diff --git a/zerver/tests/test_middleware.py b/zerver/tests/test_middleware.pyindex 4d88ee11d98..9a47cf84fd3 100644--- a/zerver/tests/test_middleware.py+++ b/zerver/tests/test_middleware.py@@ -4,6 +4,7 @@ from unittest.mock import patchfrom bs4 import BeautifulSoupfrom django.http import HttpResponse+from zerver.actions.realm_settings import do_set_realm_propertyfrom zerver.lib.realm_icon import get_realm_icon_urlfrom zerver.lib.request import RequestNotesfrom zerver.lib.test_classes import ZulipTestCase@@ -129,8 +130,7 @@ class OpenGraphTest(ZulipTestCase):"* note-3\n\n""Enjoy!")- realm.description = description- realm.save(update_fields=["description"])+ do_set_realm_property(realm, "description", description, acting_user=None)self.check_title_and_description("/login/",diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.pyindex 69763c6eeb4..5fec82094f2 100644--- a/zerver/tests/test_realm.py+++ b/zerver/tests/test_realm.py@@ -486,8 +486,9 @@ class RealmTest(ZulipTestCase):rendered_description = get_realm_rendered_description(realm)text_description = get_realm_text_description(realm)- realm.description = "New description"- realm.save(update_fields=["description"])+ do_set_realm_property(+ realm, "description", "New description", acting_user=self.example_user("iago")+ )new_rendered_description = get_realm_rendered_description(realm)self.assertNotEqual(rendered_description, new_rendered_description)diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 442aafaafd2..43f797b533e 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -1212,8 +1212,7 @@ class LoginTest(ZulipTestCase):def test_zulip_default_context_does_not_load_inline_previews(self) -> None:realm = get_realm("zulip")description = "https://www.google.com/images/srpr/logo4w.png"- realm.description = description- realm.save(update_fields=["description"])+ do_set_realm_property(realm, "description", description, acting_user=None)response: HttpResponseBase = self.client_get("/login/")expected_response = """<p><a href="https://www.google.com/images/srpr/logo4w.png">\https://www.google.com/images/srpr/logo4w.png</a></p>"""