Skip to content

Commit cce4da6

Browse files
committed
Refactor redirect tests
This is most like a little hack to make the tests of the new feature in .com pass. Why tests are passing after this changes? First, we don't need to patch anything, by default those files don't exist. Now, here is the interesting part. When a version exists (in this case `0.8.1`) the serve_docs function (from .com) tries to verify that the current user has permissions over that version first, this gives a 401 response. Accessing to a unexisting version, it gives 404, which is needed to trigger the redirect
1 parent b67fbf7 commit cce4da6

File tree

1 file changed

+20
-53
lines changed

1 file changed

+20
-53
lines changed

readthedocs/rtd_tests/tests/test_redirects.py

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from django.test import TestCase
55
from django.test.utils import override_settings
66
from django_dynamic_fixture import fixture, get
7-
from mock import patch
87

98
from readthedocs.builds.constants import LATEST
109
from readthedocs.builds.models import Version
@@ -19,21 +18,6 @@ class RedirectTests(TestCase):
1918
def setUp(self):
2019
logging.disable(logging.DEBUG)
2120
self.client.login(username='eric', password='test')
22-
self.client.post(
23-
'/dashboard/import/',
24-
{
25-
'repo_type': 'git', 'name': 'Pip',
26-
'tags': 'big, fucking, monkey', 'default_branch': '',
27-
'project_url': 'http://pip.rtfd.org',
28-
'repo': 'https://github.com/fail/sauce',
29-
'csrfmiddlewaretoken': '34af7c8a5ba84b84564403a280d9a9be',
30-
'default_version': LATEST,
31-
'privacy_level': 'public',
32-
'version_privacy_level': 'public',
33-
'description': 'wat',
34-
'documentation_type': 'sphinx',
35-
},
36-
)
3721
pip = Project.objects.get(slug='pip')
3822
pip.versions.create_latest()
3923

@@ -135,21 +119,6 @@ class RedirectAppTests(TestCase):
135119

136120
def setUp(self):
137121
self.client.login(username='eric', password='test')
138-
self.client.post(
139-
'/dashboard/import/',
140-
{
141-
'repo_type': 'git', 'name': 'Pip',
142-
'tags': 'big, fucking, monkey', 'default_branch': '',
143-
'project_url': 'http://pip.rtfd.org',
144-
'repo': 'https://github.com/fail/sauce',
145-
'csrfmiddlewaretoken': '34af7c8a5ba84b84564403a280d9a9be',
146-
'default_version': LATEST,
147-
'privacy_level': 'public',
148-
'version_privacy_level': 'public',
149-
'description': 'wat',
150-
'documentation_type': 'sphinx',
151-
},
152-
)
153122
self.pip = Project.objects.get(slug='pip')
154123
self.pip.versions.create_latest()
155124

@@ -398,35 +367,33 @@ def test_redirect_keeps_version_number(self):
398367
project=self.pip, redirect_type='page',
399368
from_url='/how_to_install.html', to_url='/install.html',
400369
)
401-
with patch('readthedocs.core.views.serve._serve_symlink_docs') as _serve_docs:
402-
_serve_docs.side_effect = Http404()
403-
r = self.client.get(
404-
'/en/0.8.1/how_to_install.html',
405-
HTTP_HOST='pip.readthedocs.org',
406-
)
407-
self.assertEqual(r.status_code, 302)
408-
self.assertEqual(
409-
r['Location'],
410-
'http://pip.readthedocs.org/en/0.8.1/install.html',
411-
)
370+
r = self.client.get(
371+
'/en/0.8.2/how_to_install.html',
372+
HTTP_HOST='pip.readthedocs.org',
373+
)
374+
self.assertEqual(r.status_code, 302)
375+
self.assertEqual(
376+
r['Location'],
377+
'http://pip.readthedocs.org/en/0.8.2/install.html',
378+
)
412379

413380
@override_settings(USE_SUBDOMAIN=True)
414381
def test_redirect_keeps_language(self):
382+
self.pip.language = 'de'
383+
self.pip.save()
415384
Redirect.objects.create(
416385
project=self.pip, redirect_type='page',
417386
from_url='/how_to_install.html', to_url='/install.html',
418387
)
419-
with patch('readthedocs.core.views.serve._serve_symlink_docs') as _serve_docs:
420-
_serve_docs.side_effect = Http404()
421-
r = self.client.get(
422-
'/de/0.8.1/how_to_install.html',
423-
HTTP_HOST='pip.readthedocs.org',
424-
)
425-
self.assertEqual(r.status_code, 302)
426-
self.assertEqual(
427-
r['Location'],
428-
'http://pip.readthedocs.org/de/0.8.1/install.html',
429-
)
388+
r = self.client.get(
389+
'/de/0.8.2/how_to_install.html',
390+
HTTP_HOST='pip.readthedocs.org',
391+
)
392+
self.assertEqual(r.status_code, 302)
393+
self.assertEqual(
394+
r['Location'],
395+
'http://pip.readthedocs.org/de/0.8.2/install.html',
396+
)
430397

431398
@override_settings(USE_SUBDOMAIN=True)
432399
def test_redirect_recognizes_custom_cname(self):

0 commit comments

Comments
 (0)