diff options
| author | Tim Graham <timograham@gmail.com> | 2015-01-18 16:43:57 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-01-18 17:43:06 -0500 |
| commit | 6e13c0490d67cdf210411f08feca3b78a49645ea (patch) | |
| tree | 5d9bc14688364af1d58ca38b6ac6e5877481f6a1 /tests/generic_views | |
| parent | bd98926f0eb19d27821a8a7679b42ff46e53e4da (diff) | |
Changed RedirectView.permanent to False per deprecation timeline; refs #21587.
Diffstat (limited to 'tests/generic_views')
| -rw-r--r-- | tests/generic_views/test_base.py | 119 |
1 files changed, 29 insertions, 90 deletions
diff --git a/tests/generic_views/test_base.py b/tests/generic_views/test_base.py index ce3a0f52d6..47518fdd92 100644 --- a/tests/generic_views/test_base.py +++ b/tests/generic_views/test_base.py @@ -2,14 +2,11 @@ from __future__ import unicode_literals import time import unittest -import warnings from django.core.exceptions import ImproperlyConfigured from django.core.urlresolvers import resolve from django.http import HttpResponse -from django.utils import six -from django.utils.deprecation import RemovedInDjango19Warning -from django.test import TestCase, RequestFactory, ignore_warnings, override_settings +from django.test import TestCase, RequestFactory, override_settings from django.views.generic import View, TemplateView, RedirectView from . import views @@ -340,7 +337,6 @@ class TemplateViewTest(TestCase): self.assertIs(match.func.view_class, TemplateView) -@ignore_warnings(category=RemovedInDjango19Warning) @override_settings(ROOT_URLCONF='generic_views.urls') class RedirectViewTest(TestCase): @@ -351,14 +347,20 @@ class RedirectViewTest(TestCase): response = RedirectView.as_view()(self.rf.get('/foo/')) self.assertEqual(response.status_code, 410) - def test_permanent_redirect(self): - "Default is a permanent redirect" + def test_default_redirect(self): + "Default is a temporary redirect" response = RedirectView.as_view(url='/bar/')(self.rf.get('/foo/')) + self.assertEqual(response.status_code, 302) + self.assertEqual(response.url, '/bar/') + + def test_permanent_redirect(self): + "Permanent redirects are an option" + response = RedirectView.as_view(url='/bar/', permanent=True)(self.rf.get('/foo/')) self.assertEqual(response.status_code, 301) self.assertEqual(response.url, '/bar/') def test_temporary_redirect(self): - "Permanent redirects are an option" + "Temporary redirects are an option" response = RedirectView.as_view(url='/bar/', permanent=False)(self.rf.get('/foo/')) self.assertEqual(response.status_code, 302) self.assertEqual(response.url, '/bar/') @@ -366,35 +368,35 @@ class RedirectViewTest(TestCase): def test_include_args(self): "GET arguments can be included in the redirected URL" response = RedirectView.as_view(url='/bar/')(self.rf.get('/foo/')) - self.assertEqual(response.status_code, 301) + self.assertEqual(response.status_code, 302) self.assertEqual(response.url, '/bar/') response = RedirectView.as_view(url='/bar/', query_string=True)(self.rf.get('/foo/?pork=spam')) - self.assertEqual(response.status_code, 301) + self.assertEqual(response.status_code, 302) self.assertEqual(response.url, '/bar/?pork=spam') def test_include_urlencoded_args(self): "GET arguments can be URL-encoded when included in the redirected URL" response = RedirectView.as_view(url='/bar/', query_string=True)( self.rf.get('/foo/?unicode=%E2%9C%93')) - self.assertEqual(response.status_code, 301) + self.assertEqual(response.status_code, 302) self.assertEqual(response.url, '/bar/?unicode=%E2%9C%93') def test_parameter_substitution(self): "Redirection URLs can be parameterized" response = RedirectView.as_view(url='/bar/%(object_id)d/')(self.rf.get('/foo/42/'), object_id=42) - self.assertEqual(response.status_code, 301) + self.assertEqual(response.status_code, 302) self.assertEqual(response.url, '/bar/42/') def test_named_url_pattern(self): "Named pattern parameter should reverse to the matching pattern" response = RedirectView.as_view(pattern_name='artist_detail')(self.rf.get('/foo/'), pk=1) - self.assertEqual(response.status_code, 301) + self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], '/detail/artist/1/') def test_named_url_pattern_using_args(self): response = RedirectView.as_view(pattern_name='artist_detail')(self.rf.get('/foo/'), 1) - self.assertEqual(response.status_code, 301) + self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], '/detail/artist/1/') def test_wrong_named_url_pattern(self): @@ -403,46 +405,46 @@ class RedirectViewTest(TestCase): self.assertEqual(response.status_code, 410) def test_redirect_POST(self): - "Default is a permanent redirect" + "Default is a temporary redirect" response = RedirectView.as_view(url='/bar/')(self.rf.post('/foo/')) - self.assertEqual(response.status_code, 301) + self.assertEqual(response.status_code, 302) self.assertEqual(response.url, '/bar/') def test_redirect_HEAD(self): - "Default is a permanent redirect" + "Default is a temporary redirect" response = RedirectView.as_view(url='/bar/')(self.rf.head('/foo/')) - self.assertEqual(response.status_code, 301) + self.assertEqual(response.status_code, 302) self.assertEqual(response.url, '/bar/') def test_redirect_OPTIONS(self): - "Default is a permanent redirect" + "Default is a temporary redirect" response = RedirectView.as_view(url='/bar/')(self.rf.options('/foo/')) - self.assertEqual(response.status_code, 301) + self.assertEqual(response.status_code, 302) self.assertEqual(response.url, '/bar/') def test_redirect_PUT(self): - "Default is a permanent redirect" + "Default is a temporary redirect" response = RedirectView.as_view(url='/bar/')(self.rf.put('/foo/')) - self.assertEqual(response.status_code, 301) + self.assertEqual(response.status_code, 302) self.assertEqual(response.url, '/bar/') def test_redirect_PATCH(self): - "Default is a permanent redirect" + "Default is a temporary redirect" response = RedirectView.as_view(url='/bar/')(self.rf.patch('/foo/')) - self.assertEqual(response.status_code, 301) + self.assertEqual(response.status_code, 302) self.assertEqual(response.url, '/bar/') def test_redirect_DELETE(self): - "Default is a permanent redirect" + "Default is a temporary redirect" response = RedirectView.as_view(url='/bar/')(self.rf.delete('/foo/')) - self.assertEqual(response.status_code, 301) + self.assertEqual(response.status_code, 302) self.assertEqual(response.url, '/bar/') def test_redirect_when_meta_contains_no_query_string(self): "regression for #16705" # we can't use self.rf.get because it always sets QUERY_STRING response = RedirectView.as_view(url='/bar/')(self.rf.request(PATH_INFO='/foo/')) - self.assertEqual(response.status_code, 301) + self.assertEqual(response.status_code, 302) def test_direct_instantiation(self): """ @@ -454,69 +456,6 @@ class RedirectViewTest(TestCase): self.assertEqual(response.status_code, 410) -@override_settings(ROOT_URLCONF='generic_views.urls') -class RedirectViewDeprecationTest(TestCase): - - rf = RequestFactory() - - def test_deprecation_warning_init(self): - with warnings.catch_warnings(record=True) as warns: - warnings.simplefilter('always') - - view = RedirectView() - response = view.dispatch(self.rf.head('/python/')) - - self.assertEqual(response.status_code, 410) - self.assertEqual(len(warns), 1) - self.assertIs(warns[0].category, RemovedInDjango19Warning) - self.assertEqual( - six.text_type(warns[0].message), - "Default value of 'RedirectView.permanent' will change " - "from True to False in Django 1.9. Set an explicit value " - "to silence this warning.", - ) - - def test_deprecation_warning_raised_when_permanent_not_passed(self): - with warnings.catch_warnings(record=True) as warns: - warnings.simplefilter('always') - - view_function = RedirectView.as_view(url='/bbb/') - request = self.rf.request(PATH_INFO='/aaa/') - view_function(request) - - self.assertEqual(len(warns), 1) - self.assertIs(warns[0].category, RemovedInDjango19Warning) - self.assertEqual( - six.text_type(warns[0].message), - "Default value of 'RedirectView.permanent' will change " - "from True to False in Django 1.9. Set an explicit value " - "to silence this warning.", - ) - - def test_no_deprecation_warning_when_permanent_passed(self): - with warnings.catch_warnings(record=True) as warns: - warnings.simplefilter('always') - - view_function = RedirectView.as_view(url='/bar/', permanent=False) - request = self.rf.request(PATH_INFO='/foo/') - view_function(request) - - self.assertEqual(len(warns), 0) - - def test_no_deprecation_warning_with_custom_redirectview(self): - class CustomRedirectView(RedirectView): - permanent = False - - with warnings.catch_warnings(record=True) as warns: - warnings.simplefilter('always') - - view_function = CustomRedirectView.as_view(url='/eggs/') - request = self.rf.request(PATH_INFO='/spam/') - view_function(request) - - self.assertEqual(len(warns), 0) - - class GetContextDataTest(unittest.TestCase): def test_get_context_data_super(self): |
