2016-07-25 22:12:12 +02:00
|
|
|
import os
|
2021-05-25 04:02:58 +02:00
|
|
|
import re
|
2024-07-12 02:30:25 +02:00
|
|
|
from collections.abc import Sequence
|
|
|
|
from typing import TYPE_CHECKING, Any
|
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
|
2023-12-15 02:14:24 +01:00
|
|
|
from zerver.models import Realm
|
|
|
|
from zerver.models.realms import get_realm
|
2023-04-26 02:28:23 +02:00
|
|
|
from zerver.views.documentation import add_api_url_context
|
2020-06-11 00:54:34 +02:00
|
|
|
|
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()
|
|
|
|
|
2023-06-30 12:01:40 +02:00
|
|
|
def _is_landing_page(self, url: str) -> bool:
|
|
|
|
for prefix in [
|
|
|
|
"/api/",
|
|
|
|
"/devlogin/",
|
|
|
|
"/devtools/",
|
|
|
|
"/emails/",
|
|
|
|
"/errors/",
|
|
|
|
"/help/",
|
|
|
|
"/integrations/",
|
|
|
|
]:
|
|
|
|
if url.startswith(prefix):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2023-06-30 12:58:10 +02:00
|
|
|
def _check_basic_fetch(
|
|
|
|
self,
|
|
|
|
*,
|
|
|
|
url: str,
|
|
|
|
subdomain: str,
|
|
|
|
expected_strings: Sequence[str],
|
2023-06-30 13:31:30 +02:00
|
|
|
allow_robots: bool,
|
2023-06-30 12:58:10 +02:00
|
|
|
) -> "TestHttpResponse":
|
2023-06-30 13:31:30 +02:00
|
|
|
# For whatever reason, we have some urls that don't follow
|
|
|
|
# the same policies as the majority of our urls.
|
|
|
|
if url.startswith("/integrations/doc-html"):
|
|
|
|
allow_robots = True
|
|
|
|
|
|
|
|
if url.startswith("/attribution/"):
|
|
|
|
allow_robots = False
|
|
|
|
|
2023-06-30 12:58:10 +02:00
|
|
|
result = self.get_doc(url, subdomain=subdomain)
|
|
|
|
self.print_msg_if_error(url, result)
|
|
|
|
self.assertEqual(result.status_code, 200)
|
|
|
|
for s in expected_strings:
|
|
|
|
self.assertIn(s, str(result.content))
|
2023-06-30 13:31:30 +02:00
|
|
|
|
|
|
|
if allow_robots:
|
|
|
|
self.assert_not_in_success_response(
|
|
|
|
['<meta name="robots" content="noindex,nofollow" />'], result
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
self.assert_in_success_response(
|
|
|
|
['<meta name="robots" content="noindex,nofollow" />'], result
|
|
|
|
)
|
2023-06-30 12:58:10 +02:00
|
|
|
return result
|
|
|
|
|
2023-06-30 15:30:07 +02:00
|
|
|
def _test(self, url: str, expected_strings: Sequence[str]) -> None:
|
2017-08-25 23:55:33 +02:00
|
|
|
# Test the URL on the root subdomain
|
2023-06-30 15:05:42 +02:00
|
|
|
self._check_basic_fetch(
|
2023-06-30 12:58:10 +02:00
|
|
|
url=url,
|
|
|
|
subdomain="",
|
|
|
|
expected_strings=expected_strings,
|
2023-06-30 13:31:30 +02:00
|
|
|
allow_robots=False,
|
2023-06-30 12:58:10 +02:00
|
|
|
)
|
2018-12-23 01:37:27 +01:00
|
|
|
|
2023-06-30 12:01:40 +02:00
|
|
|
if not self._is_landing_page(url):
|
2017-08-25 23:55:33 +02:00
|
|
|
return
|
2023-06-29 13:07:23 +02:00
|
|
|
|
2017-08-25 23:55:33 +02:00
|
|
|
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
|
2023-06-30 12:58:10 +02:00
|
|
|
result = self._check_basic_fetch(
|
|
|
|
url=url,
|
|
|
|
subdomain="",
|
|
|
|
expected_strings=expected_strings,
|
2023-06-30 13:31:30 +02:00
|
|
|
allow_robots=True,
|
2023-06-30 12:58:10 +02:00
|
|
|
)
|
2018-12-23 01:37:27 +01:00
|
|
|
|
2023-06-30 13:31:30 +02:00
|
|
|
# Confirm page has the following HTML elements:
|
|
|
|
# (I have no idea why we don't support this for /attribution/.)
|
|
|
|
if not url.startswith("/attribution/"):
|
2022-09-05 15:43:29 +02:00
|
|
|
self.assert_in_success_response(
|
|
|
|
[
|
|
|
|
"<title>",
|
|
|
|
'<meta name="description" content="',
|
|
|
|
'<meta property="og:title" content="',
|
|
|
|
'<meta property="og:description" content="',
|
|
|
|
],
|
|
|
|
result,
|
|
|
|
)
|
2017-08-25 23:55:33 +02:00
|
|
|
|
2023-06-30 15:30:07 +02:00
|
|
|
def test_zephyr_disallows_robots(self) -> None:
|
|
|
|
sample_urls = [
|
|
|
|
"/apps/",
|
|
|
|
"/case-studies/end-point/",
|
|
|
|
"/communities/",
|
|
|
|
"/devlogin/",
|
|
|
|
"/devtools/",
|
|
|
|
"/emails/",
|
|
|
|
"/errors/404/",
|
|
|
|
"/errors/5xx/",
|
|
|
|
"/integrations/",
|
|
|
|
"/integrations/",
|
|
|
|
"/integrations/bots",
|
|
|
|
"/integrations/doc-html/asana",
|
|
|
|
"/integrations/doc/github",
|
|
|
|
"/team/",
|
|
|
|
]
|
2023-06-29 13:07:23 +02:00
|
|
|
|
2023-06-30 15:30:07 +02:00
|
|
|
for url in sample_urls:
|
2023-06-30 13:31:30 +02:00
|
|
|
self._check_basic_fetch(
|
2023-06-30 12:58:10 +02:00
|
|
|
url=url,
|
|
|
|
subdomain="zephyr",
|
2023-06-30 15:30:07 +02:00
|
|
|
expected_strings=[],
|
2023-06-30 13:31:30 +02:00
|
|
|
allow_robots=False,
|
2023-06-30 12:58:10 +02:00
|
|
|
)
|
2018-12-23 01:37:27 +01:00
|
|
|
|
2023-06-30 15:30:07 +02:00
|
|
|
if self._is_landing_page(url):
|
|
|
|
with self.settings(ROOT_DOMAIN_LANDING_PAGE=True):
|
|
|
|
self._check_basic_fetch(
|
|
|
|
url=url,
|
|
|
|
subdomain="zephyr",
|
|
|
|
expected_strings=[],
|
|
|
|
allow_robots=False,
|
|
|
|
)
|
2023-06-29 13:07:23 +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))
|
2023-06-29 13:30:10 +02:00
|
|
|
endpoint_list = sorted(endpoint_list_set)
|
|
|
|
|
2023-06-29 20:38:51 +02:00
|
|
|
# We want to make sure our regex captured the actual main page.
|
|
|
|
assert "" in endpoint_list
|
|
|
|
|
|
|
|
content = {
|
|
|
|
"/api/": "The Zulip API",
|
|
|
|
"/api/api-keys": "be careful with it",
|
|
|
|
"/api/create-user": "zuliprc-admin",
|
|
|
|
"/api/delete-queue": "Delete a previously registered queue",
|
|
|
|
"/api/get-events": "dont_block",
|
|
|
|
"/api/get-own-user": "does not accept any parameters.",
|
2024-05-19 20:36:34 +02:00
|
|
|
"/api/get-stream-id": "The name of the channel to access.",
|
2023-06-29 20:38:51 +02:00
|
|
|
"/api/get-streams": "include_public",
|
2024-05-19 21:45:09 +02:00
|
|
|
"/api/get-subscriptions": "Get all channels that the user is subscribed to.",
|
2023-06-29 20:38:51 +02:00
|
|
|
"/api/get-users": "client_gravatar",
|
|
|
|
"/api/installation-instructions": "No download required!",
|
|
|
|
"/api/register-queue": "apply_markdown",
|
|
|
|
"/api/render-message": "**foo**",
|
|
|
|
"/api/send-message": "steal away your hearts",
|
|
|
|
"/api/subscribe": "authorization_errors_fatal",
|
|
|
|
"/api/unsubscribe": "not_removed",
|
|
|
|
"/api/update-message": "propagate_mode",
|
|
|
|
}
|
|
|
|
|
2023-06-29 20:55:10 +02:00
|
|
|
"""
|
|
|
|
We have 110 endpoints as of June 2023. If the
|
|
|
|
way we represent links changes, or the way we put links
|
|
|
|
into the main /api page changes, or if somebody simply introduces
|
|
|
|
a bug into the test, there is a danger of losing coverage,
|
|
|
|
although this is mitigated by other factors such as line
|
|
|
|
coverage checks. For that reason, as well as developer convenience,
|
|
|
|
we don't make the check here super precise.
|
|
|
|
"""
|
|
|
|
self.assertGreater(len(endpoint_list), 100)
|
2021-05-25 04:02:58 +02:00
|
|
|
|
|
|
|
for endpoint in endpoint_list:
|
2023-06-29 13:30:10 +02:00
|
|
|
url = f"/api/{endpoint}"
|
2023-06-29 20:38:51 +02:00
|
|
|
|
|
|
|
if url in content:
|
2023-06-30 12:58:10 +02:00
|
|
|
expected_strings = [content[url]]
|
2023-06-29 20:38:51 +02:00
|
|
|
del content[url]
|
|
|
|
else:
|
|
|
|
# TODO: Just fill out dictionary for all ~110 endpoints
|
2023-06-30 23:01:00 +02:00
|
|
|
# with some specific data from the page.
|
|
|
|
expected_strings = ["This is an API doc"]
|
|
|
|
|
|
|
|
# Mock OpenGraph call purely to speed up these tests.
|
|
|
|
with mock.patch(
|
|
|
|
"zerver.lib.html_to_text.html_to_text", return_value="This is an API doc"
|
|
|
|
) as m:
|
|
|
|
self._test(
|
|
|
|
url=url,
|
|
|
|
expected_strings=expected_strings,
|
|
|
|
)
|
|
|
|
if url != "/api/":
|
|
|
|
m.assert_called()
|
2019-05-16 22:38:53 +02:00
|
|
|
|
2023-06-29 20:38:51 +02:00
|
|
|
# Make sure we exercised all content checks.
|
|
|
|
self.assert_length(content, 0)
|
|
|
|
|
2023-06-29 12:20:20 +02:00
|
|
|
def test_api_doc_404_status_codes(self) -> None:
|
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-11-07 20:14:31 +01:00
|
|
|
result = self.client_get(
|
|
|
|
# This template shouldn't be accessed directly.
|
|
|
|
"/api/api-doc-template",
|
|
|
|
follow=True,
|
|
|
|
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
|
|
|
|
)
|
|
|
|
self.assertEqual(result.status_code, 404)
|
|
|
|
|
2022-09-05 15:26:22 +02:00
|
|
|
def test_dev_environment_endpoints(self) -> None:
|
2023-06-30 12:58:10 +02:00
|
|
|
self._test("/devlogin/", ["Normal users"])
|
|
|
|
self._test("/devtools/", ["Useful development URLs"])
|
2024-02-09 22:04:45 +01:00
|
|
|
self._test("/emails/", ["Manually generate most emails"])
|
2022-09-05 15:26:22 +02:00
|
|
|
|
|
|
|
def test_error_endpoints(self) -> None:
|
2023-06-30 12:58:10 +02:00
|
|
|
self._test("/errors/404/", ["Page not found"])
|
|
|
|
self._test("/errors/5xx/", ["Internal server error"])
|
2022-09-05 15:26:22 +02:00
|
|
|
|
|
|
|
def test_corporate_portico_endpoints(self) -> None:
|
2023-06-30 12:58:10 +02:00
|
|
|
self._test("/team/", ["industry veterans"])
|
|
|
|
self._test("/apps/", ["Apps for every platform."])
|
2022-09-05 15:26:22 +02:00
|
|
|
|
2023-06-30 12:58:10 +02:00
|
|
|
self._test("/history/", ["Zulip released as open source!"])
|
2017-07-13 01:28:38 +02:00
|
|
|
# Test the i18n version of one of these pages.
|
2023-06-30 12:58:10 +02:00
|
|
|
self._test("/en/history/", ["Zulip released as open source!"])
|
|
|
|
self._test("/values/", ["designed our company"])
|
2024-07-07 22:57:57 +02:00
|
|
|
self._test("/hello/", ["remote and flexible work"])
|
2023-06-30 12:58:10 +02:00
|
|
|
self._test("/communities/", ["Open communities directory"])
|
|
|
|
self._test("/development-community/", ["Zulip development community"])
|
2024-02-27 20:04:42 +01:00
|
|
|
self._test("/features/", ["Organized team chat solution"])
|
2023-06-30 12:58:10 +02:00
|
|
|
self._test("/jobs/", ["Work with us"])
|
|
|
|
self._test("/self-hosting/", ["Self-host Zulip"])
|
|
|
|
self._test("/security/", ["TLS encryption"])
|
|
|
|
self._test("/use-cases/", ["Use cases and customer stories"])
|
|
|
|
self._test("/why-zulip/", ["Why Zulip?"])
|
|
|
|
self._test("/try-zulip/", ["check out the Zulip app"])
|
2022-09-05 15:26:22 +02:00
|
|
|
# /for/... pages
|
2023-06-30 12:58:10 +02:00
|
|
|
self._test("/for/open-source/", ["for open source projects"])
|
|
|
|
self._test("/for/events/", ["for conferences and events"])
|
|
|
|
self._test("/for/education/", ["education pricing"])
|
|
|
|
self._test("/for/research/", ["for research"])
|
|
|
|
self._test("/for/business/", ["Communication efficiency represents"])
|
|
|
|
self._test("/for/communities/", ["Zulip for communities"])
|
2022-09-05 15:26:22 +02:00
|
|
|
# case-studies
|
2023-06-30 12:58:10 +02:00
|
|
|
self._test("/case-studies/tum/", ["Technical University of Munich"])
|
|
|
|
self._test("/case-studies/ucsd/", ["UCSD"])
|
|
|
|
self._test("/case-studies/rust/", ["Rust programming language"])
|
|
|
|
self._test("/case-studies/recurse-center/", ["Recurse Center"])
|
|
|
|
self._test("/case-studies/lean/", ["Lean theorem prover"])
|
|
|
|
self._test("/case-studies/idrift/", ["Case study: iDrift AS"])
|
|
|
|
self._test("/case-studies/end-point/", ["Case study: End Point"])
|
|
|
|
self._test("/case-studies/atolio/", ["Case study: Atolio"])
|
|
|
|
self._test("/case-studies/asciidoctor/", ["Case study: Asciidoctor"])
|
2023-06-30 13:31:30 +02:00
|
|
|
|
|
|
|
def test_oddball_attributions_page(self) -> None:
|
|
|
|
# Look elsewhere in the code--this page never allows robots nor does
|
|
|
|
# it provide og data.
|
|
|
|
self._test("/attribution/", ["Website attributions"])
|
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()
|
2023-10-11 20:08:20 +02:00
|
|
|
|
|
|
|
realm.description = ""
|
|
|
|
realm.save()
|
|
|
|
result = self.client_get("/communities/")
|
|
|
|
# Not shown because the realm has default description set.
|
|
|
|
self.assert_not_in_success_response(["Zulip Dev"], result)
|
|
|
|
|
|
|
|
realm.description = "Some description"
|
|
|
|
realm.save()
|
|
|
|
self._test("/communities/", ["Open communities directory", "Zulip Dev", "Some description"])
|
|
|
|
|
|
|
|
# No org with research type so research category not displayed.
|
|
|
|
result = self.client_get("/communities/")
|
|
|
|
self.assert_not_in_success_response(['data-category="research"'], result)
|
|
|
|
|
|
|
|
realm.org_type = Realm.ORG_TYPES["research"]["id"]
|
|
|
|
realm.save()
|
|
|
|
self._test(
|
|
|
|
"/communities/", ["Open communities directory", "Zulip Dev", 'data-category="research"']
|
|
|
|
)
|
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/",
|
2023-06-30 12:58:10 +02:00
|
|
|
expected_strings=[
|
|
|
|
"native integrations.",
|
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
|
|
|
|
2022-12-12 03:39:16 +01:00
|
|
|
for integration in INTEGRATIONS:
|
2021-02-12 08:20:45 +01:00
|
|
|
url = f"/integrations/doc-html/{integration}"
|
2023-06-30 13:31:30 +02:00
|
|
|
self._test(url, expected_strings=[])
|
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'
|
2023-06-30 13:31:30 +02:00
|
|
|
self._test(url, [title, description])
|
2019-06-15 07:19:57 +02:00
|
|
|
|
|
|
|
# Test category pages
|
2022-12-12 03:39:16 +01:00
|
|
|
for category in CATEGORIES:
|
2022-09-08 13:36:05 +02:00
|
|
|
url = f"/integrations/{category}"
|
2022-12-12 03:39:16 +01:00
|
|
|
if category in META_CATEGORY:
|
2022-09-08 13:36:05 +02:00
|
|
|
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" />'
|
2023-06-30 13:31:30 +02:00
|
|
|
self._test(url, [title, og_title, og_description])
|
2022-09-08 13:36:05 +02:00
|
|
|
|
|
|
|
# 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" />'
|
2023-06-30 13:31:30 +02:00
|
|
|
self._test(url, [og_title, og_description])
|
2019-06-15 07:19:57 +02:00
|
|
|
|
2023-06-30 13:20:06 +02:00
|
|
|
def test_integration_404s(self) -> None:
|
2018-05-11 16:35:03 +02:00
|
|
|
# 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)
|
2023-06-29 15:28:38 +02:00
|
|
|
self.assertIn('Go to <a href="/#settings/preferences">Preferences</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)
|
2023-06-29 15:28:38 +02:00
|
|
|
self.assertIn("<strong>Preferences</strong>", str(result.content))
|
2021-02-12 08:20:45 +01:00
|
|
|
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")
|
2023-07-25 15:41:30 +02:00
|
|
|
self.assertIn(
|
2023-12-01 08:06:33 +01:00
|
|
|
'<a href="/stats"><i class="zulip-icon zulip-icon-bar-chart"></i> Usage statistics</a>',
|
2023-07-25 15:41:30 +02:00
|
|
|
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)
|
2023-07-25 15:41:30 +02:00
|
|
|
self.assertIn(
|
2023-12-01 08:06:33 +01:00
|
|
|
'<strong><i class="zulip-icon zulip-icon-bar-chart"></i> Usage statistics</strong>',
|
|
|
|
str(result.content),
|
2023-07-25 15:41:30 +02:00
|
|
|
)
|
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:
|
2024-04-30 21:51:09 +02:00
|
|
|
result = self.client_get("/help/message-a-channel-by-email")
|
2023-12-09 04:22:52 +01:00
|
|
|
self.assertIn(
|
2024-05-02 17:46:14 +02:00
|
|
|
'<a href="/#channels/subscribed"><i class="zulip-icon zulip-icon-hash"></i> Channel settings</a>',
|
2023-12-09 04:22:52 +01:00
|
|
|
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):
|
2024-04-30 21:51:09 +02:00
|
|
|
result = self.client_get("/help/message-a-channel-by-email", subdomain="")
|
2018-09-16 04:30:18 +02:00
|
|
|
self.assertEqual(result.status_code, 200)
|
2023-12-09 04:22:52 +01:00
|
|
|
self.assertIn(
|
2024-05-02 17:46:14 +02:00
|
|
|
'<strong><i class="zulip-icon zulip-icon-hash"></i> Channel settings</strong>',
|
2023-12-09 04:22:52 +01:00
|
|
|
str(result.content),
|
|
|
|
)
|
2024-04-30 13:30:24 +02:00
|
|
|
self.assertNotIn("/#channels", 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:
|
2024-07-12 02:30:17 +02:00
|
|
|
context: dict[str, Any] = {}
|
2023-04-26 02:28:23 +02:00
|
|
|
add_api_url_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:
|
2024-07-12 02:30:17 +02:00
|
|
|
context: dict[str, Any] = {}
|
2023-04-26 02:28:23 +02:00
|
|
|
add_api_url_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:
|
2024-07-12 02:30:17 +02:00
|
|
|
context: dict[str, Any] = {}
|
2016-10-06 01:42:24 +02:00
|
|
|
request = HostRequestMock(host="mysubdomain.testserver")
|
2023-04-26 02:28:23 +02:00
|
|
|
add_api_url_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"])
|
|
|
|
|
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:
|
2023-10-06 18:16:22 +02:00
|
|
|
with self.assertLogs("django.request", level="ERROR") as m:
|
|
|
|
result = self.client_get("/config-error/smtp")
|
|
|
|
self.assertEqual(result.status_code, 500)
|
|
|
|
self.assert_in_response("email configuration", result)
|
|
|
|
self.assertEqual(
|
|
|
|
m.output,
|
|
|
|
["ERROR:django.request:Internal Server Error: /config-error/smtp"],
|
|
|
|
)
|
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)
|
2023-11-02 09:36:27 +01:00
|
|
|
self.assert_not_in_success_response(["/sponsorship/"], result)
|
|
|
|
self.assert_in_success_response(["/accounts/go/?next=%2Fsponsorship%2F"], 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)
|
2024-05-11 01:21:38 +02:00
|
|
|
self.assert_in_response("There is no Zulip organization at", 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)
|
2023-03-23 03:53:14 +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)
|
2023-11-02 09:36:27 +01:00
|
|
|
self.assert_in_success_response(["/sponsorship/"], result)
|
|
|
|
self.assert_not_in_success_response(["/accounts/go/?next=%2Fsponsorship%2F"], 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"
|
2023-12-05 23:20:32 +01:00
|
|
|
sponsorship_pending = "Sponsorship requested"
|
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)
|
2023-03-23 03:53:14 +01: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)
|
2023-03-23 03:53:14 +01:00
|
|
|
self.assertEqual(result["Location"], "https://zulip.com/plans/")
|
2018-08-28 01:32:52 +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
|
|
|
|
2023-12-09 18:31:27 +01:00
|
|
|
with self.settings(CLOUD_FREE_TRIAL_DAYS=60):
|
2020-10-08 16:22:59 +02:00
|
|
|
result = self.client_get("/plans/", subdomain="zulip")
|
2023-11-23 01:21:00 +01:00
|
|
|
self.assert_in_success_response([current_plan, "Start 60-day free trial"], result)
|
2020-10-08 16:22:59 +02:00
|
|
|
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
|
|
|
)
|
|
|
|
|
2023-12-05 07:42:52 +01:00
|
|
|
# Sponsored realms always have Customer entry.
|
|
|
|
customer = Customer.objects.create(realm=get_realm("zulip"), stripe_customer_id="cus_id")
|
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
|
|
|
|
2023-12-05 07:42:52 +01:00
|
|
|
plan = CustomerPlan.objects.create(
|
|
|
|
customer=customer,
|
|
|
|
tier=CustomerPlan.TIER_CLOUD_STANDARD,
|
|
|
|
status=CustomerPlan.ACTIVE,
|
|
|
|
billing_cycle_anchor=timezone_now(),
|
|
|
|
billing_schedule=CustomerPlan.BILLING_SCHEDULE_MONTHLY,
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
2023-12-05 07:42:52 +01:00
|
|
|
plan.status = CustomerPlan.FREE_TRIAL
|
|
|
|
plan.save(update_fields=["status"])
|
2020-10-08 16:22:59 +02:00
|
|
|
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:
|
apps: Fix redirect from /apps -> https://zulip.com/apps/.
When this code was moved from being in zerver in 21a2fd482eae, it kept
the `if ZILENCER_ENABLED` blocks. Since ZILENCER and CORPORATE are
generally either both on or both off, the if statement became
mostly-unnecessary.
However, because tests cannot easily remove elements from
INSTALLED_APPS and re-determine URL resolution, we switch to checking
`if CORPORATE_ENABLED` as a guard, and leave these in-place.
The other side effect of this is that with e54ded49c44c, most Zulip
deployments started to 404 requests for `/apps` instead of redirecting
them to `https://zulip.com/apps/` since they no longer had any path
configured for `/apps`. Unfortunately, this URL is in widespread use
in the app (e.g. in links from the Welcome Bot), so we should ensure
that it does successfully redirect.
Add the `/apps` path to `zerver`, but only if not CORPORATE_ENABLED,
so the URLs do not overlap.
2022-12-16 15:17:00 +01:00
|
|
|
with self.settings(CORPORATE_ENABLED=False):
|
2021-06-16 10:23:05 +02:00
|
|
|
apps_page_url = get_apps_page_url()
|
|
|
|
self.assertEqual(apps_page_url, "https://zulip.com/apps/")
|
|
|
|
|
apps: Fix redirect from /apps -> https://zulip.com/apps/.
When this code was moved from being in zerver in 21a2fd482eae, it kept
the `if ZILENCER_ENABLED` blocks. Since ZILENCER and CORPORATE are
generally either both on or both off, the if statement became
mostly-unnecessary.
However, because tests cannot easily remove elements from
INSTALLED_APPS and re-determine URL resolution, we switch to checking
`if CORPORATE_ENABLED` as a guard, and leave these in-place.
The other side effect of this is that with e54ded49c44c, most Zulip
deployments started to 404 requests for `/apps` instead of redirecting
them to `https://zulip.com/apps/` since they no longer had any path
configured for `/apps`. Unfortunately, this URL is in widespread use
in the app (e.g. in links from the Welcome Bot), so we should ensure
that it does successfully redirect.
Add the `/apps` path to `zerver`, but only if not CORPORATE_ENABLED,
so the URLs do not overlap.
2022-12-16 15:17:00 +01:00
|
|
|
with self.settings(CORPORATE_ENABLED=True):
|
2021-06-16 10:23:05 +02:00
|
|
|
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:
|
apps: Fix redirect from /apps -> https://zulip.com/apps/.
When this code was moved from being in zerver in 21a2fd482eae, it kept
the `if ZILENCER_ENABLED` blocks. Since ZILENCER and CORPORATE are
generally either both on or both off, the if statement became
mostly-unnecessary.
However, because tests cannot easily remove elements from
INSTALLED_APPS and re-determine URL resolution, we switch to checking
`if CORPORATE_ENABLED` as a guard, and leave these in-place.
The other side effect of this is that with e54ded49c44c, most Zulip
deployments started to 404 requests for `/apps` instead of redirecting
them to `https://zulip.com/apps/` since they no longer had any path
configured for `/apps`. Unfortunately, this URL is in widespread use
in the app (e.g. in links from the Welcome Bot), so we should ensure
that it does successfully redirect.
Add the `/apps` path to `zerver`, but only if not CORPORATE_ENABLED,
so the URLs do not overlap.
2022-12-16 15:17:00 +01:00
|
|
|
with self.settings(CORPORATE_ENABLED=False):
|
|
|
|
# Note that because this cannot actually uninstall the
|
|
|
|
# "corporate" app and trigger updates to URL resolution,
|
|
|
|
# this does not test the "apps/" path installed in
|
|
|
|
# zproject.urls, but rather the special-case for testing
|
|
|
|
# in corporate.views.portico
|
|
|
|
result = self.client_get("/apps")
|
|
|
|
self.assertEqual(result.status_code, 301)
|
|
|
|
self.assertTrue(result["Location"].endswith("/apps/"))
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/apps/")
|
apps: Fix redirect from /apps -> https://zulip.com/apps/.
When this code was moved from being in zerver in 21a2fd482eae, it kept
the `if ZILENCER_ENABLED` blocks. Since ZILENCER and CORPORATE are
generally either both on or both off, the if statement became
mostly-unnecessary.
However, because tests cannot easily remove elements from
INSTALLED_APPS and re-determine URL resolution, we switch to checking
`if CORPORATE_ENABLED` as a guard, and leave these in-place.
The other side effect of this is that with e54ded49c44c, most Zulip
deployments started to 404 requests for `/apps` instead of redirecting
them to `https://zulip.com/apps/` since they no longer had any path
configured for `/apps`. Unfortunately, this URL is in widespread use
in the app (e.g. in links from the Welcome Bot), so we should ensure
that it does successfully redirect.
Add the `/apps` path to `zerver`, but only if not CORPORATE_ENABLED,
so the URLs do not overlap.
2022-12-16 15:17:00 +01:00
|
|
|
self.assertEqual(result.status_code, 301)
|
|
|
|
self.assertTrue(result["Location"] == "https://zulip.com/apps/")
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/apps/linux")
|
apps: Fix redirect from /apps -> https://zulip.com/apps/.
When this code was moved from being in zerver in 21a2fd482eae, it kept
the `if ZILENCER_ENABLED` blocks. Since ZILENCER and CORPORATE are
generally either both on or both off, the if statement became
mostly-unnecessary.
However, because tests cannot easily remove elements from
INSTALLED_APPS and re-determine URL resolution, we switch to checking
`if CORPORATE_ENABLED` as a guard, and leave these in-place.
The other side effect of this is that with e54ded49c44c, most Zulip
deployments started to 404 requests for `/apps` instead of redirecting
them to `https://zulip.com/apps/` since they no longer had any path
configured for `/apps`. Unfortunately, this URL is in widespread use
in the app (e.g. in links from the Welcome Bot), so we should ensure
that it does successfully redirect.
Add the `/apps` path to `zerver`, but only if not CORPORATE_ENABLED,
so the URLs do not overlap.
2022-12-16 15:17:00 +01:00
|
|
|
self.assertEqual(result.status_code, 301)
|
|
|
|
self.assertTrue(result["Location"] == "https://zulip.com/apps/")
|
|
|
|
|
|
|
|
with self.settings(CORPORATE_ENABLED=True):
|
|
|
|
result = self.client_get("/apps")
|
|
|
|
self.assertEqual(result.status_code, 301)
|
|
|
|
self.assertTrue(result["Location"].endswith("/apps/"))
|
2020-09-12 04:18:53 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_get("/apps/")
|
apps: Fix redirect from /apps -> https://zulip.com/apps/.
When this code was moved from being in zerver in 21a2fd482eae, it kept
the `if ZILENCER_ENABLED` blocks. Since ZILENCER and CORPORATE are
generally either both on or both off, the if statement became
mostly-unnecessary.
However, because tests cannot easily remove elements from
INSTALLED_APPS and re-determine URL resolution, we switch to checking
`if CORPORATE_ENABLED` as a guard, and leave these in-place.
The other side effect of this is that with e54ded49c44c, most Zulip
deployments started to 404 requests for `/apps` instead of redirecting
them to `https://zulip.com/apps/` since they no longer had any path
configured for `/apps`. Unfortunately, this URL is in widespread use
in the app (e.g. in links from the Welcome Bot), so we should ensure
that it does successfully redirect.
Add the `/apps` path to `zerver`, but only if not CORPORATE_ENABLED,
so the URLs do not overlap.
2022-12-16 15:17:00 +01:00
|
|
|
self.assertEqual(result.status_code, 200)
|
|
|
|
html = result.content.decode()
|
|
|
|
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)
|
|
|
|
|
2023-12-18 21:57:47 +01:00
|
|
|
with self.settings(POLICIES_DIRECTORY="zerver/policies_minimal"):
|
|
|
|
response = self.client_get("/policies/terms")
|
|
|
|
self.assert_in_success_response(["These are the custom terms and conditions."], response)
|
|
|
|
|
2021-11-03 21:36:54 +01:00
|
|
|
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)
|
|
|
|
|
2023-12-18 21:57:47 +01:00
|
|
|
with self.settings(POLICIES_DIRECTORY="zerver/policies_minimal"):
|
|
|
|
response = self.client_get("/policies/privacy")
|
|
|
|
self.assert_in_success_response(["This is the custom privacy policy."], response)
|
|
|
|
|
2021-11-03 21:36:54 +01:00
|
|
|
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:
|
2023-03-23 04:14:27 +01:00
|
|
|
# Test that our ?nav=0 feature of /policies/privacy and /policies/terms,
|
2020-01-29 00:05:06 +01:00
|
|
|
# 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)
|