mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 08:14:16 +03:00
Handle invalid User situation
This commit is contained in:
parent
d198b1abe6
commit
be590d61c0
|
@ -16,5 +16,11 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
username = options['username']
|
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))
|
print('Generated token {0} for user {1}'.format(token.key, username))
|
||||||
|
|
|
@ -48,3 +48,7 @@ class AuthTokenCommandTests(TestCase):
|
||||||
assert token is not None
|
assert token is not None
|
||||||
token_saved = Token.objects.first()
|
token_saved = Token.objects.first()
|
||||||
assert token.key == token_saved.key
|
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')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user