diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/httpwrappers/tests.py | 12 | ||||
| -rw-r--r-- | tests/responses/tests.py | 25 |
2 files changed, 36 insertions, 1 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): diff --git a/tests/responses/tests.py b/tests/responses/tests.py index e80e466a56..9642790b9a 100644 --- a/tests/responses/tests.py +++ b/tests/responses/tests.py @@ -4,14 +4,37 @@ from __future__ import unicode_literals from django.conf import settings from django.http import HttpResponse +from django.http.response import HttpResponseBase from django.test import SimpleTestCase UTF8 = 'utf-8' ISO88591 = 'iso-8859-1' -class HttpResponseTests(SimpleTestCase): +class HttpResponseBaseTests(SimpleTestCase): + def test_closed(self): + r = HttpResponseBase() + self.assertIs(r.closed, False) + + r.close() + self.assertIs(r.closed, True) + + def test_write(self): + r = HttpResponseBase() + self.assertIs(r.writable(), False) + + with self.assertRaisesMessage(IOError, 'This HttpResponseBase instance is not writable'): + r.write('asdf') + with self.assertRaisesMessage(IOError, 'This HttpResponseBase instance is not writable'): + r.writelines(['asdf\n', 'qwer\n']) + def test_tell(self): + r = HttpResponseBase() + with self.assertRaisesMessage(IOError, 'This HttpResponseBase instance cannot tell its position'): + r.tell() + + +class HttpResponseTests(SimpleTestCase): def test_status_code(self): resp = HttpResponse(status=418) self.assertEqual(resp.status_code, 418) |
