From 3daac76cfbb55acb57c9a8bbfa6f12f766eacc3f Mon Sep 17 00:00:00 2001 From: Josh Schneier Date: Sat, 18 Aug 2018 15:17:11 -0400 Subject: [PATCH] Simplified how createsuperuser tests generate passwords. --- tests/auth_tests/test_management.py | 36 ++++++++++------------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py index 1d340c56f0..07b913b8d2 100644 --- a/tests/auth_tests/test_management.py +++ b/tests/auth_tests/test_management.py @@ -524,14 +524,10 @@ class CreatesuperuserManagementCommandTestCase(TestCase): Creation should fail if the password fails validation. """ new_io = StringIO() + entered_passwords = ['1234567890', '1234567890', 'password', 'password'] - # Returns '1234567890' the first two times it is called, then - # 'password' subsequently. - def bad_then_good_password(index=[0]): - index[0] += 1 - if index[0] <= 2: - return '1234567890' - return 'password' + def bad_then_good_password(): + return entered_passwords.pop(0) @mock_inputs({ 'password': bad_then_good_password, @@ -561,13 +557,10 @@ class CreatesuperuserManagementCommandTestCase(TestCase): def test_validate_password_against_username(self): new_io = StringIO() username = 'supremelycomplex' + entered_passwords = [username, username, 'superduperunguessablepassword', 'superduperunguessablepassword'] - def bad_then_good_password(index=[0]): - """Return username the first two times, then a valid password.""" - index[0] += 1 - if index[0] <= 2: - return username - return 'superduperunguessablepassword' + def bad_then_good_password(): + return entered_passwords.pop(0) @mock_inputs({ 'password': bad_then_good_password, @@ -599,21 +592,16 @@ class CreatesuperuserManagementCommandTestCase(TestCase): ) def test_validate_password_against_required_fields(self): new_io = StringIO() - username = 'josephine' + first_name = 'josephine' + entered_passwords = [first_name, first_name, 'superduperunguessablepassword', 'superduperunguessablepassword'] - # Returns the username the first two times it's called, then a valid - # password. - def bad_then_good_password(index=[0]): - """Return username the first two times, then a valid password.""" - index[0] += 1 - if index[0] <= 2: - return username - return 'superduperunguessablepassword' + def bad_then_good_password(): + return entered_passwords.pop(0) @mock_inputs({ 'password': bad_then_good_password, - 'username': username, - 'first_name': 'josephine', + 'username': 'whatever', + 'first_name': first_name, 'date_of_birth': '1970-01-01', 'email': 'joey@example.com', 'bypass': 'n',