Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added tests for conditional_content_removal.

Refs #7581. Thanks mrmachine.
  • Loading branch information...
commit 5e629a015e96a5564a0b0a273e1374b9651ce8e9 1 parent b4066d7
Aymeric Augustin authored October 21, 2012
0  tests/regressiontests/http_utils/__init__.py
No changes.
0  tests/regressiontests/http_utils/models.py
No changes.
45  tests/regressiontests/http_utils/tests.py
... ...
@@ -0,0 +1,45 @@
  1
+from __future__ import unicode_literals
  2
+
  3
+from django.http import HttpRequest, HttpResponse, StreamingHttpResponse
  4
+from django.http.utils import conditional_content_removal
  5
+from django.test import TestCase
  6
+
  7
+
  8
+class HttpUtilTests(TestCase):
  9
+
  10
+    def test_conditional_content_removal(self):
  11
+        """
  12
+        Tests that content is removed from regular and streaming responses with
  13
+        a status_code of 100-199, 204, 304 or a method of "HEAD".
  14
+        """
  15
+        req = HttpRequest()
  16
+
  17
+        # Do nothing for 200 responses.
  18
+        res = HttpResponse('abc')
  19
+        conditional_content_removal(req, res)
  20
+        self.assertEqual(res.content, b'abc')
  21
+
  22
+        res = StreamingHttpResponse(['abc'])
  23
+        conditional_content_removal(req, res)
  24
+        self.assertEqual(b''.join(res), b'abc')
  25
+
  26
+        # Strip content for some status codes.
  27
+        for status_code in (100, 150, 199, 204, 304):
  28
+            res = HttpResponse('abc', status=status_code)
  29
+            conditional_content_removal(req, res)
  30
+            self.assertEqual(res.content, b'')
  31
+
  32
+            res = StreamingHttpResponse(['abc'], status=status_code)
  33
+            conditional_content_removal(req, res)
  34
+            self.assertEqual(b''.join(res), b'')
  35
+
  36
+        # Strip content for HEAD requests.
  37
+        req.method = 'HEAD'
  38
+
  39
+        res = HttpResponse('abc')
  40
+        conditional_content_removal(req, res)
  41
+        self.assertEqual(res.content, b'')
  42
+
  43
+        res = StreamingHttpResponse(['abc'])
  44
+        conditional_content_removal(req, res)
  45
+        self.assertEqual(b''.join(res), b'')

0 notes on commit 5e629a0

Please sign in to comment.
Something went wrong with that request. Please try again.