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
19a774f9
Commit
19a774f9
authored
Aug 23, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
force_authenticate(None) also clears session info.
Closes #1055.
parent
b8561f41
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
0 deletions
+33
-0
docs/topics/release-notes.md
+1
-0
rest_framework/test.py
+2
-0
rest_framework/tests/test_testing.py
+30
-0
No files found.
docs/topics/release-notes.md
View file @
19a774f9
...
...
@@ -44,6 +44,7 @@ You can determine your currently installed version using `pip freeze`:
*
Support customizable view name and description functions, using the `VIEW_NAME_FUNCTION` and `VIEW_DESCRIPTION_FUNCTION` settings.
*
Bugfix
:
`
required=True` argument fixed for boolean serializer fields.
*
Bugfix
:
`
client.force_authenticate(None)` should also clear session info if it exists.
### 2.3.7
...
...
rest_framework/test.py
View file @
19a774f9
...
...
@@ -134,6 +134,8 @@ class APIClient(APIRequestFactory, DjangoClient):
"""
self
.
handler
.
_force_user
=
user
self
.
handler
.
_force_token
=
token
if
user
is
None
:
self
.
logout
()
# Also clear any possible session info if required
def
request
(
self
,
**
kwargs
):
# Ensure that any credentials set get added to every request.
...
...
rest_framework/tests/test_testing.py
View file @
19a774f9
...
...
@@ -17,8 +17,18 @@ def view(request):
})
@api_view
([
'GET'
,
'POST'
])
def
session_view
(
request
):
active_session
=
request
.
session
.
get
(
'active_session'
,
False
)
request
.
session
[
'active_session'
]
=
True
return
Response
({
'active_session'
:
active_session
})
urlpatterns
=
patterns
(
''
,
url
(
r'^view/$'
,
view
),
url
(
r'^session-view/$'
,
session_view
),
)
...
...
@@ -46,6 +56,26 @@ class TestAPITestClient(TestCase):
response
=
self
.
client
.
get
(
'/view/'
)
self
.
assertEqual
(
response
.
data
[
'user'
],
'example'
)
def
test_force_authenticate_with_sessions
(
self
):
"""
Setting `.force_authenticate()` forcibly authenticates each request.
"""
user
=
User
.
objects
.
create_user
(
'example'
,
'example@example.com'
)
self
.
client
.
force_authenticate
(
user
)
# First request does not yet have an active session
response
=
self
.
client
.
get
(
'/session-view/'
)
self
.
assertEqual
(
response
.
data
[
'active_session'
],
False
)
# Subsequant requests have an active session
response
=
self
.
client
.
get
(
'/session-view/'
)
self
.
assertEqual
(
response
.
data
[
'active_session'
],
True
)
# Force authenticating as `None` should also logout the user session.
self
.
client
.
force_authenticate
(
None
)
response
=
self
.
client
.
get
(
'/session-view/'
)
self
.
assertEqual
(
response
.
data
[
'active_session'
],
False
)
def
test_csrf_exempt_by_default
(
self
):
"""
By default, the test client is CSRF exempt.
...
...
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