-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Proxito: redirect to default version from root language #10313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
0bcb26a
d125fe0
f403c3c
bbcdc05
8182b5b
75988b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -84,6 +84,22 @@ For example:: | |||||
You can choose which is the :term:`default version` for Read the Docs to display. | ||||||
This usually corresponds to the most recent official release from your project. | ||||||
|
||||||
Root language redirect at ``/<lang>/`` | ||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||
|
||||||
A link to the root language of your documentation (``<slug>.readthedocs.io/en/``) | ||||||
will redirect to the :term:`default version` of that translation. | ||||||
|
||||||
.. TODO: Remove this once the feature is default on .com | ||||||
|
||||||
This redirect is currently only active on |org_brand| (``<slug>.readthedocs.io`` and :doc:`custom domains </custom-domains>`). | ||||||
|
||||||
Root language redirects on |com_brand| can be enabled by contacting :doc:`support </support>`. | ||||||
|
||||||
For example:: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
https://docs.readthedocs.io/en/ -> https://docs.readthedocs.io/en/stable/ | ||||||
|
||||||
Shortlink with ``https://<slug>.rtfd.io`` | ||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
from django.test import override_settings | ||
from django_dynamic_fixture import get | ||
|
||
from readthedocs.builds.models import Version | ||
from readthedocs.projects.constants import PUBLIC | ||
from readthedocs.projects.models import Feature | ||
from readthedocs.proxito.constants import RedirectType | ||
from readthedocs.subscriptions.constants import TYPE_CNAME | ||
|
@@ -11,6 +13,7 @@ | |
|
||
@override_settings( | ||
PUBLIC_DOMAIN='dev.readthedocs.io', | ||
RTD_EXTERNAL_VERSION_DOMAIN="dev.readthedocs.build", | ||
PUBLIC_DOMAIN_USES_HTTPS=True, | ||
RTD_DEFAULT_FEATURES={ | ||
TYPE_CNAME: 1, | ||
|
@@ -412,3 +415,49 @@ def setUp(self): | |
default_true=True, | ||
future_default_true=True, | ||
) | ||
|
||
def test_redirect_from_root_language_to_default_version(self): | ||
paths = [ | ||
"/en", | ||
"/en/", | ||
Comment on lines
+421
to
+422
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 |
||
] | ||
for path in paths: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note there are more cases like this in the other tests we can change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think parametrize doesn't work with tests that inherit from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, they don't work there https://docs.pytest.org/en/latest/how-to/unittest.html#pytest-features-in-unittest-testcase-subclasses. |
||
r = self.client.get( | ||
path, | ||
secure=True, | ||
HTTP_HOST="project.dev.readthedocs.io", | ||
) | ||
self.assertEqual(r.status_code, 302) | ||
self.assertEqual( | ||
r["Location"], | ||
"https://project.dev.readthedocs.io/en/latest/", | ||
) | ||
self.assertEqual(r.headers["CDN-Cache-Control"], "public") | ||
self.assertEqual(r.headers["Cache-Tag"], "project") | ||
self.assertEqual(r.headers["X-RTD-Redirect"], RedirectType.system.name) | ||
|
||
def test_redirect_from_root_language_to_default_external_version(self): | ||
get( | ||
Version, | ||
slug="10", | ||
project=self.project, | ||
privacy_level=PUBLIC, | ||
) | ||
paths = [ | ||
"/en", | ||
"/en/", | ||
] | ||
for path in paths: | ||
r = self.client.get( | ||
path, | ||
secure=True, | ||
HTTP_HOST="project--10.dev.readthedocs.build", | ||
) | ||
self.assertEqual(r.status_code, 302) | ||
self.assertEqual( | ||
r["Location"], | ||
"https://project--10.dev.readthedocs.build/en/10/", | ||
) | ||
self.assertEqual(r.headers["CDN-Cache-Control"], "public") | ||
self.assertEqual(r.headers["Cache-Tag"], "project") | ||
self.assertEqual(r.headers["X-RTD-Redirect"], RedirectType.system.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.