Fix authtoken managment command (#5415)

* Fix authtoken managment command username param
This commit is contained in:
Sergei Azarkin 2017-09-12 16:03:29 +03:00 committed by Tom Christie
parent 7037ce88e9
commit 9aaea2586b
2 changed files with 11 additions and 1 deletions

View File

@ -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',

View File

@ -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())