1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[1.6.x] Fixed #10491 -- Allowed passing lazy objects to HttpResponseRedirect.

Thanks liangent for the report.

Backport of 3c45fb8589 from master
This commit is contained in:
Baptiste Mispelon
2013-04-20 05:20:01 +02:00
committed by Tim Graham
parent bf132bcb8d
commit badca4716f
2 changed files with 15 additions and 3 deletions

View File

@@ -15,11 +15,14 @@ from django.http import (QueryDict, HttpResponse, HttpResponseRedirect,
SimpleCookie, BadHeaderError,
parse_cookie)
from django.test import TestCase
from django.utils.encoding import smart_str
from django.utils.encoding import smart_str, force_text
from django.utils.functional import lazy
from django.utils._os import upath
from django.utils import six
from django.utils import unittest
lazystr = lazy(force_text, six.text_type)
class QueryDictTests(unittest.TestCase):
def test_missing_key(self):
@@ -379,6 +382,10 @@ class HttpResponseTests(unittest.TestCase):
self.assertEqual(list(i), [b'abc'])
self.assertEqual(list(i), [])
def test_lazy_content(self):
r = HttpResponse(lazystr('helloworld'))
self.assertEqual(r.content, b'helloworld')
def test_file_interface(self):
r = HttpResponse()
r.write(b"hello")
@@ -415,6 +422,11 @@ class HttpResponseSubclassesTests(TestCase):
# Test that url attribute is right
self.assertEqual(response.url, response['Location'])
def test_redirect_lazy(self):
"""Make sure HttpResponseRedirect works with lazy strings."""
r = HttpResponseRedirect(lazystr('/redirected/'))
self.assertEqual(r.url, '/redirected/')
def test_not_modified(self):
response = HttpResponseNotModified()
self.assertEqual(response.status_code, 304)