Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
d3557bdc
Commit
d3557bdc
authored
Jun 25, 2011
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Allow HEAD method
parents
50efa106
0626b618
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
5 deletions
+33
-5
djangorestframework/compat.py
+11
-2
djangorestframework/tests/content.py
+9
-1
djangorestframework/tests/methods.py
+6
-0
djangorestframework/tests/renderers.py
+7
-2
No files found.
djangorestframework/compat.py
View file @
d3557bdc
...
...
@@ -67,6 +67,14 @@ except ImportError:
# django.views.generic.View (Django >= 1.3)
try
:
from
django.views.generic
import
View
if
not
hasattr
(
View
,
'head'
):
# First implementation of Django class-based views did not include head method
# in base View class - https://code.djangoproject.com/ticket/15688
class
ViewPlusHead
(
View
):
def
head
(
self
,
request
,
*
args
,
**
kwargs
):
return
self
.
get
(
request
,
*
args
,
**
kwargs
)
View
=
ViewPlusHead
except
ImportError
:
from
django
import
http
from
django.utils.functional
import
update_wrapper
...
...
@@ -145,6 +153,8 @@ except ImportError:
#)
return
http
.
HttpResponseNotAllowed
(
allowed_methods
)
def
head
(
self
,
request
,
*
args
,
**
kwargs
):
return
self
.
get
(
request
,
*
args
,
**
kwargs
)
try
:
import
markdown
...
...
@@ -193,4 +203,4 @@ try:
return
md
.
convert
(
text
)
except
ImportError
:
apply_markdown
=
None
\ No newline at end of file
apply_markdown
=
None
djangorestframework/tests/content.py
View file @
d3557bdc
...
...
@@ -6,7 +6,6 @@ from djangorestframework.compat import RequestFactory
from
djangorestframework.mixins
import
RequestMixin
from
djangorestframework.parsers
import
FormParser
,
MultiPartParser
,
PlainTextParser
class
TestContentParsing
(
TestCase
):
def
setUp
(
self
):
self
.
req
=
RequestFactory
()
...
...
@@ -16,6 +15,11 @@ class TestContentParsing(TestCase):
view
.
request
=
self
.
req
.
get
(
'/'
)
self
.
assertEqual
(
view
.
DATA
,
None
)
def
ensure_determines_no_content_HEAD
(
self
,
view
):
"""Ensure view.DATA returns None for HEAD request."""
view
.
request
=
self
.
req
.
head
(
'/'
)
self
.
assertEqual
(
view
.
DATA
,
None
)
def
ensure_determines_form_content_POST
(
self
,
view
):
"""Ensure view.DATA returns content for POST request with form content."""
form_data
=
{
'qwerty'
:
'uiop'
}
...
...
@@ -50,6 +54,10 @@ class TestContentParsing(TestCase):
"""Ensure view.DATA returns None for GET request with no content."""
self
.
ensure_determines_no_content_GET
(
RequestMixin
())
def
test_standard_behaviour_determines_no_content_HEAD
(
self
):
"""Ensure view.DATA returns None for HEAD request."""
self
.
ensure_determines_no_content_HEAD
(
RequestMixin
())
def
test_standard_behaviour_determines_form_content_POST
(
self
):
"""Ensure view.DATA returns content for POST request with form content."""
self
.
ensure_determines_form_content_POST
(
RequestMixin
())
...
...
djangorestframework/tests/methods.py
View file @
d3557bdc
...
...
@@ -24,3 +24,9 @@ class TestMethodOverloading(TestCase):
view
=
RequestMixin
()
view
.
request
=
self
.
req
.
post
(
'/'
,
{
view
.
_METHOD_PARAM
:
'DELETE'
})
self
.
assertEqual
(
view
.
method
,
'DELETE'
)
def
test_HEAD_is_a_valid_method
(
self
):
"""HEAD requests identified"""
view
=
RequestMixin
()
view
.
request
=
self
.
req
.
head
(
'/'
)
self
.
assertEqual
(
view
.
method
,
'HEAD'
)
djangorestframework/tests/renderers.py
View file @
d3557bdc
...
...
@@ -55,6 +55,13 @@ class RendererIntegrationTests(TestCase):
self
.
assertEquals
(
resp
.
content
,
RENDERER_A_SERIALIZER
(
DUMMYCONTENT
))
self
.
assertEquals
(
resp
.
status_code
,
DUMMYSTATUS
)
def
test_head_method_serializes_no_content
(
self
):
"""No response must be included in HEAD requests."""
resp
=
self
.
client
.
head
(
'/'
)
self
.
assertEquals
(
resp
.
status_code
,
DUMMYSTATUS
)
self
.
assertEquals
(
resp
[
'Content-Type'
],
RendererA
.
media_type
)
self
.
assertEquals
(
resp
.
content
,
''
)
def
test_default_renderer_serializes_content_on_accept_any
(
self
):
"""If the Accept header is set to */* the default renderer should serialize the response."""
resp
=
self
.
client
.
get
(
'/'
,
HTTP_ACCEPT
=
'*/*'
)
...
...
@@ -83,8 +90,6 @@ class RendererIntegrationTests(TestCase):
resp
=
self
.
client
.
get
(
'/'
,
HTTP_ACCEPT
=
'foo/bar'
)
self
.
assertEquals
(
resp
.
status_code
,
406
)
_flat_repr
=
'{"foo": ["bar", "baz"]}'
_indented_repr
=
"""{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment