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
52b12434
Commit
52b12434
authored
Nov 30, 2012
by
Marko Tibold
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #458 from asfaltboy/fix_authtoken_response
Fix authtoken response
parents
8d485da4
1b9d0eef
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
3 deletions
+3
-3
rest_framework/authtoken/views.py
+1
-1
rest_framework/tests/authentication.py
+2
-2
No files found.
rest_framework/authtoken/views.py
View file @
52b12434
...
@@ -18,7 +18,7 @@ class ObtainAuthToken(APIView):
...
@@ -18,7 +18,7 @@ class ObtainAuthToken(APIView):
if
serializer
.
is_valid
():
if
serializer
.
is_valid
():
token
,
created
=
Token
.
objects
.
get_or_create
(
user
=
serializer
.
object
[
'user'
])
token
,
created
=
Token
.
objects
.
get_or_create
(
user
=
serializer
.
object
[
'user'
])
return
Response
({
'token'
:
token
.
key
})
return
Response
({
'token'
:
token
.
key
})
return
Response
(
serializer
.
errors
,
status
=
status
.
HTTP_40
0_BAD_REQUEST
)
return
Response
(
serializer
.
errors
,
status
=
status
.
HTTP_40
1_UNAUTHORIZED
)
obtain_auth_token
=
ObtainAuthToken
.
as_view
()
obtain_auth_token
=
ObtainAuthToken
.
as_view
()
rest_framework/tests/authentication.py
View file @
52b12434
...
@@ -167,14 +167,14 @@ class TokenAuthTests(TestCase):
...
@@ -167,14 +167,14 @@ class TokenAuthTests(TestCase):
client
=
Client
(
enforce_csrf_checks
=
True
)
client
=
Client
(
enforce_csrf_checks
=
True
)
response
=
client
.
post
(
'/auth-token/login/'
,
response
=
client
.
post
(
'/auth-token/login/'
,
json
.
dumps
({
'username'
:
self
.
username
,
'password'
:
"badpass"
}),
'application/json'
)
json
.
dumps
({
'username'
:
self
.
username
,
'password'
:
"badpass"
}),
'application/json'
)
self
.
assertEqual
(
response
.
status_code
,
40
0
)
self
.
assertEqual
(
response
.
status_code
,
40
1
)
def
test_token_login_json_missing_fields
(
self
):
def
test_token_login_json_missing_fields
(
self
):
"""Ensure token login view using JSON POST fails if missing fields."""
"""Ensure token login view using JSON POST fails if missing fields."""
client
=
Client
(
enforce_csrf_checks
=
True
)
client
=
Client
(
enforce_csrf_checks
=
True
)
response
=
client
.
post
(
'/auth-token/login/'
,
response
=
client
.
post
(
'/auth-token/login/'
,
json
.
dumps
({
'username'
:
self
.
username
}),
'application/json'
)
json
.
dumps
({
'username'
:
self
.
username
}),
'application/json'
)
self
.
assertEqual
(
response
.
status_code
,
40
0
)
self
.
assertEqual
(
response
.
status_code
,
40
1
)
def
test_token_login_form
(
self
):
def
test_token_login_form
(
self
):
"""Ensure token login view using form POST works."""
"""Ensure token login view using form POST works."""
...
...
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