2016-07-25 22:12:12 +02:00
|
|
|
import os
|
2020-06-13 05:24:42 +02:00
|
|
|
from typing import Any, Dict, Sequence
|
2020-08-27 22:46:39 +02:00
|
|
|
from unittest import mock, skipUnless
|
2020-04-04 01:47:18 +02:00
|
|
|
from urllib.parse import urlsplit
|
2016-09-14 07:07:21 +02:00
|
|
|
|
2020-08-07 01:09:47 +02:00
|
|
|
import orjson
|
2019-08-28 06:04:21 +02:00
|
|
|
from django.conf import settings
|
2018-05-11 16:35:03 +02:00
|
|
|
from django.http import HttpResponse
|
2020-07-01 04:19:54 +02:00
|
|
|
from django.test import override_settings
|
2016-09-14 07:07:21 +02:00
|
|
|
|
2020-06-09 12:24:32 +02:00
|
|
|
from corporate.models import Customer
|
2017-11-15 22:58:34 +01:00
|
|
|
from zerver.lib.integrations import INTEGRATIONS
|
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
|
2018-08-27 12:43:00 +02:00
|
|
|
from zerver.models import Realm, get_realm
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.views.documentation import add_api_uri_context
|
|
|
|
|
2016-07-25 22:12:12 +02:00
|
|
|
|
2017-03-08 12:32:41 +01:00
|
|
|
class DocPageTest(ZulipTestCase):
|
2018-05-11 16:35:03 +02:00
|
|
|
def get_doc(self, url: str, subdomain: str) -> HttpResponse:
|
|
|
|
if url[0:23] == "/integrations/doc-html/":
|
2021-02-12 08:20:45 +01:00
|
|
|
return self.client_get(url, subdomain=subdomain, HTTP_X_REQUESTED_WITH="XMLHttpRequest")
|
2018-05-11 16:35:03 +02:00
|
|
|
return self.client_get(url, subdomain=subdomain)
|
|
|
|
|
2019-07-21 00:14:48 +02:00
|
|
|
def print_msg_if_error(self, url: str, response: HttpResponse) -> None: # nocoverage
|
|
|
|
if response.status_code == 200:
|
|
|
|
return
|
|
|
|
print("Error processing URL:", url)
|
2021-02-12 08:20:45 +01:00
|
|
|
if response.get("Content-Type") == "application/json":
|
2020-08-07 01:09:47 +02:00
|
|
|
content = orjson.loads(response.content)
|
2018-12-23 01:37:27 +01:00
|
|
|
print()
|
|
|
|
print("======================================================================")
|
2021-02-12 08:20:45 +01:00
|
|
|
print("ERROR: {}".format(content.get("msg")))
|
2018-12-23 01:37:27 +01:00
|
|
|
print()
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
def _test(
|
|
|
|
self,
|
|
|
|
url: str,
|
|
|
|
expected_content: str,
|
|
|
|
extra_strings: Sequence[str] = [],
|
|
|
|
landing_missing_strings: Sequence[str] = [],
|
|
|
|
landing_page: bool = True,
|
|
|
|
doc_html_str: bool = False,
|
|
|
|
) -> None:
|
2017-08-25 23:55:33 +02:00
|
|
|
|
2018-05-01 20:59:24 +02:00
|
|
|
# Test the URL on the "zephyr" subdomain
|
2018-05-11 16:35:03 +02:00
|
|
|
result = self.get_doc(url, subdomain="zephyr")
|
2019-07-21 00:14:48 +02:00
|
|
|
self.print_msg_if_error(url, result)
|
2018-12-23 01:37:27 +01:00
|
|
|
|
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))
|
2018-05-11 16:35:03 +02:00
|
|
|
if not doc_html_str:
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assert_in_success_response(
|
2021-04-21 00:46:14 +02:00
|
|
|
['<meta name="robots" content="noindex,nofollow" />'], result
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2017-03-08 12:32:41 +01:00
|
|
|
|
2017-08-25 23:55:33 +02:00
|
|
|
# Test the URL on the root subdomain
|
2018-05-11 16:35:03 +02:00
|
|
|
result = self.get_doc(url, subdomain="")
|
2019-07-21 00:14:48 +02:00
|
|
|
self.print_msg_if_error(url, result)
|
2018-12-23 01:37:27 +01:00
|
|
|
|
2017-08-25 23:55:33 +02:00
|
|
|
self.assertEqual(result.status_code, 200)
|
|
|
|
self.assertIn(expected_content, str(result.content))
|
2018-05-11 16:35:03 +02:00
|
|
|
if not doc_html_str:
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assert_in_success_response(
|
2021-04-21 00:46:14 +02:00
|
|
|
['<meta name="robots" content="noindex,nofollow" />'], result
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2018-05-01 20:59:24 +02:00
|
|
|
|
2017-08-25 23:55:33 +02:00
|
|
|
for s in extra_strings:
|
|
|
|
self.assertIn(s, str(result.content))
|
|
|
|
|
|
|
|
if not landing_page:
|
|
|
|
return
|
|
|
|
with self.settings(ROOT_DOMAIN_LANDING_PAGE=True):
|
2018-05-04 21:51:05 +02:00
|
|
|
# Test the URL on the root subdomain with the landing page setting
|
2018-05-11 16:35:03 +02:00
|
|
|
result = self.get_doc(url, subdomain="")
|
2019-07-21 00:14:48 +02:00
|
|
|
self.print_msg_if_error(url, result)
|
2018-12-23 01:37:27 +01:00
|
|
|
|
2017-08-25 23:55:33 +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-11-14 02:01:44 +01:00
|
|
|
for s in landing_missing_strings:
|
|
|
|
self.assertNotIn(s, str(result.content))
|
2018-05-11 16:35:03 +02:00
|
|
|
if not doc_html_str:
|
2020-08-14 19:51:11 +02:00
|
|
|
# Every page has a meta-description
|
|
|
|
self.assert_in_success_response(['<meta name="description" content="'], result)
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assert_not_in_success_response(
|
2021-04-21 00:46:14 +02:00
|
|
|
['<meta name="robots" content="noindex,nofollow" />'], result
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2017-08-25 23:55:33 +02:00
|
|
|
|
2018-05-04 21:51:05 +02:00
|
|
|
# Test the URL on the "zephyr" subdomain with the landing page setting
|
|
|
|
result = self.get_doc(url, subdomain="zephyr")
|
2019-07-21 00:14:48 +02:00
|
|
|
self.print_msg_if_error(url, result)
|
2018-12-23 01:37:27 +01:00
|
|
|
|
2018-05-04 21:51:05 +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))
|
|
|
|
if not doc_html_str:
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assert_in_success_response(
|
2021-04-21 00:46:14 +02:00
|
|
|
['<meta name="robots" content="noindex,nofollow" />'], result
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2018-05-04 21:51:05 +02:00
|
|
|
|
2019-05-16 22:38:53 +02:00
|
|
|
def test_api_doc_endpoints(self) -> None:
|
|
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
2021-02-12 08:20:45 +01:00
|
|
|
api_docs_dir = os.path.join(current_dir, "..", "..", "templates/zerver/api/")
|
2019-05-16 22:38:53 +02:00
|
|
|
files = os.listdir(api_docs_dir)
|
|
|
|
|
|
|
|
def _filter_func(fp: str) -> bool:
|
2021-02-12 08:20:45 +01:00
|
|
|
ignored_files = ["sidebar_index.md", "index.md", "missing.md"]
|
|
|
|
return fp.endswith(".md") and not fp.startswith(".") and fp not in ignored_files
|
2019-05-16 22:38:53 +02:00
|
|
|
|
|
|
|
files = list(filter(_filter_func, files))
|
|
|
|
|
|
|
|
for f in files:
|
2021-02-12 08:20:45 +01:00
|
|
|
endpoint = f"/api/{os.path.splitext(f)[0]}"
|
|
|
|
self._test(endpoint, "", doc_html_str=True)
|
2019-05-16 22:38:53 +02:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_doc_endpoints(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
self._test("/api/", "The Zulip API")
|
|
|
|
self._test("/api/api-keys", "be careful with it")
|
|
|
|
self._test("/api/installation-instructions", "No download required!")
|
|
|
|
self._test("/api/send-message", "steal away your hearts")
|
|
|
|
self._test("/api/render-message", "**foo**")
|
|
|
|
self._test("/api/get-streams", "include_public")
|
|
|
|
self._test("/api/get-stream-id", "The name of the stream to access.")
|
|
|
|
self._test("/api/get-subscriptions", "Get all streams that the user is subscribed to.")
|
|
|
|
self._test("/api/get-users", "client_gravatar")
|
|
|
|
self._test("/api/register-queue", "apply_markdown")
|
|
|
|
self._test("/api/get-events", "dont_block")
|
|
|
|
self._test("/api/delete-queue", "Delete a previously registered queue")
|
|
|
|
self._test("/api/update-message", "propagate_mode")
|
|
|
|
self._test("/api/get-own-user", "takes no parameters")
|
|
|
|
self._test("/api/subscribe", "authorization_errors_fatal")
|
|
|
|
self._test("/api/create-user", "zuliprc-admin")
|
|
|
|
self._test("/api/unsubscribe", "not_removed")
|
2020-08-27 22:46:39 +02:00
|
|
|
if settings.ZILENCER_ENABLED:
|
2021-02-12 08:20:45 +01:00
|
|
|
self._test("/team/", "industry veterans")
|
|
|
|
self._test("/history/", "Cambridge, Massachusetts")
|
2017-07-13 01:28:38 +02:00
|
|
|
# Test the i18n version of one of these pages.
|
2021-02-12 08:20:45 +01:00
|
|
|
self._test("/en/history/", "Cambridge, Massachusetts")
|
2020-08-27 22:46:39 +02:00
|
|
|
if settings.ZILENCER_ENABLED:
|
2021-02-12 08:20:45 +01:00
|
|
|
self._test("/apps/", "Apps for every platform.")
|
|
|
|
self._test("/features/", "Beautiful messaging")
|
docs: Add missing space to compound verbs “log in”, “set up”, etc.
Noun: backup, checkout, cleanup, login, logout, setup, shutdown, signup,
timeout.
Verb: back up, check out, clean up, log in, log out, set up, shut
down, sign up, time out.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-04-25 23:05:38 +02:00
|
|
|
self._test("/hello/", "Chat for distributed teams", landing_missing_strings=["Log in"])
|
2021-02-12 08:20:45 +01:00
|
|
|
self._test("/why-zulip/", "Why Zulip?")
|
|
|
|
self._test("/for/open-source/", "for open source projects")
|
|
|
|
self._test("/for/research/", "for researchers")
|
|
|
|
self._test("/for/companies/", "in a company")
|
|
|
|
self._test("/for/working-groups-and-communities/", "standards bodies")
|
|
|
|
self._test("/security/", "TLS encryption")
|
|
|
|
self._test("/devlogin/", "Normal users", landing_page=False)
|
|
|
|
self._test("/devtools/", "Useful development URLs")
|
|
|
|
self._test("/errors/404/", "Page not found")
|
|
|
|
self._test("/errors/5xx/", "Internal server error")
|
|
|
|
self._test("/emails/", "manually generate most of the emails by clicking")
|
2017-03-08 12:32:41 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
result = self.client_get(
|
2021-02-12 08:20:45 +01:00
|
|
|
"/integrations/doc-html/nonexistent_integration",
|
2021-02-12 08:19:30 +01:00
|
|
|
follow=True,
|
2021-02-12 08:20:45 +01:00
|
|
|
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2017-07-12 02:50:27 +02:00
|
|
|
self.assertEqual(result.status_code, 404)
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/new-user/")
|
2017-07-13 01:28:38 +02:00
|
|
|
self.assertEqual(result.status_code, 301)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertIn("hello", result["Location"])
|
2017-03-08 12:32:41 +01:00
|
|
|
|
2019-07-11 05:59:52 +02:00
|
|
|
def test_portico_pages_open_graph_metadata(self) -> None:
|
|
|
|
# Why Zulip
|
2021-02-12 08:20:45 +01:00
|
|
|
url = "/why-zulip/"
|
2021-04-21 00:46:14 +02:00
|
|
|
title = '<meta property="og:title" content="Team chat with first-class threading" />'
|
2019-07-11 05:59:52 +02:00
|
|
|
description = '<meta property="og:description" content="Most team chats are overwhelming'
|
|
|
|
self._test(url, title, doc_html_str=True)
|
|
|
|
self._test(url, description, doc_html_str=True)
|
|
|
|
|
|
|
|
# Features
|
2021-02-12 08:20:45 +01:00
|
|
|
url = "/features/"
|
2021-05-10 07:02:14 +02:00
|
|
|
title = '<meta property="og:title" content="Zulip features" />'
|
2019-07-11 05:59:52 +02:00
|
|
|
description = '<meta property="og:description" content="First class threading'
|
|
|
|
self._test(url, title, doc_html_str=True)
|
|
|
|
self._test(url, description, doc_html_str=True)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_integration_doc_endpoints(self) -> None:
|
2021-02-12 08:19:30 +01:00
|
|
|
self._test(
|
2021-02-12 08:20:45 +01:00
|
|
|
"/integrations/",
|
|
|
|
"native integrations.",
|
2021-02-12 08:19:30 +01:00
|
|
|
extra_strings=[
|
2021-02-12 08:20:45 +01:00
|
|
|
"And hundreds more through",
|
|
|
|
"Hubot",
|
|
|
|
"Zapier",
|
|
|
|
"IFTTT",
|
2021-02-12 08:19:30 +01:00
|
|
|
],
|
|
|
|
)
|
2017-11-11 00:41:55 +01:00
|
|
|
|
|
|
|
for integration in INTEGRATIONS.keys():
|
2021-02-12 08:20:45 +01:00
|
|
|
url = f"/integrations/doc-html/{integration}"
|
|
|
|
self._test(url, "", doc_html_str=True)
|
2017-11-11 00:41:55 +01:00
|
|
|
|
2019-06-15 07:19:57 +02:00
|
|
|
def test_integration_pages_open_graph_metadata(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
url = "/integrations/doc/github"
|
2021-04-21 00:46:14 +02:00
|
|
|
title = '<meta property="og:title" content="Connect GitHub to Zulip" />'
|
2019-06-15 07:19:57 +02:00
|
|
|
description = '<meta property="og:description" content="Zulip comes with over'
|
|
|
|
self._test(url, title, doc_html_str=True)
|
|
|
|
self._test(url, description, doc_html_str=True)
|
|
|
|
|
|
|
|
# Test category pages
|
2021-02-12 08:20:45 +01:00
|
|
|
url = "/integrations/communication"
|
2021-04-21 00:46:14 +02:00
|
|
|
title = '<meta property="og:title" content="Connect your Communication tools to Zulip" />'
|
2019-06-15 07:19:57 +02:00
|
|
|
description = '<meta property="og:description" content="Zulip comes with over'
|
|
|
|
self._test(url, title, doc_html_str=True)
|
|
|
|
self._test(url, description, doc_html_str=True)
|
2019-07-10 21:30:06 +02:00
|
|
|
|
|
|
|
# Test integrations page
|
2021-02-12 08:20:45 +01:00
|
|
|
url = "/integrations/"
|
2021-04-21 00:46:14 +02:00
|
|
|
title = '<meta property="og:title" content="Connect the tools you use to Zulip" />'
|
2019-07-10 21:30:06 +02:00
|
|
|
description = '<meta property="og:description" content="Zulip comes with over'
|
|
|
|
self._test(url, title, doc_html_str=True)
|
|
|
|
self._test(url, description, doc_html_str=True)
|
2019-06-15 07:19:57 +02:00
|
|
|
|
2018-05-11 16:35:03 +02:00
|
|
|
def test_doc_html_str_non_ajax_call(self) -> None:
|
|
|
|
# We don't need to test all the pages for 404
|
|
|
|
for integration in list(INTEGRATIONS.keys())[5]:
|
|
|
|
with self.settings(ROOT_DOMAIN_LANDING_PAGE=True):
|
2021-02-12 08:20:45 +01:00
|
|
|
url = f"/en/integrations/doc-html/{integration}"
|
2018-05-11 16:35:03 +02:00
|
|
|
result = self.client_get(url, subdomain="", follow=True)
|
|
|
|
self.assertEqual(result.status_code, 404)
|
|
|
|
result = self.client_get(url, subdomain="zephyr", follow=True)
|
|
|
|
self.assertEqual(result.status_code, 404)
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
url = f"/en/integrations/doc-html/{integration}"
|
2018-05-11 16:35:03 +02:00
|
|
|
result = self.client_get(url, subdomain="", follow=True)
|
|
|
|
self.assertEqual(result.status_code, 404)
|
|
|
|
result = self.client_get(url, subdomain="zephyr", follow=True)
|
|
|
|
self.assertEqual(result.status_code, 404)
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/integrations/doc-html/nonexistent_integration", follow=True)
|
2018-05-11 16:35:03 +02:00
|
|
|
self.assertEqual(result.status_code, 404)
|
2018-01-25 23:38:57 +01:00
|
|
|
|
2019-03-12 15:32:33 +01:00
|
|
|
def test_electron_detection(self) -> None:
|
|
|
|
result = self.client_get("/accounts/password/reset/")
|
2020-03-08 21:12:38 +01:00
|
|
|
# TODO: Ideally, this Mozilla would be the specific browser.
|
|
|
|
self.assertTrue('data-platform="Mozilla"' in result.content.decode("utf-8"))
|
2019-03-12 15:32:33 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
result = self.client_get("/accounts/password/reset/", HTTP_USER_AGENT="ZulipElectron/1.0.0")
|
2019-03-12 15:32:33 +01:00
|
|
|
self.assertTrue('data-platform="ZulipElectron"' in result.content.decode("utf-8"))
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-04-05 21:20:17 +02:00
|
|
|
class HelpTest(ZulipTestCase):
|
2018-09-15 06:17:04 +02:00
|
|
|
def test_help_settings_links(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/help/change-the-time-format")
|
2018-04-18 04:31:57 +02:00
|
|
|
self.assertEqual(result.status_code, 200)
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assertIn(
|
|
|
|
'Go to <a href="/#settings/display-settings">Display settings</a>', str(result.content)
|
|
|
|
)
|
2018-12-06 19:11:02 +01:00
|
|
|
# Check that the sidebar was rendered properly.
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertIn("Getting started with Zulip", str(result.content))
|
2018-04-18 04:31:57 +02:00
|
|
|
|
|
|
|
with self.settings(ROOT_DOMAIN_LANDING_PAGE=True):
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/help/change-the-time-format", subdomain="")
|
2018-04-18 04:31:57 +02:00
|
|
|
self.assertEqual(result.status_code, 200)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertIn("<strong>Display settings</strong>", str(result.content))
|
|
|
|
self.assertNotIn("/#settings", str(result.content))
|
2018-09-15 06:17:04 +02:00
|
|
|
|
2018-09-16 04:30:18 +02:00
|
|
|
def test_help_relative_links_for_gear(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/help/analytics")
|
2018-09-15 06:17:04 +02:00
|
|
|
self.assertIn('<a href="/stats">Statistics</a>', str(result.content))
|
|
|
|
self.assertEqual(result.status_code, 200)
|
|
|
|
|
|
|
|
with self.settings(ROOT_DOMAIN_LANDING_PAGE=True):
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/help/analytics", subdomain="")
|
2018-09-15 06:17:04 +02:00
|
|
|
self.assertEqual(result.status_code, 200)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertIn("<strong>Statistics</strong>", str(result.content))
|
|
|
|
self.assertNotIn("/stats", str(result.content))
|
2018-04-18 04:31:57 +02:00
|
|
|
|
2018-09-16 04:30:18 +02:00
|
|
|
def test_help_relative_links_for_stream(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/help/message-a-stream-by-email")
|
2018-09-16 04:30:18 +02:00
|
|
|
self.assertIn('<a href="/#streams/subscribed">Your streams</a>', str(result.content))
|
|
|
|
self.assertEqual(result.status_code, 200)
|
|
|
|
|
|
|
|
with self.settings(ROOT_DOMAIN_LANDING_PAGE=True):
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/help/message-a-stream-by-email", subdomain="")
|
2018-09-16 04:30:18 +02:00
|
|
|
self.assertEqual(result.status_code, 200)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertIn("<strong>Manage streams</strong>", str(result.content))
|
|
|
|
self.assertNotIn("/#streams", str(result.content))
|
2018-09-16 04:30:18 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-07-01 04:19:54 +02:00
|
|
|
class IntegrationTest(ZulipTestCase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_check_if_every_integration_has_logo_that_exists(self) -> None:
|
2016-07-25 22:12:12 +02:00
|
|
|
for integration in INTEGRATIONS.values():
|
2020-04-04 01:47:18 +02:00
|
|
|
path = urlsplit(integration.logo_url).path
|
|
|
|
self.assertTrue(os.path.isfile(settings.DEPLOY_ROOT + path), integration.name)
|
2016-11-23 18:58:59 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_api_url_view_subdomains_base(self) -> None:
|
2020-09-02 08:14:51 +02:00
|
|
|
context: Dict[str, Any] = {}
|
2017-08-24 05:27:21 +02:00
|
|
|
add_api_uri_context(context, HostRequestMock())
|
2017-10-30 22:04:15 +01:00
|
|
|
self.assertEqual(context["api_url_scheme_relative"], "testserver/api")
|
|
|
|
self.assertEqual(context["api_url"], "http://testserver/api")
|
2017-08-24 05:27:21 +02:00
|
|
|
self.assertTrue(context["html_settings_links"])
|
|
|
|
|
2017-08-25 04:32:16 +02:00
|
|
|
@override_settings(ROOT_DOMAIN_LANDING_PAGE=True)
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_api_url_view_subdomains_homepage_base(self) -> None:
|
2020-09-02 08:14:51 +02:00
|
|
|
context: Dict[str, Any] = {}
|
2016-07-19 14:35:08 +02:00
|
|
|
add_api_uri_context(context, HostRequestMock())
|
2017-10-30 22:04:15 +01:00
|
|
|
self.assertEqual(context["api_url_scheme_relative"], "yourZulipDomain.testserver/api")
|
|
|
|
self.assertEqual(context["api_url"], "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
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_api_url_view_subdomains_full(self) -> None:
|
2020-09-02 08:14:51 +02:00
|
|
|
context: 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)
|
2017-10-30 22:04:15 +01:00
|
|
|
self.assertEqual(context["api_url_scheme_relative"], "mysubdomain.testserver/api")
|
|
|
|
self.assertEqual(context["api_url"], "http://mysubdomain.testserver/api")
|
2017-02-28 07:18:45 +01:00
|
|
|
self.assertTrue(context["html_settings_links"])
|
|
|
|
|
2018-04-05 20:31:43 +02:00
|
|
|
def test_html_settings_links(self) -> None:
|
2020-09-02 08:14:51 +02:00
|
|
|
context: Dict[str, Any] = {}
|
2018-04-05 20:31:43 +02:00
|
|
|
with self.settings(ROOT_DOMAIN_LANDING_PAGE=True):
|
|
|
|
add_api_uri_context(context, HostRequestMock())
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(context["settings_html"], "Zulip settings page")
|
|
|
|
self.assertEqual(context["subscriptions_html"], "streams page")
|
2017-02-28 07:18:45 +01:00
|
|
|
|
2020-09-02 08:14:51 +02:00
|
|
|
context = {}
|
2018-04-05 20:31:43 +02:00
|
|
|
with self.settings(ROOT_DOMAIN_LANDING_PAGE=True):
|
|
|
|
add_api_uri_context(context, HostRequestMock(host="mysubdomain.testserver"))
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(context["settings_html"], '<a href="/#settings">Zulip settings page</a>')
|
2018-04-05 20:31:43 +02:00
|
|
|
self.assertEqual(
|
2021-02-12 08:20:45 +01:00
|
|
|
context["subscriptions_html"], '<a target="_blank" href="/#streams">streams page</a>'
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2018-04-05 20:31:43 +02:00
|
|
|
|
2020-09-02 08:14:51 +02:00
|
|
|
context = {}
|
2018-04-05 20:31:43 +02:00
|
|
|
add_api_uri_context(context, HostRequestMock())
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(context["settings_html"], '<a href="/#settings">Zulip settings page</a>')
|
2017-02-28 07:18:45 +01:00
|
|
|
self.assertEqual(
|
2021-02-12 08:20:45 +01:00
|
|
|
context["subscriptions_html"], '<a target="_blank" href="/#streams">streams page</a>'
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
|
|
|
|
2017-03-08 12:33:50 +01:00
|
|
|
|
2017-07-27 03:05:45 +02:00
|
|
|
class AboutPageTest(ZulipTestCase):
|
2020-08-27 22:46:39 +02:00
|
|
|
@skipUnless(settings.ZILENCER_ENABLED, "requires zilencer")
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_endpoint(self) -> None:
|
2020-04-08 22:08:04 +02:00
|
|
|
with self.settings(CONTRIBUTOR_DATA_FILE_PATH="zerver/tests/fixtures/authors.json"):
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/team/")
|
|
|
|
self.assert_in_success_response(["Our amazing community"], result)
|
|
|
|
self.assert_in_success_response(["2017-11-20"], result)
|
|
|
|
self.assert_in_success_response(["timabbott", "showell", "gnprice", "rishig"], result)
|
2020-04-07 19:27:07 +02:00
|
|
|
|
|
|
|
with mock.patch("zerver.views.portico.open", side_effect=FileNotFoundError) as m:
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/team/")
|
2020-04-07 19:27:07 +02:00
|
|
|
self.assertEqual(result.status_code, 200)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assert_in_success_response(["Never ran"], result)
|
2020-08-29 00:54:27 +02:00
|
|
|
m.assert_called_once()
|
2020-04-07 19:27:07 +02:00
|
|
|
|
|
|
|
with self.settings(ZILENCER_ENABLED=False):
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/team/")
|
2020-04-07 19:27:07 +02:00
|
|
|
self.assertEqual(result.status_code, 301)
|
2020-06-08 23:04:39 +02:00
|
|
|
self.assertEqual(result["Location"], "https://zulip.com/team/")
|
2017-03-08 12:43:45 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_split_by(self) -> None:
|
2017-03-08 12:43:45 +01:00
|
|
|
"""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
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-02-15 19:16:16 +01:00
|
|
|
class SmtpConfigErrorTest(ZulipTestCase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_smtp_error(self) -> None:
|
2017-08-17 18:27:36 +02:00
|
|
|
result = self.client_get("/config-error/smtp")
|
|
|
|
self.assertEqual(result.status_code, 200)
|
2017-10-25 01:58:05 +02:00
|
|
|
self.assert_in_success_response(["email configuration"], result)
|
2018-02-21 06:31:53 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-08-27 12:43:00 +02:00
|
|
|
class PlansPageTest(ZulipTestCase):
|
|
|
|
def test_plans_auth(self) -> None:
|
2020-07-15 22:18:32 +02:00
|
|
|
root_domain = ""
|
|
|
|
result = self.client_get("/plans/", subdomain=root_domain)
|
2018-08-27 12:43:00 +02:00
|
|
|
self.assert_in_success_response(["Sign up now"], result)
|
2020-07-15 22:18:32 +02:00
|
|
|
|
|
|
|
non_existent_domain = "moo"
|
|
|
|
result = self.client_get("/plans/", subdomain=non_existent_domain)
|
2019-03-12 01:56:52 +01:00
|
|
|
self.assertEqual(result.status_code, 404)
|
|
|
|
self.assert_in_response("does not exist", result)
|
2020-07-15 22:18:32 +02:00
|
|
|
|
2018-08-28 01:32:52 +02:00
|
|
|
realm = get_realm("zulip")
|
2018-10-24 06:09:01 +02:00
|
|
|
realm.plan_type = Realm.STANDARD_FREE
|
2018-08-28 01:32:52 +02:00
|
|
|
realm.save(update_fields=["plan_type"])
|
2018-08-27 12:43:00 +02:00
|
|
|
result = self.client_get("/plans/", subdomain="zulip")
|
|
|
|
self.assertEqual(result.status_code, 302)
|
2018-12-04 02:12:08 +01:00
|
|
|
self.assertEqual(result["Location"], "/accounts/login/?next=plans")
|
2020-07-15 22:18:32 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
guest_user = "polonius"
|
2020-07-15 22:18:32 +02:00
|
|
|
self.login(guest_user)
|
|
|
|
result = self.client_get("/plans/", subdomain="zulip", follow=True)
|
|
|
|
self.assertEqual(result.status_code, 404)
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
organization_member = "hamlet"
|
2020-07-15 22:18:32 +02:00
|
|
|
self.login(organization_member)
|
2018-08-27 12:43:00 +02:00
|
|
|
result = self.client_get("/plans/", subdomain="zulip")
|
2018-08-15 18:05:07 +02:00
|
|
|
self.assert_in_success_response(["Current plan"], result)
|
2018-08-27 12:43:00 +02:00
|
|
|
# Test root domain, with login on different domain
|
|
|
|
result = self.client_get("/plans/", subdomain="")
|
|
|
|
# TODO: works in manual testing, but I suspect something is funny in
|
|
|
|
# the test environment
|
|
|
|
# self.assert_in_success_response(["Sign up now"], result)
|
2018-08-15 18:05:07 +02:00
|
|
|
|
|
|
|
def test_CTA_text_by_plan_type(self) -> None:
|
|
|
|
sign_up_now = "Sign up now"
|
2018-10-24 06:09:01 +02:00
|
|
|
buy_standard = "Buy Standard"
|
2018-08-15 18:05:07 +02:00
|
|
|
current_plan = "Current plan"
|
2020-06-09 12:24:32 +02:00
|
|
|
sponsorship_pending = "Sponsorship pending"
|
2018-08-15 18:05:07 +02:00
|
|
|
|
|
|
|
# Root domain
|
|
|
|
result = self.client_get("/plans/", subdomain="")
|
2018-10-24 06:09:01 +02:00
|
|
|
self.assert_in_success_response([sign_up_now, buy_standard], result)
|
2020-06-09 12:24:32 +02:00
|
|
|
self.assert_not_in_success_response([current_plan, sponsorship_pending], result)
|
2018-08-15 18:05:07 +02:00
|
|
|
|
|
|
|
realm = get_realm("zulip")
|
2018-08-28 01:32:52 +02:00
|
|
|
realm.plan_type = Realm.SELF_HOSTED
|
|
|
|
realm.save(update_fields=["plan_type"])
|
|
|
|
|
2019-07-23 02:33:45 +02:00
|
|
|
with self.settings(PRODUCTION=True):
|
|
|
|
result = self.client_get("/plans/", subdomain="zulip")
|
|
|
|
self.assertEqual(result.status_code, 302)
|
2020-06-08 23:04:39 +02:00
|
|
|
self.assertEqual(result["Location"], "https://zulip.com/plans")
|
2019-07-23 02:33:45 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
self.login("iago")
|
2019-07-23 02:33:45 +02:00
|
|
|
|
|
|
|
# SELF_HOSTED should hide the local plans page, even if logged in
|
|
|
|
result = self.client_get("/plans/", subdomain="zulip")
|
|
|
|
self.assertEqual(result.status_code, 302)
|
2020-06-08 23:04:39 +02:00
|
|
|
self.assertEqual(result["Location"], "https://zulip.com/plans")
|
2018-08-28 01:32:52 +02:00
|
|
|
|
2019-07-23 02:33:45 +02:00
|
|
|
# But in the development environment, it renders a page
|
2018-08-28 01:32:52 +02:00
|
|
|
result = self.client_get("/plans/", subdomain="zulip")
|
2019-07-23 02:33:45 +02:00
|
|
|
self.assert_in_success_response([sign_up_now, buy_standard], result)
|
2020-06-09 12:24:32 +02:00
|
|
|
self.assert_not_in_success_response([current_plan, sponsorship_pending], result)
|
2018-08-15 18:05:07 +02:00
|
|
|
|
|
|
|
realm.plan_type = Realm.LIMITED
|
|
|
|
realm.save(update_fields=["plan_type"])
|
|
|
|
result = self.client_get("/plans/", subdomain="zulip")
|
2018-10-24 06:09:01 +02:00
|
|
|
self.assert_in_success_response([current_plan, buy_standard], result)
|
2020-06-09 12:24:32 +02:00
|
|
|
self.assert_not_in_success_response([sign_up_now, sponsorship_pending], result)
|
2018-08-15 18:05:07 +02:00
|
|
|
|
2018-10-24 06:09:01 +02:00
|
|
|
realm.plan_type = Realm.STANDARD_FREE
|
2018-08-15 18:05:07 +02:00
|
|
|
realm.save(update_fields=["plan_type"])
|
|
|
|
result = self.client_get("/plans/", subdomain="zulip")
|
|
|
|
self.assert_in_success_response([current_plan], result)
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assert_not_in_success_response(
|
|
|
|
[sign_up_now, buy_standard, sponsorship_pending], result
|
|
|
|
)
|
2018-08-15 18:05:07 +02:00
|
|
|
|
2018-10-24 06:09:01 +02:00
|
|
|
realm.plan_type = Realm.STANDARD
|
2018-08-15 18:05:07 +02:00
|
|
|
realm.save(update_fields=["plan_type"])
|
|
|
|
result = self.client_get("/plans/", subdomain="zulip")
|
|
|
|
self.assert_in_success_response([current_plan], result)
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assert_not_in_success_response(
|
|
|
|
[sign_up_now, buy_standard, sponsorship_pending], result
|
|
|
|
)
|
2020-06-09 12:24:32 +02:00
|
|
|
|
|
|
|
realm.plan_type = Realm.LIMITED
|
|
|
|
realm.save()
|
2021-02-12 08:19:30 +01:00
|
|
|
Customer.objects.create(
|
|
|
|
realm=get_realm("zulip"), stripe_customer_id="cus_id", sponsorship_pending=True
|
|
|
|
)
|
2020-06-09 12:24:32 +02:00
|
|
|
result = self.client_get("/plans/", subdomain="zulip")
|
|
|
|
self.assert_in_success_response([current_plan], result)
|
|
|
|
self.assert_in_success_response([current_plan, sponsorship_pending], result)
|
2018-10-24 06:09:01 +02:00
|
|
|
self.assert_not_in_success_response([sign_up_now, buy_standard], result)
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-01-29 20:41:23 +01:00
|
|
|
class AppsPageTest(ZulipTestCase):
|
|
|
|
def test_apps_view(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/apps")
|
2020-01-29 20:41:23 +01:00
|
|
|
self.assertEqual(result.status_code, 301)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertTrue(result["Location"].endswith("/apps/"))
|
2020-01-29 20:41:23 +01:00
|
|
|
|
|
|
|
with self.settings(ZILENCER_ENABLED=False):
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/apps/")
|
2020-01-29 20:41:23 +01:00
|
|
|
self.assertEqual(result.status_code, 301)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertTrue(result["Location"] == "https://zulip.com/apps/")
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2020-09-12 04:18:53 +02:00
|
|
|
with self.settings(ZILENCER_ENABLED=False):
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/apps/linux")
|
2020-09-12 04:18:53 +02:00
|
|
|
self.assertEqual(result.status_code, 301)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertTrue(result["Location"] == "https://zulip.com/apps/")
|
2020-09-12 04:18:53 +02:00
|
|
|
|
2020-01-29 20:41:23 +01:00
|
|
|
with self.settings(ZILENCER_ENABLED=True):
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/apps/")
|
2020-01-29 20:41:23 +01:00
|
|
|
self.assertEqual(result.status_code, 200)
|
2021-02-12 08:20:45 +01:00
|
|
|
html = result.content.decode("utf-8")
|
|
|
|
self.assertIn("Apps for every platform.", html)
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2020-10-22 13:39:55 +02:00
|
|
|
def test_app_download_link_view(self) -> None:
|
|
|
|
return_value = "https://github.com/zulip/zulip-desktop/releases/download/v5.4.3/Zulip-Web-Setup-5.4.3.exe"
|
2021-02-12 08:19:30 +01:00
|
|
|
with mock.patch(
|
|
|
|
"zerver.views.portico.get_latest_github_release_download_link_for_platform",
|
|
|
|
return_value=return_value,
|
|
|
|
) as m:
|
2020-10-22 13:39:55 +02:00
|
|
|
result = self.client_get("/apps/download/windows")
|
|
|
|
m.assert_called_once_with("windows")
|
|
|
|
self.assertEqual(result.status_code, 302)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertTrue(result["Location"] == return_value)
|
2020-10-22 13:39:55 +02:00
|
|
|
|
|
|
|
result = self.client_get("/apps/download/plan9")
|
|
|
|
self.assertEqual(result.status_code, 404)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-01-29 20:41:23 +01:00
|
|
|
class PrivacyTermsTest(ZulipTestCase):
|
|
|
|
def test_custom_tos_template(self) -> None:
|
|
|
|
response = self.client_get("/terms/")
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assert_in_success_response(
|
|
|
|
[
|
2021-02-12 08:20:45 +01:00
|
|
|
'Thanks for using our products and services ("Services"). ',
|
2021-02-12 08:19:30 +01:00
|
|
|
"By using our Services, you are agreeing to these terms",
|
|
|
|
],
|
|
|
|
response,
|
|
|
|
)
|
2020-01-29 20:41:23 +01:00
|
|
|
|
|
|
|
def test_custom_terms_of_service_template(self) -> None:
|
2021-02-12 08:19:30 +01:00
|
|
|
not_configured_message = (
|
2021-02-12 08:20:45 +01:00
|
|
|
"This installation of Zulip does not have a configured terms of service"
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2020-01-29 20:41:23 +01:00
|
|
|
with self.settings(TERMS_OF_SERVICE=None):
|
2021-02-12 08:20:45 +01:00
|
|
|
response = self.client_get("/terms/")
|
2020-01-29 20:41:23 +01:00
|
|
|
self.assert_in_success_response([not_configured_message], response)
|
2021-02-12 08:20:45 +01:00
|
|
|
with self.settings(TERMS_OF_SERVICE="zerver/tests/markdown/test_markdown.md"):
|
|
|
|
response = self.client_get("/terms/")
|
|
|
|
self.assert_in_success_response(["This is some <em>bold text</em>."], response)
|
2020-01-29 20:41:23 +01:00
|
|
|
self.assert_not_in_success_response([not_configured_message], response)
|
|
|
|
|
|
|
|
def test_custom_privacy_policy_template(self) -> None:
|
2021-02-12 08:19:30 +01:00
|
|
|
not_configured_message = (
|
2021-02-12 08:20:45 +01:00
|
|
|
"This installation of Zulip does not have a configured privacy policy"
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2020-01-29 20:41:23 +01:00
|
|
|
with self.settings(PRIVACY_POLICY=None):
|
2021-02-12 08:20:45 +01:00
|
|
|
response = self.client_get("/privacy/")
|
2020-01-29 20:41:23 +01:00
|
|
|
self.assert_in_success_response([not_configured_message], response)
|
2021-02-12 08:20:45 +01:00
|
|
|
with self.settings(PRIVACY_POLICY="zerver/tests/markdown/test_markdown.md"):
|
|
|
|
response = self.client_get("/privacy/")
|
|
|
|
self.assert_in_success_response(["This is some <em>bold text</em>."], response)
|
2020-01-29 20:41:23 +01:00
|
|
|
self.assert_not_in_success_response([not_configured_message], response)
|
|
|
|
|
|
|
|
def test_custom_privacy_policy_template_with_absolute_url(self) -> None:
|
|
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
2021-02-12 08:19:30 +01:00
|
|
|
abs_path = os.path.join(
|
2021-02-12 08:20:45 +01:00
|
|
|
current_dir, "..", "..", "templates/zerver/tests/markdown/test_markdown.md"
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2020-01-29 20:41:23 +01:00
|
|
|
with self.settings(PRIVACY_POLICY=abs_path):
|
2021-02-12 08:20:45 +01:00
|
|
|
response = self.client_get("/privacy/")
|
|
|
|
self.assert_in_success_response(["This is some <em>bold text</em>."], response)
|
2020-01-29 00:05:06 +01:00
|
|
|
|
|
|
|
def test_no_nav(self) -> None:
|
|
|
|
# Test that our ?nav=0 feature of /privacy and /terms,
|
|
|
|
# designed to comply with the Apple App Store draconian
|
|
|
|
# policies that ToS/Privacy pages linked from an iOS app have
|
|
|
|
# no links to the rest of the site if there's pricing
|
|
|
|
# information for anything elsewhere on the site.
|
|
|
|
response = self.client_get("/terms/")
|
|
|
|
self.assert_in_success_response(["Plans"], response)
|
|
|
|
|
2020-09-13 00:11:30 +02:00
|
|
|
response = self.client_get("/terms/", {"nav": "no"})
|
2020-01-29 00:05:06 +01:00
|
|
|
self.assert_not_in_success_response(["Plans"], response)
|
|
|
|
|
2020-09-13 00:11:30 +02:00
|
|
|
response = self.client_get("/privacy/", {"nav": "no"})
|
2020-01-29 00:05:06 +01:00
|
|
|
self.assert_not_in_success_response(["Plans"], response)
|