1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Corrected deprecation warnings for RedirectView; refs #21587.

This commit is contained in:
Berker Peksag
2014-11-27 05:44:56 +02:00
committed by Tim Graham
parent 9253042d53
commit 47789410db
6 changed files with 49 additions and 52 deletions

View File

@@ -22,11 +22,8 @@ rather than the HTML rendered to the end-user.
"""
from __future__ import unicode_literals
import warnings
from django.core import mail
from django.http import HttpResponse
from django.utils.deprecation import RemovedInDjango19Warning
from django.test import Client, TestCase, RequestFactory
from django.test import override_settings
@@ -177,18 +174,14 @@ class ClientTest(TestCase):
def test_permanent_redirect(self):
"GET a URL that redirects permanently elsewhere"
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango19Warning)
response = self.client.get('/permanent_redirect_view/')
# Check that the response was a 301 (permanent redirect)
self.assertRedirects(response, 'http://testserver/get_view/', status_code=301)
response = self.client.get('/permanent_redirect_view/')
# Check that the response was a 301 (permanent redirect)
self.assertRedirects(response, 'http://testserver/get_view/', status_code=301)
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango19Warning)
client_providing_host = Client(HTTP_HOST='django.testserver')
response = client_providing_host.get('/permanent_redirect_view/')
# Check that the response was a 301 (permanent redirect) with absolute URI
self.assertRedirects(response, 'http://django.testserver/get_view/', status_code=301)
client_providing_host = Client(HTTP_HOST='django.testserver')
response = client_providing_host.get('/permanent_redirect_view/')
# Check that the response was a 301 (permanent redirect) with absolute URI
self.assertRedirects(response, 'http://django.testserver/get_view/', status_code=301)
def test_temporary_redirect(self):
"GET a URL that does a non-permanent redirect"
@@ -198,34 +191,26 @@ class ClientTest(TestCase):
def test_redirect_to_strange_location(self):
"GET a URL that redirects to a non-200 page"
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango19Warning)
response = self.client.get('/double_redirect_view/')
response = self.client.get('/double_redirect_view/')
# Check that the response was a 302, and that
# the attempt to get the redirection location returned 301 when retrieved
self.assertRedirects(response, 'http://testserver/permanent_redirect_view/', target_status_code=301)
# Check that the response was a 302, and that
# the attempt to get the redirection location returned 301 when retrieved
self.assertRedirects(response, 'http://testserver/permanent_redirect_view/', target_status_code=301)
def test_follow_redirect(self):
"A URL that redirects can be followed to termination."
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango19Warning)
response = self.client.get('/double_redirect_view/', follow=True)
self.assertRedirects(response, 'http://testserver/get_view/', status_code=302, target_status_code=200)
response = self.client.get('/double_redirect_view/', follow=True)
self.assertRedirects(response, 'http://testserver/get_view/', status_code=302, target_status_code=200)
self.assertEqual(len(response.redirect_chain), 2)
def test_redirect_http(self):
"GET a URL that redirects to an http URI"
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango19Warning)
response = self.client.get('/http_redirect_view/', follow=True)
response = self.client.get('/http_redirect_view/', follow=True)
self.assertFalse(response.test_was_secure_request)
def test_redirect_https(self):
"GET a URL that redirects to an https URI"
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInDjango19Warning)
response = self.client.get('/https_redirect_view/', follow=True)
response = self.client.get('/https_redirect_view/', follow=True)
self.assertTrue(response.test_was_secure_request)
def test_notfound_response(self):