diff --git a/tools/test-backend b/tools/test-backend index e4ccc4467f..58d2ca14c4 100755 --- a/tools/test-backend +++ b/tools/test-backend @@ -96,7 +96,6 @@ not_yet_fully_covered = { 'zerver/tests/tests.py', # Getting views file coverage to 100% is a major project goal 'zerver/views/auth.py', - 'zerver/views/integrations.py', 'zerver/views/messages.py', 'zerver/views/report.py', 'zerver/views/home.py', diff --git a/zerver/tests/test_integrations.py b/zerver/tests/test_integrations.py index bc8f99e543..46661aaffd 100644 --- a/zerver/tests/test_integrations.py +++ b/zerver/tests/test_integrations.py @@ -10,7 +10,10 @@ from typing import Any from zproject.settings import DEPLOY_ROOT from zerver.lib.integrations import INTEGRATIONS, HUBOT_LOZENGES from zerver.lib.test_helpers import HostRequestMock -from zerver.views.integrations import add_api_uri_context +from zerver.views.integrations import ( + add_api_uri_context, + add_integrations_context, +) class IntegrationTest(TestCase): def test_check_if_every_integration_has_logo_that_exists(self): @@ -30,6 +33,7 @@ class IntegrationTest(TestCase): add_api_uri_context(context, HostRequestMock()) self.assertEqual(context["external_api_path_subdomain"], "testserver/api") self.assertEqual(context["external_api_uri_subdomain"], "http://testserver/api") + self.assertTrue(context["html_settings_links"]) @override_settings(REALMS_HAVE_SUBDOMAINS=True) def test_api_url_view_subdomains_base(self): @@ -38,6 +42,7 @@ class IntegrationTest(TestCase): add_api_uri_context(context, HostRequestMock()) self.assertEqual(context["external_api_path_subdomain"], "yourZulipDomain.testserver/api") self.assertEqual(context["external_api_uri_subdomain"], "http://yourZulipDomain.testserver/api") + self.assertFalse(context["html_settings_links"]) @override_settings(REALMS_HAVE_SUBDOMAINS=True) def test_api_url_view_subdomains_full(self): @@ -47,3 +52,26 @@ class IntegrationTest(TestCase): add_api_uri_context(context, request) self.assertEqual(context["external_api_path_subdomain"], "mysubdomain.testserver/api") self.assertEqual(context["external_api_uri_subdomain"], "http://mysubdomain.testserver/api") + self.assertTrue(context["html_settings_links"]) + + def test_integration_view_html_settings_links(self): + # type: () -> None + context = dict() + context['html_settings_links'] = False + add_integrations_context(context) + self.assertEqual( + context['settings_html'], + 'Zulip settings page') + self.assertEqual( + context['subscriptions_html'], + 'subscriptions page') + + context = dict() + context['html_settings_links'] = True + add_integrations_context(context) + self.assertEqual( + context['settings_html'], + 'Zulip settings page') + self.assertEqual( + context['subscriptions_html'], + 'subscriptions page') diff --git a/zerver/views/integrations.py b/zerver/views/integrations.py index 5c416b772a..a6431a49c7 100644 --- a/zerver/views/integrations.py +++ b/zerver/views/integrations.py @@ -80,27 +80,31 @@ class HelpView(ApiURLView): return result +def add_integrations_context(context): + # type: (Dict[str, Any]) -> None + alphabetical_sorted_integration = OrderedDict(sorted(INTEGRATIONS.items())) + alphabetical_sorted_hubot_lozenges = OrderedDict(sorted(HUBOT_LOZENGES.items())) + context['integrations_dict'] = alphabetical_sorted_integration + context['hubot_lozenges_dict'] = alphabetical_sorted_hubot_lozenges + + if context["html_settings_links"]: + settings_html = 'Zulip settings page' + subscriptions_html = 'subscriptions page' + else: + settings_html = 'Zulip settings page' + subscriptions_html = 'subscriptions page' + + context['settings_html'] = settings_html + context['subscriptions_html'] = subscriptions_html + + class IntegrationView(ApiURLView): template_name = 'zerver/integrations.html' def get_context_data(self, **kwargs): # type: (**Any) -> Dict[str, Any] context = super(IntegrationView, self).get_context_data(**kwargs) # type: Dict[str, Any] - alphabetical_sorted_integration = OrderedDict(sorted(INTEGRATIONS.items())) - alphabetical_sorted_hubot_lozenges = OrderedDict(sorted(HUBOT_LOZENGES.items())) - context['integrations_dict'] = alphabetical_sorted_integration - context['hubot_lozenges_dict'] = alphabetical_sorted_hubot_lozenges - - if context["html_settings_links"]: - settings_html = 'Zulip settings page' - subscriptions_html = 'subscriptions page' - else: - settings_html = 'Zulip settings page' - subscriptions_html = 'subscriptions page' - - context['settings_html'] = settings_html - context['subscriptions_html'] = subscriptions_html - + add_integrations_context(context) return context