Added a missing test for createsuperuser management command.

This commit is contained in:
Hasan Ramezani 2018-06-07 12:59:49 +04:30 committed by Tim Graham
parent 98e8c0293b
commit 6df3d36801
1 changed files with 28 additions and 0 deletions

View File

@ -701,6 +701,34 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
stdout=new_io,
)
def test_existing_username_provided_via_option_and_interactive(self):
"""call_command() gets username='janet' and interactive=True."""
new_io = StringIO()
entered_passwords = ['password', 'password']
User.objects.create(username='janet')
def return_passwords():
return entered_passwords.pop(0)
@mock_inputs({
'password': return_passwords,
'username': 'janet1',
'email': 'test@test.com'
})
def test(self):
call_command(
'createsuperuser',
username='janet',
interactive=True,
stdin=MockTTY(),
stdout=new_io,
stderr=new_io,
)
msg = 'Error: That username is already taken.\nSuperuser created successfully.'
self.assertEqual(new_io.getvalue().strip(), msg)
test(self)
def test_validation_mismatched_passwords(self):
"""
Creation should fail if the user enters mismatched passwords.