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
6bbfbf77
Commit
6bbfbf77
authored
Jul 15, 2011
by
Tom Drummond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests to ensure you can access request.POST with UserLoggedInAuthentication
parent
73ad2e50
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
1 deletions
+52
-1
djangorestframework/tests/content.py
+52
-1
No files found.
djangorestframework/tests/content.py
View file @
6bbfbf77
"""
"""
Tests for content parsing, and form-overloaded content parsing.
Tests for content parsing, and form-overloaded content parsing.
"""
"""
from
django.test
import
TestCase
from
django.conf.urls.defaults
import
patterns
from
django.contrib.auth.models
import
User
from
django.test
import
TestCase
,
Client
from
djangorestframework
import
status
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
from
djangorestframework.response
import
Response
from
djangorestframework.views
import
View
class
MockView
(
View
):
authentication
=
(
UserLoggedInAuthentication
,)
def
post
(
self
,
request
):
if
request
.
POST
.
get
(
'example'
)
is
not
None
:
return
Response
(
status
.
OK
)
return
Response
(
status
.
INTERNAL_SERVER_ERROR
)
urlpatterns
=
patterns
(
''
,
(
r'^$'
,
MockView
.
as_view
()),
)
class
TestContentParsing
(
TestCase
):
class
TestContentParsing
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -84,3 +102,36 @@ class TestContentParsing(TestCase):
...
@@ -84,3 +102,36 @@ 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
)
class
TestContentParsingWithAuthentication
(
TestCase
):
urls
=
'djangorestframework.tests.content'
def
setUp
(
self
):
self
.
csrf_client
=
Client
(
enforce_csrf_checks
=
True
)
self
.
username
=
'john'
self
.
email
=
'lennon@thebeatles.com'
self
.
password
=
'password'
self
.
user
=
User
.
objects
.
create_user
(
self
.
username
,
self
.
email
,
self
.
password
)
self
.
req
=
RequestFactory
()
def
test_user_logged_in_authentication_has_post_when_not_logged_in
(
self
):
"""Ensures request.POST exists after UserLoggedInAuthentication when user doesn't log in"""
content
=
{
'example'
:
'example'
}
response
=
self
.
client
.
post
(
'/'
,
content
)
self
.
assertEqual
(
status
.
OK
,
response
.
status_code
)
response
=
self
.
csrf_client
.
post
(
'/'
,
content
)
self
.
assertEqual
(
status
.
OK
,
response
.
status_code
)
def
test_user_logged_in_authentication_has_post_when_logged_in
(
self
):
"""Ensures request.POST exists after UserLoggedInAuthentication when user does log in"""
self
.
client
.
login
(
username
=
'john'
,
password
=
'password'
)
self
.
csrf_client
.
login
(
username
=
'john'
,
password
=
'password'
)
content
=
{
'example'
:
'example'
}
response
=
self
.
client
.
post
(
'/'
,
content
)
self
.
assertEqual
(
status
.
OK
,
response
.
status_code
,
"POST data"
)
response
=
self
.
csrf_client
.
post
(
'/'
,
content
)
self
.
assertEqual
(
status
.
OK
,
response
.
status_code
)
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