summaryrefslogtreecommitdiff
path: root/tests/httpwrappers
diff options
context:
space:
mode:
authorTom Carrick <tom@carrick.eu>2020-09-15 12:43:37 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-10-07 09:19:57 +0200
commitdcb69043d0de45bb55998fc418d93c28bc7689ae (patch)
treeac58b959d8b749965841721e6cc2a58784bb51c3 /tests/httpwrappers
parent2e7cc95499f758a1c4aa036cbf1dcddf82a89ea2 (diff)
Fixed #32002 -- Added headers parameter to HttpResponse and subclasses.
Diffstat (limited to 'tests/httpwrappers')
-rw-r--r--tests/httpwrappers/tests.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py
index fbc5019979..cbf8b7d586 100644
--- a/tests/httpwrappers/tests.py
+++ b/tests/httpwrappers/tests.py
@@ -286,7 +286,7 @@ class QueryDictTests(SimpleTestCase):
QueryDict.fromkeys(0)
-class HttpResponseTests(unittest.TestCase):
+class HttpResponseTests(SimpleTestCase):
def test_headers_type(self):
r = HttpResponse()
@@ -470,10 +470,31 @@ class HttpResponseTests(unittest.TestCase):
# del doesn't raise a KeyError on nonexistent headers.
del r.headers['X-Foo']
+ def test_instantiate_with_headers(self):
+ r = HttpResponse('hello', headers={'X-Foo': 'foo'})
+ self.assertEqual(r.headers['X-Foo'], 'foo')
+ self.assertEqual(r.headers['x-foo'], 'foo')
+
def test_content_type(self):
r = HttpResponse('hello', content_type='application/json')
self.assertEqual(r.headers['Content-Type'], 'application/json')
+ def test_content_type_headers(self):
+ r = HttpResponse('hello', headers={'Content-Type': 'application/json'})
+ self.assertEqual(r.headers['Content-Type'], 'application/json')
+
+ def test_content_type_mutually_exclusive(self):
+ msg = (
+ "'headers' must not contain 'Content-Type' when the "
+ "'content_type' parameter is provided."
+ )
+ with self.assertRaisesMessage(ValueError, msg):
+ HttpResponse(
+ 'hello',
+ content_type='application/json',
+ headers={'Content-Type': 'text/csv'},
+ )
+
class HttpResponseSubclassesTests(SimpleTestCase):
def test_redirect(self):