diff options
author | Michael Kelly <mkelly@mozilla.com> | 2014-04-14 11:58:59 -0400 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2014-11-03 12:29:19 -0500 |
commit | ebc8e79cf3bdd42a99e91d6e679248d07097d3db (patch) | |
tree | 4c4a59eb2a00372efc7ac0794e5fd6f12a635a39 /tests/httpwrappers/tests.py | |
parent | f7969b0920c403118656f6bfec58d6454d79ef1a (diff) | |
download | django-ebc8e79cf3bdd42a99e91d6e679248d07097d3db.tar.gz |
Fixed #18523 -- Added stream-like API to HttpResponse.
Added getvalue() to HttpResponse to return the content of the response,
along with a few other methods to partially match io.IOBase.
Thanks Claude Paroz for the suggestion and Nick Sanford for review.
Diffstat (limited to 'tests/httpwrappers/tests.py')
-rw-r--r-- | tests/httpwrappers/tests.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py index 9b9b19e180..4e705e2aeb 100644 --- a/tests/httpwrappers/tests.py +++ b/tests/httpwrappers/tests.py @@ -407,6 +407,15 @@ class HttpResponseTests(unittest.TestCase): r.write(b'def') self.assertEqual(r.content, b'abcdef') + def test_stream_interface(self): + r = HttpResponse('asdf') + self.assertEqual(r.getvalue(), b'asdf') + + r = HttpResponse() + self.assertEqual(r.writable(), True) + r.writelines(['foo\n', 'bar\n', 'baz\n']) + self.assertEqual(r.content, b'foo\nbar\nbaz\n') + def test_unsafe_redirect(self): bad_urls = [ 'data:text/html,<script>window.alert("xss")</script>', @@ -537,6 +546,9 @@ class StreamingHttpResponseTests(TestCase): with self.assertRaises(Exception): r.tell() + r = StreamingHttpResponse(iter(['hello', 'world'])) + self.assertEqual(r.getvalue(), b'helloworld') + class FileCloseTests(TestCase): |