diff options
| author | Baptiste Mispelon <bmispelon@gmail.com> | 2013-04-20 05:20:01 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-07-30 13:39:44 -0400 |
| commit | 3c45fb8589bfff580bb4d9d3c13172183c597abd (patch) | |
| tree | 46eb2abba2f22915f7cb388e968e622fb1a01c5e /tests/httpwrappers | |
| parent | 75cf5fc7f0244c081cc25651d066de3ba852f1e8 (diff) | |
Fixed #10491 -- Allowed passing lazy objects to HttpResponseRedirect.
Thanks liangent for the report.
Diffstat (limited to 'tests/httpwrappers')
| -rw-r--r-- | tests/httpwrappers/tests.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py index 3a2ec23864..1679b6e036 100644 --- a/tests/httpwrappers/tests.py +++ b/tests/httpwrappers/tests.py @@ -16,10 +16,13 @@ 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 +lazystr = lazy(force_text, six.text_type) + class QueryDictTests(unittest.TestCase): def test_missing_key(self): @@ -366,6 +369,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") @@ -402,6 +409,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) |
