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
7e2e3cbf
Commit
7e2e3cbf
authored
Jul 15, 2011
by
Tom Drummond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added more tests related to request.POST and request.DATA
parent
6bbfbf77
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
5 deletions
+64
-5
djangorestframework/tests/content.py
+64
-5
No files found.
djangorestframework/tests/content.py
View file @
7e2e3cbf
...
@@ -8,7 +8,8 @@ from djangorestframework import status
...
@@ -8,7 +8,8 @@ from djangorestframework import status
from
djangorestframework.authentication
import
UserLoggedInAuthentication
from
djangorestframework.authentication
import
UserLoggedInAuthentication
from
djangorestframework.compat
import
RequestFactory
from
djangorestframework.compat
import
RequestFactory
from
djangorestframework.mixins
import
RequestMixin
from
djangorestframework.mixins
import
RequestMixin
from
djangorestframework.parsers
import
FormParser
,
MultiPartParser
,
PlainTextParser
from
djangorestframework.parsers
import
FormParser
,
MultiPartParser
,
\
PlainTextParser
,
JSONParser
from
djangorestframework.response
import
Response
from
djangorestframework.response
import
Response
from
djangorestframework.views
import
View
from
djangorestframework.views
import
View
...
@@ -102,6 +103,64 @@ class TestContentParsing(TestCase):
...
@@ -102,6 +103,64 @@ class TestContentParsing(TestCase):
view
.
request
=
self
.
req
.
post
(
'/'
,
form_data
)
view
.
request
=
self
.
req
.
post
(
'/'
,
form_data
)
view
.
parsers
=
(
PlainTextParser
,)
view
.
parsers
=
(
PlainTextParser
,)
self
.
assertEqual
(
view
.
DATA
,
content
)
self
.
assertEqual
(
view
.
DATA
,
content
)
def
test_accessing_post_after_data_form
(
self
):
"""Ensures request.POST can be accessed after request.DATA in form request"""
form_data
=
{
'qwerty'
:
'uiop'
}
view
=
RequestMixin
()
view
.
parsers
=
(
FormParser
,
MultiPartParser
)
view
.
request
=
self
.
req
.
post
(
'/'
,
data
=
form_data
)
self
.
assertEqual
(
view
.
DATA
.
items
(),
form_data
.
items
())
self
.
assertEqual
(
view
.
request
.
POST
.
items
(),
form_data
.
items
())
def
test_empty_post_after_data_for_json
(
self
):
"""Ensures request.POST can be accessed after request.DATA in json request"""
from
django.utils
import
simplejson
as
json
data
=
{
'qwerty'
:
'uiop'
}
content
=
json
.
dumps
(
data
)
content_type
=
'application/json'
view
=
RequestMixin
()
view
.
parsers
=
(
JSONParser
,)
form_data
=
{
view
.
_CONTENT_PARAM
:
content
,
view
.
_CONTENTTYPE_PARAM
:
content_type
}
view
.
request
=
self
.
req
.
post
(
'/'
,
data
=
form_data
)
self
.
assertEqual
(
view
.
DATA
.
items
(),
data
.
items
())
self
.
assertEqual
(
view
.
request
.
POST
.
items
(),
form_data
.
items
())
def
test_accessing_data_after_post_form
(
self
):
"""Ensures request.DATA can be accessed after request.POST in form request"""
form_data
=
{
'qwerty'
:
'uiop'
}
view
=
RequestMixin
()
view
.
parsers
=
(
FormParser
,
MultiPartParser
)
view
.
request
=
self
.
req
.
post
(
'/'
,
data
=
form_data
)
self
.
assertEqual
(
view
.
request
.
POST
.
items
(),
form_data
.
items
())
self
.
assertEqual
(
view
.
DATA
.
items
(),
form_data
.
items
())
def
test_accessing_data_after_post_json
(
self
):
"""Ensures request.DATA can be accessed after request.POST in json request"""
from
django.utils
import
simplejson
as
json
data
=
{
'qwerty'
:
'uiop'
}
content
=
json
.
dumps
(
data
)
content_type
=
'application/json'
view
=
RequestMixin
()
view
.
parsers
=
(
JSONParser
,)
form_data
=
{
view
.
_CONTENT_PARAM
:
content
,
view
.
_CONTENTTYPE_PARAM
:
content_type
}
view
.
request
=
self
.
req
.
post
(
'/'
,
data
=
form_data
)
self
.
assertEqual
(
view
.
request
.
POST
.
items
(),
form_data
.
items
())
self
.
assertEqual
(
view
.
DATA
.
items
(),
data
.
items
())
class
TestContentParsingWithAuthentication
(
TestCase
):
class
TestContentParsingWithAuthentication
(
TestCase
):
urls
=
'djangorestframework.tests.content'
urls
=
'djangorestframework.tests.content'
...
@@ -119,10 +178,10 @@ class TestContentParsingWithAuthentication(TestCase):
...
@@ -119,10 +178,10 @@ class TestContentParsingWithAuthentication(TestCase):
content
=
{
'example'
:
'example'
}
content
=
{
'example'
:
'example'
}
response
=
self
.
client
.
post
(
'/'
,
content
)
response
=
self
.
client
.
post
(
'/'
,
content
)
self
.
assertEqual
(
status
.
OK
,
response
.
status_code
)
self
.
assertEqual
(
status
.
OK
,
response
.
status_code
,
"POST data is malformed"
)
response
=
self
.
csrf_client
.
post
(
'/'
,
content
)
response
=
self
.
csrf_client
.
post
(
'/'
,
content
)
self
.
assertEqual
(
status
.
OK
,
response
.
status_code
)
self
.
assertEqual
(
status
.
OK
,
response
.
status_code
,
"POST data is malformed"
)
def
test_user_logged_in_authentication_has_post_when_logged_in
(
self
):
def
test_user_logged_in_authentication_has_post_when_logged_in
(
self
):
"""Ensures request.POST exists after UserLoggedInAuthentication when user does log in"""
"""Ensures request.POST exists after UserLoggedInAuthentication when user does log in"""
...
@@ -131,7 +190,7 @@ class TestContentParsingWithAuthentication(TestCase):
...
@@ -131,7 +190,7 @@ class TestContentParsingWithAuthentication(TestCase):
content
=
{
'example'
:
'example'
}
content
=
{
'example'
:
'example'
}
response
=
self
.
client
.
post
(
'/'
,
content
)
response
=
self
.
client
.
post
(
'/'
,
content
)
self
.
assertEqual
(
status
.
OK
,
response
.
status_code
,
"POST data"
)
self
.
assertEqual
(
status
.
OK
,
response
.
status_code
,
"POST data
is malformed
"
)
response
=
self
.
csrf_client
.
post
(
'/'
,
content
)
response
=
self
.
csrf_client
.
post
(
'/'
,
content
)
self
.
assertEqual
(
status
.
OK
,
response
.
status_code
)
self
.
assertEqual
(
status
.
OK
,
response
.
status_code
,
"POST data is malformed"
)
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