diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py index 73cf66699b..da0ec73626 100644 --- a/tests/auth_tests/test_management.py +++ b/tests/auth_tests/test_management.py @@ -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.