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
85a921c7
Commit
85a921c7
authored
Nov 24, 2012
by
Mark Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added setter to user property
parent
fd89bca3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
rest_framework/request.py
+9
-0
rest_framework/tests/request.py
+28
-0
No files found.
rest_framework/request.py
View file @
85a921c7
...
@@ -169,6 +169,15 @@ class Request(object):
...
@@ -169,6 +169,15 @@ class Request(object):
self
.
_user
,
self
.
_auth
=
self
.
_authenticate
()
self
.
_user
,
self
.
_auth
=
self
.
_authenticate
()
return
self
.
_user
return
self
.
_user
@user.setter
def
user
(
self
,
value
):
"""
Sets the user on the current request. This is necessary to maintain
compatilbility with django.contrib.auth where the user proprety is
set in the login and logout functions.
"""
self
.
_user
=
value
@property
@property
def
auth
(
self
):
def
auth
(
self
):
"""
"""
...
...
rest_framework/tests/request.py
View file @
85a921c7
...
@@ -3,6 +3,8 @@ Tests for content parsing, and form-overloaded content parsing.
...
@@ -3,6 +3,8 @@ Tests for content parsing, and form-overloaded content parsing.
"""
"""
from
django.conf.urls.defaults
import
patterns
from
django.conf.urls.defaults
import
patterns
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.contrib.auth
import
authenticate
,
login
,
logout
from
django.contrib.sessions.middleware
import
SessionMiddleware
from
django.test
import
TestCase
,
Client
from
django.test
import
TestCase
,
Client
from
django.utils
import
simplejson
as
json
from
django.utils
import
simplejson
as
json
...
@@ -276,3 +278,29 @@ class TestContentParsingWithAuthentication(TestCase):
...
@@ -276,3 +278,29 @@ class TestContentParsingWithAuthentication(TestCase):
# response = self.csrf_client.post('/', content)
# response = self.csrf_client.post('/', content)
# self.assertEqual(status.OK, response.status_code, "POST data is malformed")
# self.assertEqual(status.OK, response.status_code, "POST data is malformed")
class
TestUserSetter
(
TestCase
):
def
setUp
(
self
):
# Pass request object through session middleware so session is
# available to login and logout functions
self
.
request
=
Request
(
factory
.
get
(
'/'
))
SessionMiddleware
()
.
process_request
(
self
.
request
)
User
.
objects
.
create_user
(
'ringo'
,
'starr@thebeatles.com'
,
'yellow'
)
self
.
user
=
authenticate
(
username
=
'ringo'
,
password
=
'yellow'
)
def
test_user_can_be_set
(
self
):
self
.
request
.
user
=
self
.
user
self
.
assertEqual
(
self
.
request
.
user
,
self
.
user
)
def
test_user_can_login
(
self
):
login
(
self
.
request
,
self
.
user
)
self
.
assertEqual
(
self
.
request
.
user
,
self
.
user
)
def
test_user_can_logout
(
self
):
self
.
request
.
user
=
self
.
user
self
.
assertFalse
(
self
.
request
.
user
.
is_anonymous
())
logout
(
self
.
request
)
self
.
assertTrue
(
self
.
request
.
user
.
is_anonymous
())
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