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
0fe8d1a1
Commit
0fe8d1a1
authored
Apr 11, 2011
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
form overloading tests passing
parent
e29a3f4c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
19 deletions
+29
-19
djangorestframework/mediatypes.py
+1
-1
djangorestframework/request.py
+8
-0
djangorestframework/tests/content.py
+20
-18
No files found.
djangorestframework/mediatypes.py
View file @
0fe8d1a1
...
...
@@ -63,7 +63,7 @@ class MediaType(object):
"""
return
self
.
media_type
==
'application/x-www-form-urlencoded'
or
\
self
.
media_type
==
'multipart/form-data'
def
as_tuple
(
self
):
return
(
self
.
main_type
,
self
.
sub_type
,
self
.
params
)
...
...
djangorestframework/request.py
View file @
0fe8d1a1
from
djangorestframework.mediatypes
import
MediaType
from
djangorestframework.utils
import
as_tuple
from
djangorestframework.response
import
ResponseException
from
djangorestframework.parsers
import
FormParser
,
MultipartParser
from
djangorestframework
import
status
#from djangorestframework.requestparsing import parse, load_parser
...
...
@@ -151,11 +152,18 @@ class RequestMixin(object):
if
not
self
.
USE_FORM_OVERLOADING
or
self
.
method
!=
'POST'
or
not
self
.
content_type
.
is_form
():
return
# Temporarily switch to using the form parsers, then parse the content
parsers
=
self
.
parsers
self
.
parsers
=
(
FormParser
,
MultipartParser
)
content
=
self
.
RAW_CONTENT
self
.
parsers
=
parsers
# Method overloading - change the method and remove the param from the content
if
self
.
METHOD_PARAM
in
content
:
self
.
method
=
content
[
self
.
METHOD_PARAM
]
.
upper
()
del
self
.
_raw_content
[
self
.
METHOD_PARAM
]
# Content overloading - rewind the stream and modify the content type
if
self
.
CONTENT_PARAM
in
content
and
self
.
CONTENTTYPE_PARAM
in
content
:
self
.
_content_type
=
MediaType
(
content
[
self
.
CONTENTTYPE_PARAM
])
self
.
_stream
=
StringIO
(
content
[
self
.
CONTENT_PARAM
])
...
...
djangorestframework/tests/content.py
View file @
0fe8d1a1
...
...
@@ -67,25 +67,25 @@ class TestContentMixins(TestCase):
self
.
assertEqual
(
view
.
RAW_CONTENT
,
content
)
def
test_standard_behaviour_determines_no_content_GET
(
self
):
"""Ensure
request
.RAW_CONTENT returns None for GET request with no content."""
"""Ensure
view
.RAW_CONTENT returns None for GET request with no content."""
self
.
ensure_determines_no_content_GET
(
RequestMixin
())
def
test_standard_behaviour_determines_form_content_POST
(
self
):
"""Ensure
request
.RAW_CONTENT returns content for POST request with form content."""
"""Ensure
view
.RAW_CONTENT returns content for POST request with form content."""
self
.
ensure_determines_form_content_POST
(
RequestMixin
())
def
test_standard_behaviour_determines_non_form_content_POST
(
self
):
"""Ensure
StandardContentMixin.determine_content(request) returns (content type, content) for POST request with
content."""
"""Ensure
view.RAW_CONTENT returns content for POST request with non-form
content."""
self
.
ensure_determines_non_form_content_POST
(
RequestMixin
())
def
test_standard_behaviour_determines_form_content_PUT
(
self
):
"""Ensure
StandardContentMixin.determine_content(request) returns content for PUT request with
content."""
"""Ensure
view.RAW_CONTENT returns content for PUT request with form
content."""
self
.
ensure_determines_form_content_PUT
(
RequestMixin
())
#
def test_standard_behaviour_determines_non_form_content_PUT(self):
# """Ensure StandardContentMixin.determine_content(request) returns (content type, content) for PUT request with
content."""
# self.ensure_determines_non_form_content_PUT(StandardConten
tMixin())
#
def
test_standard_behaviour_determines_non_form_content_PUT
(
self
):
"""Ensure view.RAW_CONTENT returns content for PUT request with non-form
content."""
self
.
ensure_determines_non_form_content_PUT
(
Reques
tMixin
())
# # OverloadedContentMixin behavioural tests
#
# def test_overloaded_behaviour_determines_no_content_GET(self):
...
...
@@ -108,16 +108,18 @@ class TestContentMixins(TestCase):
# """Ensure StandardContentMixin.determine_content(request) returns (content type, content) for PUT request with content."""
# self.ensure_determines_non_form_content_PUT(OverloadedContentMixin())
#
# def test_overloaded_behaviour_allows_content_tunnelling(self):
# """Ensure determine_content(request) returns (content type, content) for overloaded POST request"""
# content = 'qwerty'
# content_type = 'text/plain'
# form_data = {OverloadedContentMixin.CONTENT_PARAM: content,
# OverloadedContentMixin.CONTENTTYPE_PARAM: content_type}
# request = self.req.post('/', form_data)
# self.assertEqual(OverloadedContentMixin().determine_content(request), (content_type, content))
# self.assertEqual(request.META['CONTENT_TYPE'], content_type)
#
def
test_overloaded_behaviour_allows_content_tunnelling
(
self
):
"""Ensure request.RAW_CONTENT returns content for overloaded POST request"""
content
=
'qwerty'
content_type
=
'text/plain'
view
=
RequestMixin
()
form_data
=
{
view
.
CONTENT_PARAM
:
content
,
view
.
CONTENTTYPE_PARAM
:
content_type
}
view
.
request
=
self
.
req
.
post
(
'/'
,
form_data
)
view
.
parsers
=
(
PlainTextParser
,)
view
.
perform_form_overloading
()
self
.
assertEqual
(
view
.
RAW_CONTENT
,
content
)
# def test_overloaded_behaviour_allows_content_tunnelling_content_type_not_set(self):
# """Ensure determine_content(request) returns (None, content) for overloaded POST request with content type not set"""
# content = 'qwerty'
...
...
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