Fixed #28044 -- Unified the logic for createsuperuser's interactive and --noinput modes.

This commit is contained in:
Dohyeon Kim 2018-05-29 21:41:32 +09:00 committed by Tim Graham
parent 0914a2003b
commit f1f4aeb22e
2 changed files with 109 additions and 73 deletions

View file

@ -568,6 +568,22 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
test(self)
def test_blank_username_non_interactive(self):
new_io = StringIO()
def test(self):
with self.assertRaisesMessage(CommandError, 'Username cannot be blank.'):
call_command(
'createsuperuser',
username='',
interactive=False,
stdin=MockTTY(),
stdout=new_io,
stderr=new_io,
)
test(self)
def test_password_validation_bypass(self):
"""
Password validation can be bypassed by entering 'y' at the prompt.
@ -672,6 +688,19 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
test(self)
def test_existing_username_non_interactive(self):
"""Creation fails if the username already exists."""
User.objects.create(username='janet')
new_io = StringIO()
with self.assertRaisesMessage(CommandError, "Error: That username is already taken."):
call_command(
'createsuperuser',
username='janet',
email='',
interactive=False,
stdout=new_io,
)
def test_validation_mismatched_passwords(self):
"""
Creation should fail if the user enters mismatched passwords.