Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tests: Create assertNotInHomePage helper function.
Vishnu KSbbcf39630301
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.pyindex 709ae7bda98..54bd3c60975 100644--- a/zerver/tests/test_home.py+++ b/zerver/tests/test_home.py@@ -403,6 +403,9 @@ class HomeTest(ZulipTestCase):def assertInHomePage(self, string: str) -> bool:return self.assertIn(string, self._get_home_page().content.decode("utf-8"))+ def assertNotInHomePage(self, string: str) -> bool:+ return self.assertNotIn(string, self._get_home_page().content.decode("utf-8"))+def _sanity_check(self, result: HttpResponse) -> None:"""Use this for tests that are geared toward specific edge cases, but@@ -694,9 +697,7 @@ class HomeTest(ZulipTestCase):self.login_user(user_profile)self.assertFalse(user_profile.is_realm_admin)- result = self._get_home_page()- html = result.content.decode("utf-8")- self.assertNotIn("Invite more users", html)+ self.assertNotInHomePage("Invite more users")user_profile.role = UserProfile.ROLE_REALM_ADMINISTRATORuser_profile.save()@@ -712,9 +713,7 @@ class HomeTest(ZulipTestCase):self.login_user(user_profile)self.assertFalse(user_profile.is_realm_admin)self.assertEqual(get_realm("zulip").invite_to_realm_policy, Realm.POLICY_MEMBERS_ONLY)- result = self._get_home_page()- html = result.content.decode("utf-8")- self.assertNotIn("Invite more users", html)+ self.assertNotInHomePage("Invite more users")def test_show_billing(self) -> None:customer = Customer.objects.create(realm=get_realm("zulip"), stripe_customer_id="cus_id")@@ -724,8 +723,7 @@ class HomeTest(ZulipTestCase):user.role = UserProfile.ROLE_REALM_OWNERuser.save(update_fields=["role"])self.login_user(user)- result_html = self._get_home_page().content.decode("utf-8")- self.assertNotIn("Billing", result_html)+ self.assertNotInHomePage("Billing")# realm owner, with inactive CustomerPlan -> show billing linkCustomerPlan.objects.create(@@ -741,8 +739,7 @@ class HomeTest(ZulipTestCase):# realm admin, with CustomerPlan -> no billing linkuser.role = UserProfile.ROLE_REALM_ADMINISTRATORuser.save(update_fields=["role"])- result_html = self._get_home_page().content.decode("utf-8")- self.assertNotIn("Billing", result_html)+ self.assertNotInHomePage("Billing")# billing admin, with CustomerPlan -> show billing linkuser.role = UserProfile.ROLE_MEMBER@@ -753,22 +750,19 @@ class HomeTest(ZulipTestCase):# member, with CustomerPlan -> no billing linkuser.is_billing_admin = Falseuser.save(update_fields=["is_billing_admin"])- result_html = self._get_home_page().content.decode("utf-8")- self.assertNotIn("Billing", result_html)+ self.assertNotInHomePage("Billing")# guest, with CustomerPlan -> no billing linkuser.role = UserProfile.ROLE_GUESTuser.save(update_fields=["role"])- result_html = self._get_home_page().content.decode("utf-8")- self.assertNotIn("Billing", result_html)+ self.assertNotInHomePage("Billing")# billing admin, but no CustomerPlan -> no billing linkuser.role = UserProfile.ROLE_MEMBERuser.is_billing_admin = Trueuser.save(update_fields=["role", "is_billing_admin"])CustomerPlan.objects.all().delete()- result_html = self._get_home_page().content.decode("utf-8")- self.assertNotIn("Billing", result_html)+ self.assertNotInHomePage("Billing")# billing admin, with sponsorship pending -> show billing linkcustomer.sponsorship_pending = True@@ -786,8 +780,7 @@ class HomeTest(ZulipTestCase):# Don't show plans to guest usersself.login("polonius")do_change_plan_type(realm, Realm.LIMITED, acting_user=None)- result_html = self._get_home_page().content.decode("utf-8")- self.assertNotIn("Plans", result_html)+ self.assertNotInHomePage("Plans")# Show plans link to all other users if plan_type is LIMITEDself.login("hamlet")@@ -795,12 +788,10 @@ class HomeTest(ZulipTestCase):# Show plans link to no one, including admins, if SELF_HOSTED or STANDARDdo_change_plan_type(realm, Realm.SELF_HOSTED, acting_user=None)- result_html = self._get_home_page().content.decode("utf-8")- self.assertNotIn("Plans", result_html)+ self.assertNotInHomePage("Plans")do_change_plan_type(realm, Realm.STANDARD, acting_user=None)- result_html = self._get_home_page().content.decode("utf-8")- self.assertNotIn("Plans", result_html)+ self.assertNotInHomePage("Plans")def test_show_support_zulip(self) -> None:realm = get_realm("zulip")@@ -813,16 +804,13 @@ class HomeTest(ZulipTestCase):self.assertInHomePage("Support Zulip")with self.settings(PROMOTE_SPONSORING_ZULIP=False):- result_html = self._get_home_page().content.decode("utf-8")- self.assertNotIn("Support Zulip", result_html)+ self.assertNotInHomePage("Support Zulip")do_change_plan_type(realm, Realm.LIMITED, acting_user=None)- result_html = self._get_home_page().content.decode("utf-8")- self.assertNotIn("Support Zulip", result_html)+ self.assertNotInHomePage("Support Zulip")do_change_plan_type(realm, Realm.STANDARD, acting_user=None)- result_html = self._get_home_page().content.decode("utf-8")- self.assertNotIn("Support Zulip", result_html)+ self.assertNotInHomePage("Support Zulip")def test_desktop_home(self) -> None:self.login("hamlet")