diff options
| author | Tim Graham <timograham@gmail.com> | 2016-04-25 07:56:07 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-04-25 07:56:07 -0400 |
| commit | bb0b4b705b508451567bcada9106b91b8fca9e86 (patch) | |
| tree | e7239192a52349d084f621d7bf6ffe656447de80 /tests/http_utils | |
| parent | bd145e7209a0e628cced10384bd6f62d65c0f211 (diff) | |
Fixed #26052 -- Moved conditional_content_removal() processing to the test client.
Diffstat (limited to 'tests/http_utils')
| -rw-r--r-- | tests/http_utils/tests.py | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/tests/http_utils/tests.py b/tests/http_utils/tests.py deleted file mode 100644 index 53e06c8938..0000000000 --- a/tests/http_utils/tests.py +++ /dev/null @@ -1,71 +0,0 @@ -from __future__ import unicode_literals - -import gzip -import io - -from django.http import HttpRequest, HttpResponse, StreamingHttpResponse -from django.http.utils import conditional_content_removal -from django.test import SimpleTestCase - - -# based on Python 3.3's gzip.compress -def gzip_compress(data): - buf = io.BytesIO() - f = gzip.GzipFile(fileobj=buf, mode='wb', compresslevel=0) - try: - f.write(data) - finally: - f.close() - return buf.getvalue() - - -class HttpUtilTests(SimpleTestCase): - - def test_conditional_content_removal(self): - """ - Tests that content is removed from regular and streaming responses with - a status_code of 100-199, 204, 304 or a method of "HEAD". - """ - req = HttpRequest() - - # Do nothing for 200 responses. - res = HttpResponse('abc') - conditional_content_removal(req, res) - self.assertEqual(res.content, b'abc') - - res = StreamingHttpResponse(['abc']) - conditional_content_removal(req, res) - self.assertEqual(b''.join(res), b'abc') - - # Strip content for some status codes. - for status_code in (100, 150, 199, 204, 304): - res = HttpResponse('abc', status=status_code) - conditional_content_removal(req, res) - self.assertEqual(res.content, b'') - - res = StreamingHttpResponse(['abc'], status=status_code) - conditional_content_removal(req, res) - self.assertEqual(b''.join(res), b'') - - # Issue #20472 - abc = gzip_compress(b'abc') - res = HttpResponse(abc, status=304) - res['Content-Encoding'] = 'gzip' - conditional_content_removal(req, res) - self.assertEqual(res.content, b'') - - res = StreamingHttpResponse([abc], status=304) - res['Content-Encoding'] = 'gzip' - conditional_content_removal(req, res) - self.assertEqual(b''.join(res), b'') - - # Strip content for HEAD requests. - req.method = 'HEAD' - - res = HttpResponse('abc') - conditional_content_removal(req, res) - self.assertEqual(res.content, b'') - - res = StreamingHttpResponse(['abc']) - conditional_content_removal(req, res) - self.assertEqual(b''.join(res), b'') |
