mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 11:04:02 +03:00
Fix authtoken managment command (#5415)
* Fix authtoken managment command username param
This commit is contained in:
parent
7037ce88e9
commit
9aaea2586b
|
@ -19,7 +19,7 @@ class Command(BaseCommand):
|
|||
return token[0]
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('username', type=str, nargs='+')
|
||||
parser.add_argument('username', type=str)
|
||||
|
||||
parser.add_argument(
|
||||
'-r',
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import pytest
|
||||
from django.contrib.admin import site
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management import call_command
|
||||
from django.test import TestCase
|
||||
from django.utils.six import StringIO
|
||||
|
||||
from rest_framework.authtoken.admin import TokenAdmin
|
||||
from rest_framework.authtoken.management.commands.drf_create_token import \
|
||||
|
@ -68,3 +70,11 @@ class AuthTokenCommandTests(TestCase):
|
|||
second_token_key = Token.objects.first().key
|
||||
|
||||
assert first_token_key == second_token_key
|
||||
|
||||
def test_command_output(self):
|
||||
out = StringIO()
|
||||
call_command('drf_create_token', self.user.username, stdout=out)
|
||||
token_saved = Token.objects.first()
|
||||
self.assertIn('Generated token', out.getvalue())
|
||||
self.assertIn(self.user.username, out.getvalue())
|
||||
self.assertIn(token_saved.key, out.getvalue())
|
||||
|
|
Loading…
Reference in New Issue
Block a user