|
1 | 1 | from __future__ import absolute_import
|
2 |
| -from django.core.urlresolvers import reverse |
3 | 2 | from django.http import Http404
|
4 | 3 | from django.test import TestCase
|
5 | 4 | from django.test.utils import override_settings
|
|
9 | 8 | from mock import patch
|
10 | 9 |
|
11 | 10 | from readthedocs.builds.constants import LATEST
|
| 11 | +from readthedocs.builds.models import Version |
12 | 12 | from readthedocs.projects.models import Project
|
13 | 13 | from readthedocs.redirects.models import Redirect
|
14 | 14 |
|
@@ -185,6 +185,31 @@ def test_redirect_exact_with_rest(self):
|
185 | 185 | self.assertEqual(
|
186 | 186 | r['Location'], 'http://pip.readthedocs.org/en/master/guides/install.html')
|
187 | 187 |
|
| 188 | + @override_settings(USE_SUBDOMAIN=True) |
| 189 | + def test_redirect_inactive_version(self): |
| 190 | + """ |
| 191 | + Inactive Version (``active=False``) should redirect properly. |
| 192 | +
|
| 193 | + The function that servers the page should return 404 when serving a page |
| 194 | + of an inactive version and the redirect system should work. |
| 195 | + """ |
| 196 | + version = get( |
| 197 | + Version, |
| 198 | + slug='oldversion', |
| 199 | + project=self.pip, |
| 200 | + active=False, |
| 201 | + ) |
| 202 | + Redirect.objects.create( |
| 203 | + project=self.pip, |
| 204 | + redirect_type='exact', |
| 205 | + from_url='/en/oldversion/', |
| 206 | + to_url='/en/newversion/', |
| 207 | + ) |
| 208 | + r = self.client.get('/en/oldversion/', HTTP_HOST='pip.readthedocs.org') |
| 209 | + self.assertEqual(r.status_code, 302) |
| 210 | + self.assertEqual( |
| 211 | + r['Location'], 'http://pip.readthedocs.org/en/newversion/') |
| 212 | + |
188 | 213 | @override_settings(USE_SUBDOMAIN=True)
|
189 | 214 | def test_redirect_keeps_version_number(self):
|
190 | 215 | Redirect.objects.create(
|
|
0 commit comments