2016-07-25 22:12:12 +02:00
|
|
|
import os
|
2021-05-25 04:02:58 +02:00
|
|
|
import re
|
2022-06-08 04:52:09 +02:00
|
|
|
from typing import TYPE_CHECKING, 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
|
2020-07-01 04:19:54 +02:00
|
|
|
from django.test import override_settings
|
2020-10-08 16:22:59 +02:00
|
|
|
from django.utils.timezone import now as timezone_now
|
2016-09-14 07:07:21 +02:00
|
|
|
|
2020-10-08 16:22:59 +02:00
|
|
|
from corporate.models import Customer, CustomerPlan
|
2021-06-16 10:23:05 +02:00
|
|
|
from zerver.context_processors import get_apps_page_url
|
2022-09-08 13:36:05 +02:00
|
|
|
from zerver.lib.integrations import CATEGORIES, INTEGRATIONS, META_CATEGORY
|
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
|
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
|
|
|
|
|
2022-06-08 04:52:09 +02:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from django.test.client import _MonkeyPatchedWSGIResponse as TestHttpResponse
|
|
|
|
|
2016-07-25 22:12:12 +02:00
|
|
|
|
2017-03-08 12:32:41 +01:00
|
|
|
class DocPageTest(ZulipTestCase):
|
2022-06-08 04:52:09 +02:00
|
|
|
def get_doc(self, url: str, subdomain: str) -> "TestHttpResponse":
|
2018-05-11 16:35:03 +02:00
|
|
|
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)
|
|
|
|
|
2022-06-08 04:52:09 +02:00
|
|
|
def print_msg_if_error(self, url: str, response: "TestHttpResponse") -> None: # nocoverage
|
2019-07-21 00:14:48 +02:00
|
|
|
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:
|
2022-09-05 15:43:29 +02:00
|
|
|
# Confirm page has the following HTML elements:
|
|
|
|
self.assert_in_success_response(
|
|
|
|
[
|
|
|
|
"<title>",
|
|
|
|
'<meta name="description" content="',
|
|
|
|
'<meta property="og:title" content="',
|
|
|
|
'<meta property="og: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:
|
2021-05-25 04:02:58 +02:00
|
|
|
# We extract the set of /api/ endpoints to check by parsing
|
|
|
|
# the /api/ page sidebar for links starting with /api/.
|
2021-08-02 23:18:03 +02:00
|
|
|
api_page_raw = str(self.client_get("/api/").content)
|
2021-05-25 04:02:58 +02:00
|
|
|
ENDPOINT_REGEXP = re.compile(r"href=\"/api/\s*(.*?)\"")
|
|
|
|
endpoint_list_set = set(re.findall(ENDPOINT_REGEXP, api_page_raw))
|
|
|
|
endpoint_list = [f"/api/{endpoint}" for endpoint in endpoint_list_set]
|
|
|
|
# Validate that the parsing logic isn't broken, since if it
|
|
|
|
# broke, the below would become a noop.
|
2021-07-13 19:42:37 +02:00
|
|
|
self.assertGreater(len(endpoint_list), 70)
|
2021-05-25 04:02:58 +02:00
|
|
|
|
|
|
|
for endpoint in endpoint_list:
|
2021-02-12 08:20:45 +01:00
|
|
|
self._test(endpoint, "", doc_html_str=True)
|
2019-05-16 22:38:53 +02:00
|
|
|
|
2021-05-25 04:02:58 +02:00
|
|
|
result = self.client_get(
|
|
|
|
"/api/nonexistent-page",
|
|
|
|
follow=True,
|
|
|
|
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
|
|
|
|
)
|
|
|
|
self.assertEqual(result.status_code, 404)
|
|
|
|
|
2022-09-05 15:26:22 +02:00
|
|
|
# Test some API doc endpoints for specific content and metadata.
|
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")
|
2021-06-23 15:13:41 +02:00
|
|
|
self._test("/api/get-own-user", "does not accept any parameters.")
|
2021-02-12 08:20:45 +01:00
|
|
|
self._test("/api/subscribe", "authorization_errors_fatal")
|
|
|
|
self._test("/api/create-user", "zuliprc-admin")
|
|
|
|
self._test("/api/unsubscribe", "not_removed")
|
2022-09-05 15:26:22 +02:00
|
|
|
|
|
|
|
def test_dev_environment_endpoints(self) -> None:
|
|
|
|
self._test("/devlogin/", "Normal users", landing_page=False)
|
2022-09-05 15:43:29 +02:00
|
|
|
self._test("/devtools/", "Useful development URLs", landing_page=False)
|
|
|
|
self._test(
|
|
|
|
"/emails/", "manually generate most of the emails by clicking", landing_page=False
|
|
|
|
)
|
2022-09-05 15:26:22 +02:00
|
|
|
|
|
|
|
def test_error_endpoints(self) -> None:
|
2022-09-05 15:43:29 +02:00
|
|
|
self._test("/errors/404/", "Page not found", landing_page=False)
|
|
|
|
self._test("/errors/5xx/", "Internal server error", landing_page=False)
|
2022-09-05 15:26:22 +02:00
|
|
|
|
|
|
|
def test_corporate_portico_endpoints(self) -> None:
|
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")
|
2022-09-05 15:26:22 +02:00
|
|
|
self._test("/apps/", "Apps for every platform.")
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
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")
|
2022-09-05 15:26:22 +02:00
|
|
|
|
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"])
|
2022-09-05 15:26:22 +02:00
|
|
|
self._test("/attribution/", "Website attributions")
|
|
|
|
self._test("/communities/", "Open communities directory")
|
2021-12-01 19:48:10 +01:00
|
|
|
self._test("/development-community/", "Zulip development community")
|
2022-09-05 15:26:22 +02:00
|
|
|
self._test("/features/", "Beautiful messaging")
|
2022-09-05 17:24:21 +02:00
|
|
|
self._test("/jobs/", "Work with us")
|
2022-09-05 15:26:22 +02:00
|
|
|
self._test("/self-hosting/", "Self-host Zulip")
|
|
|
|
self._test("/security/", "TLS encryption")
|
|
|
|
self._test("/use-cases/", "Use cases and customer stories")
|
2021-02-12 08:20:45 +01:00
|
|
|
self._test("/why-zulip/", "Why Zulip?")
|
2022-09-05 15:26:22 +02:00
|
|
|
# /for/... pages
|
2021-02-12 08:20:45 +01:00
|
|
|
self._test("/for/open-source/", "for open source projects")
|
2021-07-20 20:33:48 +02:00
|
|
|
self._test("/for/events/", "for conferences and events")
|
2021-07-21 12:20:15 +02:00
|
|
|
self._test("/for/education/", "education pricing")
|
2022-09-05 15:26:22 +02:00
|
|
|
self._test("/for/research/", "for research")
|
|
|
|
self._test("/for/business/", "Communication efficiency represents")
|
|
|
|
self._test("/for/communities/", "Zulip for communities")
|
|
|
|
# case-studies
|
2021-07-09 22:19:05 +02:00
|
|
|
self._test("/case-studies/tum/", "Technical University of Munich")
|
2021-07-19 06:55:57 +02:00
|
|
|
self._test("/case-studies/ucsd/", "UCSD")
|
2021-11-24 21:55:00 +01:00
|
|
|
self._test("/case-studies/rust/", "Rust programming language")
|
2022-05-05 22:57:37 +02:00
|
|
|
self._test("/case-studies/recurse-center/", "Recurse Center")
|
2021-11-24 21:55:00 +01:00
|
|
|
self._test("/case-studies/lean/", "Lean theorem prover")
|
2022-02-04 21:36:29 +01:00
|
|
|
self._test("/case-studies/idrift/", "Case study: iDrift AS")
|
2022-03-25 23:30:26 +01:00
|
|
|
self._test("/case-studies/asciidoctor/", "Case study: Asciidoctor")
|
2017-03-08 12:32:41 +01:00
|
|
|
|
2022-08-30 07:47:43 +02:00
|
|
|
def test_open_organizations_endpoint(self) -> None:
|
2022-09-05 15:07:02 +02:00
|
|
|
zulip_dev_info = ["Zulip Dev", "great for testing!"]
|
|
|
|
|
|
|
|
result = self.client_get("/communities/")
|
|
|
|
self.assert_not_in_success_response(zulip_dev_info, result)
|
|
|
|
|
2022-08-30 07:47:43 +02:00
|
|
|
realm = get_realm("zulip")
|
|
|
|
realm.want_advertise_in_communities_directory = True
|
|
|
|
realm.save()
|
2022-09-05 15:07:02 +02:00
|
|
|
self._test("/communities/", "Open communities directory", extra_strings=zulip_dev_info)
|
2022-08-30 07:47:43 +02:00
|
|
|
|
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",
|
|
|
|
"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
|
|
|
|
2022-09-05 14:57:36 +02:00
|
|
|
result = self.client_get(
|
|
|
|
"/integrations/doc-html/nonexistent_integration",
|
|
|
|
follow=True,
|
|
|
|
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
|
|
|
|
)
|
|
|
|
self.assertEqual(result.status_code, 404)
|
|
|
|
|
2019-06-15 07:19:57 +02:00
|
|
|
def test_integration_pages_open_graph_metadata(self) -> None:
|
2022-09-08 13:36:05 +02:00
|
|
|
og_description = '<meta property="og:description" content="Zulip comes with over'
|
|
|
|
|
|
|
|
# Test a particular integration page
|
2021-02-12 08:20:45 +01:00
|
|
|
url = "/integrations/doc/github"
|
2022-09-08 13:36:05 +02:00
|
|
|
title = '<meta property="og:title" content="GitHub | Zulip integrations" />'
|
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
|
2022-09-08 13:36:05 +02:00
|
|
|
for category in CATEGORIES.keys():
|
|
|
|
url = f"/integrations/{category}"
|
|
|
|
if category in META_CATEGORY.keys():
|
|
|
|
title = f"<title>{CATEGORIES[category]} | Zulip integrations</title>"
|
|
|
|
og_title = f'<meta property="og:title" content="{CATEGORIES[category]} | Zulip integrations" />'
|
|
|
|
else:
|
|
|
|
title = f"<title>{CATEGORIES[category]} tools | Zulip integrations</title>"
|
|
|
|
og_title = f'<meta property="og:title" content="{CATEGORIES[category]} tools | Zulip integrations" />'
|
|
|
|
self._test(url, title)
|
|
|
|
self._test(url, og_title, doc_html_str=True)
|
|
|
|
self._test(url, og_description, doc_html_str=True)
|
|
|
|
|
|
|
|
# Test integrations index page
|
2021-02-12 08:20:45 +01:00
|
|
|
url = "/integrations/"
|
2022-09-08 13:36:05 +02:00
|
|
|
og_title = '<meta property="og:title" content="Zulip integrations" />'
|
|
|
|
self._test(url, og_title, doc_html_str=True)
|
|
|
|
self._test(url, og_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.
|
2021-08-02 23:20:39 +02:00
|
|
|
self.assertTrue('data-platform="Mozilla"' in result.content.decode())
|
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")
|
2021-08-02 23:20:39 +02:00
|
|
|
self.assertTrue('data-platform="ZulipElectron"' in result.content.decode())
|
2019-03-12 15:32:33 +01:00
|
|
|
|
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")
|
2021-05-12 16:56:51 +02:00
|
|
|
self.assertIn('<a href="/stats">Usage statistics</a>', str(result.content))
|
2018-09-15 06:17:04 +02:00
|
|
|
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-05-12 16:56:51 +02:00
|
|
|
self.assertIn("<strong>Usage statistics</strong>", str(result.content))
|
2021-02-12 08:20:45 +01:00
|
|
|
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")
|
2022-03-28 17:54:29 +02:00
|
|
|
self.assertIn('<a href="/#streams/subscribed">Subscribed streams</a>', str(result.content))
|
2018-09-16 04:30:18 +02:00
|
|
|
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():
|
2022-07-23 00:33:09 +02:00
|
|
|
assert integration.logo_url is not None
|
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
|
|
|
|
2022-08-17 19:24:10 +02:00
|
|
|
with mock.patch("corporate.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
|
|
|
|
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)
|
2022-01-05 03:22:30 +01:00
|
|
|
self.assert_in_success_response(["Self-host Zulip"], result)
|
2021-06-10 03:59:43 +02:00
|
|
|
self.assert_not_in_success_response(["/upgrade#sponsorship"], result)
|
2022-05-12 06:27:31 +02:00
|
|
|
self.assert_in_success_response(["/accounts/go/?next=%2Fupgrade%23sponsorship"], 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")
|
2021-10-18 23:28:17 +02:00
|
|
|
realm.plan_type = Realm.PLAN_TYPE_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)
|
2021-06-15 22:23:45 +02: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)
|
2021-06-10 03:59:43 +02:00
|
|
|
self.assert_in_success_response(["/upgrade#sponsorship"], result)
|
2022-05-12 06:27:31 +02:00
|
|
|
self.assert_not_in_success_response(["/accounts/go/?next=%2Fupgrade%23sponsorship"], result)
|
2021-06-10 03:59:43 +02:00
|
|
|
|
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:
|
2021-07-22 03:03:45 +02:00
|
|
|
sign_up_now = "Create organization"
|
2021-09-13 18:30:10 +02:00
|
|
|
upgrade_to_standard = "Upgrade to 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="")
|
2021-09-13 18:30:10 +02:00
|
|
|
self.assert_in_success_response([sign_up_now, upgrade_to_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")
|
2021-10-18 23:28:17 +02:00
|
|
|
realm.plan_type = Realm.PLAN_TYPE_SELF_HOSTED
|
2018-08-28 01:32:52 +02:00
|
|
|
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")
|
2021-09-13 18:30:10 +02:00
|
|
|
self.assert_in_success_response([sign_up_now, upgrade_to_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
|
|
|
|
2021-10-18 23:28:17 +02:00
|
|
|
realm.plan_type = Realm.PLAN_TYPE_LIMITED
|
2018-08-15 18:05:07 +02:00
|
|
|
realm.save(update_fields=["plan_type"])
|
|
|
|
result = self.client_get("/plans/", subdomain="zulip")
|
2021-09-13 18:30:10 +02:00
|
|
|
self.assert_in_success_response([current_plan, upgrade_to_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
|
|
|
|
2020-10-08 16:22:59 +02:00
|
|
|
with self.settings(FREE_TRIAL_DAYS=60):
|
|
|
|
result = self.client_get("/plans/", subdomain="zulip")
|
|
|
|
self.assert_in_success_response([current_plan, "Start 60 day free trial"], result)
|
|
|
|
self.assert_not_in_success_response(
|
2021-09-13 18:30:10 +02:00
|
|
|
[sign_up_now, sponsorship_pending, upgrade_to_standard], result
|
2020-10-08 16:22:59 +02:00
|
|
|
)
|
|
|
|
|
2021-10-18 23:28:17 +02:00
|
|
|
realm.plan_type = Realm.PLAN_TYPE_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(
|
2021-09-13 18:30:10 +02:00
|
|
|
[sign_up_now, upgrade_to_standard, sponsorship_pending], result
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2018-08-15 18:05:07 +02:00
|
|
|
|
2021-10-18 23:28:17 +02:00
|
|
|
realm.plan_type = Realm.PLAN_TYPE_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(
|
2021-09-13 18:30:10 +02:00
|
|
|
[sign_up_now, upgrade_to_standard, sponsorship_pending], result
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2020-06-09 12:24:32 +02:00
|
|
|
|
2020-10-08 16:22:59 +02:00
|
|
|
customer = Customer.objects.create(realm=get_realm("zulip"), stripe_customer_id="cus_id")
|
|
|
|
plan = CustomerPlan.objects.create(
|
|
|
|
customer=customer,
|
|
|
|
tier=CustomerPlan.STANDARD,
|
|
|
|
status=CustomerPlan.FREE_TRIAL,
|
|
|
|
billing_cycle_anchor=timezone_now(),
|
|
|
|
billing_schedule=CustomerPlan.MONTHLY,
|
|
|
|
)
|
|
|
|
result = self.client_get("/plans/", subdomain="zulip")
|
|
|
|
self.assert_in_success_response(["Current plan (free trial)"], result)
|
|
|
|
self.assert_not_in_success_response(
|
2021-09-13 18:30:10 +02:00
|
|
|
[sign_up_now, upgrade_to_standard, sponsorship_pending], result
|
2020-10-08 16:22:59 +02:00
|
|
|
)
|
|
|
|
|
2021-10-18 23:28:17 +02:00
|
|
|
realm.plan_type = Realm.PLAN_TYPE_LIMITED
|
2020-06-09 12:24:32 +02:00
|
|
|
realm.save()
|
2020-10-08 16:22:59 +02:00
|
|
|
customer.sponsorship_pending = True
|
|
|
|
customer.save()
|
|
|
|
plan.delete()
|
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)
|
2021-09-13 18:30:10 +02:00
|
|
|
self.assert_not_in_success_response([sign_up_now, upgrade_to_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):
|
2021-06-16 10:23:05 +02:00
|
|
|
def test_get_apps_page_url(self) -> None:
|
|
|
|
with self.settings(ZILENCER_ENABLED=False):
|
|
|
|
apps_page_url = get_apps_page_url()
|
|
|
|
self.assertEqual(apps_page_url, "https://zulip.com/apps/")
|
|
|
|
|
|
|
|
with self.settings(ZILENCER_ENABLED=True):
|
|
|
|
apps_page_url = get_apps_page_url()
|
|
|
|
self.assertEqual(apps_page_url, "/apps/")
|
|
|
|
|
2020-01-29 20:41:23 +01:00
|
|
|
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-08-02 23:20:39 +02:00
|
|
|
html = result.content.decode()
|
2021-02-12 08:20:45 +01:00
|
|
|
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:
|
2021-08-20 03:25:07 +02:00
|
|
|
return_value = "https://desktop-download.zulip.com/v5.4.3/Zulip-Web-Setup-5.4.3.exe"
|
2021-02-12 08:19:30 +01:00
|
|
|
with mock.patch(
|
2022-08-17 19:24:10 +02:00
|
|
|
"corporate.views.portico.get_latest_github_release_download_link_for_platform",
|
2021-02-12 08:19:30 +01:00
|
|
|
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):
|
2021-11-03 21:36:54 +01:00
|
|
|
def test_terms_and_policies_index(self) -> None:
|
|
|
|
with self.settings(POLICIES_DIRECTORY="corporate/policies"):
|
|
|
|
response = self.client_get("/policies/")
|
|
|
|
self.assert_in_success_response(["Terms and policies"], response)
|
2020-01-29 20:41:23 +01:00
|
|
|
|
|
|
|
def test_custom_terms_of_service_template(self) -> None:
|
2021-11-03 21:36:54 +01:00
|
|
|
not_configured_message = "This server is an installation"
|
|
|
|
with self.settings(POLICIES_DIRECTORY="zerver/policies_absent"):
|
|
|
|
response = self.client_get("/policies/terms")
|
|
|
|
self.assert_in_response(not_configured_message, response)
|
|
|
|
|
|
|
|
with self.settings(POLICIES_DIRECTORY="corporate/policies"):
|
|
|
|
response = self.client_get("/policies/terms")
|
|
|
|
self.assert_in_success_response(["Kandra Labs"], response)
|
2020-01-29 20:41:23 +01:00
|
|
|
|
|
|
|
def test_custom_privacy_policy_template(self) -> None:
|
2021-11-03 21:36:54 +01:00
|
|
|
not_configured_message = "This server is an installation"
|
|
|
|
with self.settings(POLICIES_DIRECTORY="zerver/policies_absent"):
|
|
|
|
response = self.client_get("/policies/privacy")
|
|
|
|
self.assert_in_response(not_configured_message, response)
|
|
|
|
|
|
|
|
with self.settings(POLICIES_DIRECTORY="corporate/policies"):
|
|
|
|
response = self.client_get("/policies/privacy")
|
|
|
|
self.assert_in_success_response(["Kandra Labs"], response)
|
2020-01-29 20:41:23 +01:00
|
|
|
|
|
|
|
def test_custom_privacy_policy_template_with_absolute_url(self) -> None:
|
2021-11-03 21:36:54 +01:00
|
|
|
"""Verify that using our recommended production default of an absolute path
|
|
|
|
like /etc/zulip/policies/ works."""
|
2020-01-29 20:41:23 +01:00
|
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
2021-11-03 21:36:54 +01:00
|
|
|
abs_path = os.path.abspath(
|
|
|
|
os.path.join(current_dir, "..", "..", "templates/corporate/policies")
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2021-11-03 21:36:54 +01:00
|
|
|
with self.settings(POLICIES_DIRECTORY=abs_path):
|
|
|
|
response = self.client_get("/policies/privacy")
|
|
|
|
self.assert_in_success_response(["Kandra Labs"], response)
|
|
|
|
|
|
|
|
with self.settings(POLICIES_DIRECTORY=abs_path):
|
|
|
|
response = self.client_get("/policies/nonexistent")
|
|
|
|
self.assert_in_response("No such page", response)
|
|
|
|
|
|
|
|
def test_redirects_from_older_urls(self) -> None:
|
|
|
|
with self.settings(POLICIES_DIRECTORY="corporate/policies"):
|
|
|
|
result = self.client_get("/privacy/", follow=True)
|
|
|
|
self.assert_in_success_response(["Kandra Labs"], result)
|
|
|
|
|
|
|
|
with self.settings(POLICIES_DIRECTORY="corporate/policies"):
|
|
|
|
result = self.client_get("/terms/", follow=True)
|
|
|
|
self.assert_in_success_response(["Kandra Labs"], result)
|
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.
|
|
|
|
|
2021-11-03 21:36:54 +01:00
|
|
|
# We don't have this link at all on these pages; this first
|
|
|
|
# line of the test would change if we were to adjust the
|
|
|
|
# design.
|
|
|
|
response = self.client_get("/policies/terms")
|
|
|
|
self.assert_not_in_success_response(["Back to Zulip"], response)
|
|
|
|
|
|
|
|
response = self.client_get("/policies/terms", {"nav": "no"})
|
|
|
|
self.assert_not_in_success_response(["Back to Zulip"], response)
|
2020-01-29 00:05:06 +01:00
|
|
|
|
2021-11-03 21:36:54 +01:00
|
|
|
response = self.client_get("/policies/privacy", {"nav": "no"})
|
|
|
|
self.assert_not_in_success_response(["Back to Zulip"], response)
|