tests: Create assertInHomePage helper function.

This commit is contained in:
Vishnu KS 2021-03-08 11:23:47 +00:00 committed by Tim Abbott
parent 06f1ea657e
commit 75a3059b57
1 changed files with 10 additions and 15 deletions

View File

@ -400,6 +400,9 @@ class HomeTest(ZulipTestCase):
result = self.client_get("/", dict(**kwargs)) result = self.client_get("/", dict(**kwargs))
return result return result
def assertInHomePage(self, string: str) -> bool:
return self.assertIn(string, self._get_home_page().content.decode("utf-8"))
def _sanity_check(self, result: HttpResponse) -> None: def _sanity_check(self, result: HttpResponse) -> None:
""" """
Use this for tests that are geared toward specific edge cases, but Use this for tests that are geared toward specific edge cases, but
@ -697,9 +700,7 @@ class HomeTest(ZulipTestCase):
user_profile.role = UserProfile.ROLE_REALM_ADMINISTRATOR user_profile.role = UserProfile.ROLE_REALM_ADMINISTRATOR
user_profile.save() user_profile.save()
result = self._get_home_page() self.assertInHomePage("Invite more users")
html = result.content.decode("utf-8")
self.assertIn("Invite more users", html)
def test_show_invites_for_guest_users(self) -> None: def test_show_invites_for_guest_users(self) -> None:
user_profile = self.example_user("polonius") user_profile = self.example_user("polonius")
@ -735,8 +736,7 @@ class HomeTest(ZulipTestCase):
tier=CustomerPlan.STANDARD, tier=CustomerPlan.STANDARD,
status=CustomerPlan.ENDED, status=CustomerPlan.ENDED,
) )
result_html = self._get_home_page().content.decode("utf-8") self.assertInHomePage("Billing")
self.assertIn("Billing", result_html)
# realm admin, with CustomerPlan -> no billing link # realm admin, with CustomerPlan -> no billing link
user.role = UserProfile.ROLE_REALM_ADMINISTRATOR user.role = UserProfile.ROLE_REALM_ADMINISTRATOR
@ -748,8 +748,7 @@ class HomeTest(ZulipTestCase):
user.role = UserProfile.ROLE_MEMBER user.role = UserProfile.ROLE_MEMBER
user.is_billing_admin = True user.is_billing_admin = True
user.save(update_fields=["role", "is_billing_admin"]) user.save(update_fields=["role", "is_billing_admin"])
result_html = self._get_home_page().content.decode("utf-8") self.assertInHomePage("Billing")
self.assertIn("Billing", result_html)
# member, with CustomerPlan -> no billing link # member, with CustomerPlan -> no billing link
user.is_billing_admin = False user.is_billing_admin = False
@ -774,8 +773,7 @@ class HomeTest(ZulipTestCase):
# billing admin, with sponsorship pending -> show billing link # billing admin, with sponsorship pending -> show billing link
customer.sponsorship_pending = True customer.sponsorship_pending = True
customer.save(update_fields=["sponsorship_pending"]) customer.save(update_fields=["sponsorship_pending"])
result_html = self._get_home_page().content.decode("utf-8") self.assertInHomePage("Billing")
self.assertIn("Billing", result_html)
# billing admin, no customer object -> make sure it doesn't crash # billing admin, no customer object -> make sure it doesn't crash
customer.delete() customer.delete()
@ -793,8 +791,7 @@ class HomeTest(ZulipTestCase):
# Show plans link to all other users if plan_type is LIMITED # Show plans link to all other users if plan_type is LIMITED
self.login("hamlet") self.login("hamlet")
result_html = self._get_home_page().content.decode("utf-8") self.assertInHomePage("Plans")
self.assertIn("Plans", result_html)
# Show plans link to no one, including admins, if SELF_HOSTED or STANDARD # Show plans link to no one, including admins, if SELF_HOSTED or STANDARD
do_change_plan_type(realm, Realm.SELF_HOSTED, acting_user=None) do_change_plan_type(realm, Realm.SELF_HOSTED, acting_user=None)
@ -810,12 +807,10 @@ class HomeTest(ZulipTestCase):
self.login("hamlet") self.login("hamlet")
result_html = self._get_home_page().content.decode("utf-8") self.assertInHomePage("Support Zulip")
self.assertIn("Support Zulip", result_html)
do_change_plan_type(realm, Realm.STANDARD_FREE, acting_user=None) do_change_plan_type(realm, Realm.STANDARD_FREE, acting_user=None)
result_html = self._get_home_page().content.decode("utf-8") self.assertInHomePage("Support Zulip")
self.assertIn("Support Zulip", result_html)
with self.settings(PROMOTE_SPONSORING_ZULIP=False): with self.settings(PROMOTE_SPONSORING_ZULIP=False):
result_html = self._get_home_page().content.decode("utf-8") result_html = self._get_home_page().content.decode("utf-8")