diff options
| author | David Gibbons <dgibbons@eircom.net> | 2015-08-18 02:28:22 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-08-18 16:22:14 -0400 |
| commit | 39b55537ec2ff0f968ffb778d9e0a076db8f7a0e (patch) | |
| tree | 3ce40e57398e8b04ce27f32a32794611791e4458 /tests/auth_tests | |
| parent | b04544e21d525ca84c30f92c34740dfcb20d928b (diff) | |
Added two more tests for user-entered passwords when creating a superuser.
Diffstat (limited to 'tests/auth_tests')
| -rw-r--r-- | tests/auth_tests/test_management.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py index a63dfbc6fd..70d5ceac5b 100644 --- a/tests/auth_tests/test_management.py +++ b/tests/auth_tests/test_management.py @@ -498,6 +498,72 @@ class CreatesuperuserManagementCommandTestCase(TestCase): test(self) + def test_validation_mismatched_passwords(self): + """ + Creation should fail if the user enters mismatched passwords. + """ + new_io = six.StringIO() + + # The first two passwords do not match, but the second two do match and + # are valid. + entered_passwords = ["password", "not password", "password2", "password2"] + + def mismatched_passwords_then_matched(): + return entered_passwords.pop(0) + + @mock_inputs({ + 'password': mismatched_passwords_then_matched, + 'username': 'joe1234567890', + }) + def test(self): + call_command( + "createsuperuser", + interactive=True, + stdin=MockTTY(), + stdout=new_io, + stderr=new_io, + ) + self.assertEqual( + new_io.getvalue().strip(), + "Error: Your passwords didn't match.\n" + "Superuser created successfully." + ) + + test(self) + + def test_validation_blank_password_entered(self): + """ + Creation should fail if the user enters blank passwords. + """ + new_io = six.StringIO() + + # The first two passwords are empty strings, but the second two are + # valid. + entered_passwords = ["", "", "password2", "password2"] + + def blank_passwords_then_valid(): + return entered_passwords.pop(0) + + @mock_inputs({ + 'password': blank_passwords_then_valid, + 'username': 'joe1234567890', + }) + def test(self): + call_command( + "createsuperuser", + interactive=True, + stdin=MockTTY(), + stdout=new_io, + stderr=new_io, + ) + self.assertEqual( + new_io.getvalue().strip(), + "Error: Blank passwords aren't allowed.\n" + "Superuser created successfully." + ) + + test(self) + class CustomUserModelValidationTestCase(SimpleTestCase): @override_settings(AUTH_USER_MODEL='auth.CustomUserNonListRequiredFields') |
