2016-07-25 22:12:12 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import os
|
2017-03-08 12:33:50 +01:00
|
|
|
import subprocess
|
2016-09-14 07:07:21 +02:00
|
|
|
|
2016-07-19 14:35:08 +02:00
|
|
|
from django.conf import settings
|
|
|
|
from django.test import TestCase, override_settings
|
2017-05-10 20:28:05 +02:00
|
|
|
from typing import Any, Dict, List
|
2016-09-14 07:07:21 +02:00
|
|
|
|
2016-07-25 22:12:12 +02:00
|
|
|
from zproject.settings import DEPLOY_ROOT
|
2016-11-23 18:58:59 +01:00
|
|
|
from zerver.lib.integrations import INTEGRATIONS, HUBOT_LOZENGES
|
2017-03-08 12:32:41 +01:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
2016-09-28 06:06:21 +02:00
|
|
|
from zerver.lib.test_helpers import HostRequestMock
|
2017-03-08 12:43:45 +01:00
|
|
|
from zerver.lib.utils import split_by
|
2017-02-28 07:18:45 +01:00
|
|
|
from zerver.views.integrations import (
|
|
|
|
add_api_uri_context,
|
|
|
|
add_integrations_context,
|
|
|
|
)
|
2016-07-25 22:12:12 +02:00
|
|
|
|
2017-03-08 12:32:41 +01:00
|
|
|
class DocPageTest(ZulipTestCase):
|
2017-05-10 20:28:05 +02:00
|
|
|
def _test(self, url, expected_content, extra_strings=[]):
|
|
|
|
# type: (str, str, List[str]) -> None
|
2017-03-08 12:32:41 +01:00
|
|
|
result = self.client_get(url)
|
|
|
|
self.assertEqual(result.status_code, 200)
|
|
|
|
self.assertIn(expected_content, str(result.content))
|
2017-05-10 20:28:05 +02:00
|
|
|
for s in extra_strings:
|
|
|
|
self.assertIn(s, str(result.content))
|
2017-03-08 12:32:41 +01:00
|
|
|
|
|
|
|
def test_doc_endpoints(self):
|
|
|
|
# type: () -> None
|
|
|
|
self._test('/api/', 'We hear you like APIs')
|
|
|
|
self._test('/api/endpoints/', 'pre-built API bindings for')
|
|
|
|
self._test('/about/', 'Cambridge, Massachusetts')
|
|
|
|
# Test the i18n version of one of these pages.
|
|
|
|
self._test('/en/about/', 'Cambridge, Massachusetts')
|
|
|
|
self._test('/apps/', 'Appsolutely')
|
|
|
|
self._test('/features/', 'Talk about multiple topics at once')
|
2017-05-10 02:23:38 +02:00
|
|
|
self._test('/hello/', 'productive group chat')
|
2017-06-19 00:47:02 +02:00
|
|
|
self._test('/for/open-source/', 'for open source projects')
|
2017-05-10 20:28:05 +02:00
|
|
|
self._test('/integrations/',
|
|
|
|
'require creating a Zulip bot',
|
|
|
|
extra_strings=[
|
|
|
|
# Ensure that the non-webhook integratins are in the HTML.
|
|
|
|
"zulip_git_config.py",
|
|
|
|
# Ensure that the webhook integrations are in the HTML.
|
|
|
|
"https://my.pingdom.com/reports/integration/settings",
|
|
|
|
])
|
2017-03-22 21:14:16 +01:00
|
|
|
self._test('/devlogin/', 'Normal users')
|
2017-06-14 02:01:01 +02:00
|
|
|
self._test('/devtools/', 'Useful development URLs')
|
2017-06-15 06:21:32 +02:00
|
|
|
self._test('/errors/404/', 'Page not found')
|
|
|
|
self._test('/errors/5xx/', 'Internal server error')
|
2017-06-10 05:23:19 +02:00
|
|
|
self._test('/emails/', 'Road Runner invited you to join Zulip')
|
2017-04-20 21:02:56 +02:00
|
|
|
self._test('/register/', 'Sign up for Zulip')
|
2017-03-08 12:32:41 +01:00
|
|
|
|
|
|
|
result = self.client_get('/new-user/')
|
|
|
|
self.assertEqual(result.status_code, 301)
|
|
|
|
self.assertIn('hello', result['Location'])
|
|
|
|
|
|
|
|
result = self.client_get('/robots.txt')
|
|
|
|
self.assertEqual(result.status_code, 301)
|
|
|
|
self.assertIn('static/robots.txt', result['Location'])
|
|
|
|
|
|
|
|
result = self.client_get('/static/robots.txt')
|
|
|
|
self.assertEqual(result.status_code, 200)
|
|
|
|
self.assertIn(
|
|
|
|
'Disallow: /',
|
|
|
|
''.join(str(x) for x in list(result.streaming_content))
|
|
|
|
)
|
|
|
|
|
2016-09-14 07:07:21 +02:00
|
|
|
class IntegrationTest(TestCase):
|
2016-07-25 22:12:12 +02:00
|
|
|
def test_check_if_every_integration_has_logo_that_exists(self):
|
2016-09-11 23:57:44 +02:00
|
|
|
# type: () -> None
|
2016-07-25 22:12:12 +02:00
|
|
|
for integration in INTEGRATIONS.values():
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(DEPLOY_ROOT, integration.logo)))
|
2016-09-14 07:07:21 +02:00
|
|
|
|
2016-11-23 18:58:59 +01:00
|
|
|
def test_check_if_every_hubot_lozenges_has_logo_that_exists(self):
|
|
|
|
# type: () -> None
|
|
|
|
for integration in HUBOT_LOZENGES.values():
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(DEPLOY_ROOT, integration.logo)))
|
|
|
|
|
2016-07-19 14:35:08 +02:00
|
|
|
@override_settings(REALMS_HAVE_SUBDOMAINS=False)
|
2016-09-14 07:07:21 +02:00
|
|
|
def test_api_url_view_base(self):
|
|
|
|
# type: () -> None
|
|
|
|
context = dict() # type: Dict[str, Any]
|
2016-09-28 06:06:21 +02:00
|
|
|
add_api_uri_context(context, HostRequestMock())
|
2016-10-06 01:42:24 +02:00
|
|
|
self.assertEqual(context["external_api_path_subdomain"], "testserver/api")
|
|
|
|
self.assertEqual(context["external_api_uri_subdomain"], "http://testserver/api")
|
2017-02-28 07:18:45 +01:00
|
|
|
self.assertTrue(context["html_settings_links"])
|
2016-07-19 14:35:08 +02:00
|
|
|
|
|
|
|
@override_settings(REALMS_HAVE_SUBDOMAINS=True)
|
|
|
|
def test_api_url_view_subdomains_base(self):
|
|
|
|
# type: () -> None
|
|
|
|
context = dict() # type: Dict[str, Any]
|
|
|
|
add_api_uri_context(context, HostRequestMock())
|
2016-10-06 01:42:24 +02:00
|
|
|
self.assertEqual(context["external_api_path_subdomain"], "yourZulipDomain.testserver/api")
|
|
|
|
self.assertEqual(context["external_api_uri_subdomain"], "http://yourZulipDomain.testserver/api")
|
2017-02-28 07:18:45 +01:00
|
|
|
self.assertFalse(context["html_settings_links"])
|
2016-07-19 14:35:08 +02:00
|
|
|
|
2016-10-06 01:42:24 +02:00
|
|
|
@override_settings(REALMS_HAVE_SUBDOMAINS=True)
|
2016-07-19 14:35:08 +02:00
|
|
|
def test_api_url_view_subdomains_full(self):
|
|
|
|
# type: () -> None
|
|
|
|
context = dict() # type: Dict[str, Any]
|
2016-10-06 01:42:24 +02:00
|
|
|
request = HostRequestMock(host="mysubdomain.testserver")
|
2016-07-19 14:35:08 +02:00
|
|
|
add_api_uri_context(context, request)
|
2016-10-06 01:42:24 +02:00
|
|
|
self.assertEqual(context["external_api_path_subdomain"], "mysubdomain.testserver/api")
|
|
|
|
self.assertEqual(context["external_api_uri_subdomain"], "http://mysubdomain.testserver/api")
|
2017-02-28 07:18:45 +01:00
|
|
|
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'],
|
2017-03-09 00:20:22 +01:00
|
|
|
'streams page')
|
2017-02-28 07:18:45 +01:00
|
|
|
|
|
|
|
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'],
|
2017-03-09 00:20:22 +01:00
|
|
|
'<a target="_blank" href="../#streams">streams page</a>')
|
2017-03-08 12:33:50 +01:00
|
|
|
|
|
|
|
class AuthorsPageTest(ZulipTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
# type: () -> None
|
|
|
|
""" Manual installation which did not execute `tools/provision`
|
|
|
|
would not have the `static/generated/github-contributors.json` fixture
|
|
|
|
file.
|
|
|
|
"""
|
|
|
|
# This block has unreliable test coverage due to the implicit
|
|
|
|
# caching here, so we exclude it from coverage.
|
|
|
|
if not os.path.exists(settings.CONTRIBUTORS_DATA):
|
|
|
|
# Copy the fixture file in `zerver/fixtures` to `static/generated`
|
|
|
|
update_script = os.path.join(os.path.dirname(__file__),
|
|
|
|
'../../tools/update-authors-json') # nocoverage
|
|
|
|
subprocess.check_call([update_script, '--use-fixture']) # nocoverage
|
|
|
|
|
|
|
|
def test_endpoint(self):
|
|
|
|
# type: () -> None
|
|
|
|
result = self.client_get('/authors/')
|
|
|
|
self.assert_in_success_response(
|
|
|
|
['Contributors', 'Statistic last Updated:', 'commits',
|
|
|
|
'@timabbott'],
|
|
|
|
result
|
|
|
|
)
|
2017-03-08 12:43:45 +01:00
|
|
|
|
|
|
|
def test_split_by(self):
|
|
|
|
# type: () -> None
|
|
|
|
"""Utility function primarily used in authors page"""
|
|
|
|
flat_list = [1, 2, 3, 4, 5, 6, 7]
|
|
|
|
expected_result = [[1, 2], [3, 4], [5, 6], [7, None]]
|
|
|
|
self.assertEqual(split_by(flat_list, 2, None), expected_result)
|