test-backend: Raise zerver/views/integrations.py test coverage to 100%.

This commit is contained in:
Elliott Jin 2017-02-27 22:18:45 -08:00 committed by Tim Abbott
parent 2ea0430bf1
commit 11ba94f11a
3 changed files with 48 additions and 17 deletions

View File

@ -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',

View File

@ -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'],
'<a href="../#settings">Zulip settings page</a>')
self.assertEqual(
context['subscriptions_html'],
'<a target="_blank" href="../#subscriptions">subscriptions page</a>')

View File

@ -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 = '<a href="../#settings">Zulip settings page</a>'
subscriptions_html = '<a target="_blank" href="../#subscriptions">subscriptions page</a>'
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 = '<a href="../#settings">Zulip settings page</a>'
subscriptions_html = '<a target="_blank" href="../#subscriptions">subscriptions page</a>'
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