Fixed #7583 -- Corrected the testing docs that referred to the defunct headers attribute of the response. Added a test case to validate (and document) the new behavior. Thanks to Malcolm for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7900 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b038abe1fe
commit
4aa6c57251
|
@ -600,8 +600,6 @@ Specifically, a ``Response`` object has the following attributes:
|
||||||
``context`` will be a list of ``Context``
|
``context`` will be a list of ``Context``
|
||||||
objects, in the order in which they were rendered.
|
objects, in the order in which they were rendered.
|
||||||
|
|
||||||
``headers`` The HTTP headers of the response. This is a dictionary.
|
|
||||||
|
|
||||||
``request`` The request data that stimulated the response.
|
``request`` The request data that stimulated the response.
|
||||||
|
|
||||||
``status_code`` The HTTP status of the response, as an integer. See
|
``status_code`` The HTTP status of the response, as an integer. See
|
||||||
|
@ -619,6 +617,10 @@ Specifically, a ``Response`` object has the following attributes:
|
||||||
which they were rendered.
|
which they were rendered.
|
||||||
=============== ==========================================================
|
=============== ==========================================================
|
||||||
|
|
||||||
|
You can also use dictionary syntax on the response object to query the value
|
||||||
|
of any settings in the HTTP headers. For example, you could determine the
|
||||||
|
content type of a response using ``response['Content-Type']``.
|
||||||
|
|
||||||
.. _RFC2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
|
.. _RFC2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
|
||||||
.. _template inheritance: ../templates/#template-inheritance
|
.. _template inheritance: ../templates/#template-inheritance
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,13 @@ class ClientTest(TestCase):
|
||||||
self.assertEqual(response.context['data'], '37')
|
self.assertEqual(response.context['data'], '37')
|
||||||
self.assertEqual(response.template.name, 'POST Template')
|
self.assertEqual(response.template.name, 'POST Template')
|
||||||
self.failUnless('Data received' in response.content)
|
self.failUnless('Data received' in response.content)
|
||||||
|
|
||||||
|
def test_response_headers(self):
|
||||||
|
"Check the value of HTTP headers returned in a response"
|
||||||
|
response = self.client.get("/test_client/header_view/")
|
||||||
|
|
||||||
|
self.assertEquals(response['X-DJANGO-TEST'], 'Slartibartfast')
|
||||||
|
|
||||||
def test_raw_post(self):
|
def test_raw_post(self):
|
||||||
"POST raw data (with a content type) to a view"
|
"POST raw data (with a content type) to a view"
|
||||||
test_doc = """<?xml version="1.0" encoding="utf-8"?><library><book><title>Blink</title><author>Malcolm Gladwell</author></book></library>"""
|
test_doc = """<?xml version="1.0" encoding="utf-8"?><library><book><title>Blink</title><author>Malcolm Gladwell</author></book></library>"""
|
||||||
|
|
|
@ -5,6 +5,7 @@ import views
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
(r'^get_view/$', views.get_view),
|
(r'^get_view/$', views.get_view),
|
||||||
(r'^post_view/$', views.post_view),
|
(r'^post_view/$', views.post_view),
|
||||||
|
(r'^header_view/$', views.view_with_header),
|
||||||
(r'^raw_post_view/$', views.raw_post_view),
|
(r'^raw_post_view/$', views.raw_post_view),
|
||||||
(r'^redirect_view/$', views.redirect_view),
|
(r'^redirect_view/$', views.redirect_view),
|
||||||
(r'^permanent_redirect_view/$', redirect_to, { 'url': '/test_client/get_view/' }),
|
(r'^permanent_redirect_view/$', redirect_to, { 'url': '/test_client/get_view/' }),
|
||||||
|
|
|
@ -32,6 +32,12 @@ def post_view(request):
|
||||||
|
|
||||||
return HttpResponse(t.render(c))
|
return HttpResponse(t.render(c))
|
||||||
|
|
||||||
|
def view_with_header(request):
|
||||||
|
"A view that has a custom header"
|
||||||
|
response = HttpResponse()
|
||||||
|
response['X-DJANGO-TEST'] = 'Slartibartfast'
|
||||||
|
return response
|
||||||
|
|
||||||
def raw_post_view(request):
|
def raw_post_view(request):
|
||||||
"""A view which expects raw XML to be posted and returns content extracted
|
"""A view which expects raw XML to be posted and returns content extracted
|
||||||
from the XML"""
|
from the XML"""
|
||||||
|
|
Loading…
Reference in New Issue