mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #28044 -- Unified the logic for createsuperuser's interactive and --noinput modes.
This commit is contained in:
parent
0914a2003b
commit
f1f4aeb22e
2 changed files with 109 additions and 73 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue