From 6df3d3680167ec84e32fe5994c0cffc1460e4c37 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Thu, 7 Jun 2018 12:59:49 +0430 Subject: [PATCH] Added a missing test for createsuperuser management command. --- tests/auth_tests/test_management.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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.