1
0
mirror of https://github.com/django/django.git synced 2025-10-30 00:56:09 +00:00

Fixed #32002 -- Added headers parameter to HttpResponse and subclasses.

This commit is contained in:
Tom Carrick
2020-09-15 12:43:37 +02:00
committed by Mariusz Felisiak
parent 2e7cc95499
commit dcb69043d0
9 changed files with 115 additions and 32 deletions

View File

@@ -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):