2016-07-25 22:12:12 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
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-08-25 23:55:33 +02:00
|
|
|
def _test(self, url, expected_content, extra_strings=[],
|
|
|
|
landing_page=True):
|
|
|
|
# type: (str, str, List[str], bool) -> None
|
|
|
|
|
|
|
|
# Test the URL on the "zulip" subdomain
|
|
|
|
result = self.client_get(url, subdomain="zulip")
|
2017-07-13 01:28:38 +02:00
|
|
|
self.assertEqual(result.status_code, 200)
|
|
|
|
self.assertIn(expected_content, str(result.content))
|
|
|
|
for s in extra_strings:
|
|
|
|
self.assertIn(s, str(result.content))
|
2017-03-08 12:32:41 +01:00
|
|
|
|
2017-08-25 23:55:33 +02:00
|
|
|
# Test the URL on the root subdomain
|
|
|
|
result = self.client_get(url, subdomain="")
|
|
|
|
self.assertEqual(result.status_code, 200)
|
|
|
|
self.assertIn(expected_content, str(result.content))
|
|
|
|
for s in extra_strings:
|
|
|
|
self.assertIn(s, str(result.content))
|
|
|
|
|
|
|
|
if not landing_page:
|
|
|
|
return
|
|
|
|
# Test the URL on the root subdomain with the landing page setting
|
|
|
|
with self.settings(ROOT_DOMAIN_LANDING_PAGE=True):
|
|
|
|
result = self.client_get(url, subdomain="")
|
|
|
|
self.assertEqual(result.status_code, 200)
|
|
|
|
self.assertIn(expected_content, str(result.content))
|
|
|
|
for s in extra_strings:
|
|
|
|
self.assertIn(s, str(result.content))
|
|
|
|
|
2017-07-13 01:28:38 +02: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')
|
2017-07-26 19:08:16 +02:00
|
|
|
self._test('/apps/', 'Apps for every platform.')
|
2017-08-02 09:09:10 +02:00
|
|
|
self._test('/features/', 'Beautiful messaging')
|
2017-07-13 01:28:38 +02:00
|
|
|
self._test('/hello/', 'productive group chat')
|
2017-07-19 05:45:45 +02:00
|
|
|
self._test('/why-zulip/', 'all stakeholders can see and')
|
2017-07-13 01:28:38 +02:00
|
|
|
self._test('/for/open-source/', 'for open source projects')
|
2017-07-30 20:14:59 +02:00
|
|
|
self._test('/for/companies/', 'in a company')
|
2017-08-01 00:19:18 +02:00
|
|
|
self._test('/for/working-groups-and-communities/', 'standards bodies')
|
2017-05-15 20:42:04 +02:00
|
|
|
self._test('/plans/', 'Commercial support')
|
2017-07-13 01:28:38 +02:00
|
|
|
self._test('/integrations/',
|
|
|
|
'Over 60 native integrations.',
|
|
|
|
extra_strings=[
|
|
|
|
'And hundreds more through',
|
|
|
|
'Hubot',
|
|
|
|
'Zapier',
|
|
|
|
'IFTTT'
|
|
|
|
])
|
2017-07-18 01:58:23 +02:00
|
|
|
self._test('/integrations/doc-html/travis', 'Your Travis CI notifications may look like:')
|
2017-09-17 02:28:59 +02:00
|
|
|
self._test('/integrations/doc-html/googlesearch', 'This bot allows users to do Google search queries')
|
2017-08-25 23:55:33 +02:00
|
|
|
self._test('/devlogin/', 'Normal users', landing_page=False)
|
2017-07-13 01:28:38 +02:00
|
|
|
self._test('/devtools/', 'Useful development URLs')
|
|
|
|
self._test('/errors/404/', 'Page not found')
|
|
|
|
self._test('/errors/5xx/', 'Internal server error')
|
2017-09-24 00:44:29 +02:00
|
|
|
|
2017-10-03 02:04:32 +02:00
|
|
|
with self.settings(EMAIL_BACKEND='zproject.backends.EmailLogBackEnd'):
|
|
|
|
# For reaching full coverage for clear_emails function
|
|
|
|
result = self.client_get('/emails/clear/')
|
|
|
|
self.assertEqual(result.status_code, 302)
|
|
|
|
result = self.client_get(result['Location'])
|
|
|
|
self.assertIn('manually generate most of the emails by clicking', str(result.content))
|
|
|
|
|
|
|
|
result = self.client_get('/emails/generate/')
|
|
|
|
self.assertEqual(result.status_code, 302)
|
|
|
|
self.assertIn('emails', result['Location'])
|
|
|
|
|
|
|
|
self._test('/emails/', 'manually generate most of the emails by clicking')
|
|
|
|
self._test('/register/', 'Sign up for Zulip')
|
2017-03-08 12:32:41 +01:00
|
|
|
|
2017-07-18 01:58:23 +02:00
|
|
|
result = self.client_get('/integrations/doc-html/nonexistent_integration', follow=True)
|
2017-07-12 02:50:27 +02:00
|
|
|
self.assertEqual(result.status_code, 404)
|
|
|
|
|
2017-07-13 01:28:38 +02:00
|
|
|
result = self.client_get('/new-user/')
|
|
|
|
self.assertEqual(result.status_code, 301)
|
|
|
|
self.assertIn('hello', result['Location'])
|
2017-03-08 12:32:41 +01:00
|
|
|
|
2017-09-16 10:55:26 +02:00
|
|
|
result = self.client_get('/static/favicon.ico')
|
2017-07-13 01:28:38 +02:00
|
|
|
self.assertEqual(result.status_code, 200)
|
2017-07-14 03:38:12 +02:00
|
|
|
|
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
|
|
|
def test_api_url_view_subdomains_base(self):
|
2017-08-24 05:27:21 +02:00
|
|
|
# type: () -> None
|
|
|
|
context = dict() # type: Dict[str, Any]
|
|
|
|
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"])
|
|
|
|
|
2017-08-25 04:32:16 +02:00
|
|
|
@override_settings(ROOT_DOMAIN_LANDING_PAGE=True)
|
2017-08-24 05:27:21 +02:00
|
|
|
def test_api_url_view_subdomains_homepage_base(self):
|
2016-07-19 14:35:08 +02:00
|
|
|
# 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
|
|
|
|
|
|
|
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'],
|
2017-08-01 03:12:24 +02:00
|
|
|
'<a href="../../#settings">Zulip settings page</a>')
|
2017-02-28 07:18:45 +01:00
|
|
|
self.assertEqual(
|
|
|
|
context['subscriptions_html'],
|
2017-08-01 03:12:24 +02:00
|
|
|
'<a target="_blank" href="../../#streams">streams page</a>')
|
2017-03-08 12:33:50 +01:00
|
|
|
|
2017-07-27 03:05:45 +02:00
|
|
|
class AboutPageTest(ZulipTestCase):
|
2017-03-08 12:33:50 +01:00
|
|
|
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
|
2017-07-27 03:05:45 +02:00
|
|
|
result = self.client_get('/about/')
|
2017-03-08 12:33:50 +01:00
|
|
|
self.assert_in_success_response(
|
2017-07-27 03:05:45 +02:00
|
|
|
['Contributors', 'commits', '@timabbott'],
|
2017-03-08 12:33:50 +01:00
|
|
|
result
|
|
|
|
)
|
2017-03-08 12:43:45 +01:00
|
|
|
|
|
|
|
def test_split_by(self):
|
|
|
|
# type: () -> None
|
|
|
|
"""Utility function primarily used in authors page"""
|
2017-07-27 03:05:45 +02:00
|
|
|
flat_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
|
|
expected_result = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
|
|
|
self.assertEqual(split_by(flat_list, 3, None), expected_result)
|
2017-08-07 17:38:25 +02:00
|
|
|
|
|
|
|
class ConfigErrorTest(ZulipTestCase):
|
|
|
|
@override_settings(GOOGLE_OAUTH2_CLIENT_ID=None)
|
|
|
|
def test_google(self):
|
|
|
|
# type: () -> None
|
|
|
|
result = self.client_get("/accounts/login/google/")
|
|
|
|
self.assertEqual(result.status_code, 302)
|
|
|
|
self.assertEqual(result.url, '/config-error/google')
|
|
|
|
result = self.client_get(result.url)
|
|
|
|
self.assert_in_success_response(["GOOGLE_OAUTH2_CLIENT_ID"], result)
|
|
|
|
|
|
|
|
@override_settings(SOCIAL_AUTH_GITHUB_KEY=None)
|
|
|
|
def test_github(self):
|
|
|
|
# type: () -> None
|
|
|
|
result = self.client_get("/accounts/login/social/github")
|
|
|
|
self.assertEqual(result.status_code, 302)
|
|
|
|
self.assertEqual(result.url, '/config-error/github')
|
|
|
|
result = self.client_get(result.url)
|
|
|
|
self.assert_in_success_response(["SOCIAL_AUTH_GITHUB_KEY"], result)
|
|
|
|
|
|
|
|
@override_settings(SOCIAL_AUTH_GITHUB_KEY=None)
|
|
|
|
@override_settings(DEVELOPMENT=False)
|
|
|
|
def test_github_production_error(self):
|
|
|
|
# type: () -> None
|
|
|
|
"""Test the !DEVELOPMENT code path of config-error."""
|
|
|
|
result = self.client_get("/accounts/login/social/github")
|
|
|
|
self.assertEqual(result.status_code, 302)
|
|
|
|
self.assertEqual(result.url, '/config-error/github')
|
|
|
|
result = self.client_get(result.url)
|
|
|
|
self.assert_in_success_response(["/etc/zulip/zulip-secrets.conf"], result)
|
2017-08-17 18:27:36 +02:00
|
|
|
|
|
|
|
def test_smtp_error(self):
|
|
|
|
# type: () -> None
|
|
|
|
result = self.client_get("/config-error/smtp")
|
|
|
|
self.assertEqual(result.status_code, 200)
|
|
|
|
self.assert_in_success_response(["/var/log/zulip"], result)
|