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/responses | |
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/responses')
-rw-r--r-- | tests/responses/tests.py | 25 |
1 files changed, 24 insertions, 1 deletions
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) |