summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Schneier <josh.schneier@gmail.com>2018-08-18 15:17:11 -0400
committerTim Graham <timograham@gmail.com>2018-08-18 16:26:13 -0400
commit3daac76cfbb55acb57c9a8bbfa6f12f766eacc3f (patch)
tree5c0a247e0ca9563737f971c04e149b9c35637b27
parent8c70ba92dda3520487e1746a1f917eb1a21948b8 (diff)
Simplified how createsuperuser tests generate passwords.
-rw-r--r--tests/auth_tests/test_management.py36
1 files 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',