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
be590d61
Commit
be590d61
authored
May 31, 2017
by
Andrea Grandi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle invalid User situation
parent
d198b1ab
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
1 deletions
+11
-1
rest_framework/authtoken/management/commands/drf_create_token.py
+7
-1
tests/test_authtoken.py
+4
-0
No files found.
rest_framework/authtoken/management/commands/drf_create_token.py
View file @
be590d61
...
...
@@ -16,5 +16,11 @@ class Command(BaseCommand):
def
handle
(
self
,
*
args
,
**
options
):
username
=
options
[
'username'
]
token
=
self
.
create_user_token
(
username
)
try
:
token
=
self
.
create_user_token
(
username
)
except
User
.
DoesNotExist
:
print
(
'Cannot create the Token: user {0} does not exist'
.
format
(
username
))
print
(
'Generated token {0} for user {1}'
.
format
(
token
.
key
,
username
))
tests/test_authtoken.py
View file @
be590d61
...
...
@@ -48,3 +48,7 @@ class AuthTokenCommandTests(TestCase):
assert
token
is
not
None
token_saved
=
Token
.
objects
.
first
()
assert
token
.
key
==
token_saved
.
key
def
test_command_create_user_token_invalid_user
(
self
):
with
pytest
.
raises
(
User
.
DoesNotExist
):
AuthTokenCommand
()
.
create_user_token
(
'not_existing_user'
)
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