summaryrefslogtreecommitdiff
path: root/tests/auth_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auth_tests')
-rw-r--r--tests/auth_tests/test_hashers.py43
1 files changed, 22 insertions, 21 deletions
diff --git a/tests/auth_tests/test_hashers.py b/tests/auth_tests/test_hashers.py
index 3da495f2be..33bca3fbc1 100644
--- a/tests/auth_tests/test_hashers.py
+++ b/tests/auth_tests/test_hashers.py
@@ -621,29 +621,30 @@ class TestUtilsHashPass(SimpleTestCase):
("letmein", make_password(password="letmein"), ValueError), # valid encoded
]
for password, encoded, hasher_side_effect in cases:
- with (
- self.subTest(encoded=encoded),
- mock.patch(
+ with self.subTest(encoded=encoded):
+ with mock.patch(
"django.contrib.auth.hashers.identify_hasher",
side_effect=hasher_side_effect,
- ) as mock_identify_hasher,
- mock.patch(
- "django.contrib.auth.hashers.make_password"
- ) as mock_make_password,
- mock.patch(
- "django.contrib.auth.hashers.get_random_string",
- side_effect=lambda size: "x" * size,
- ),
- mock.patch.object(hasher, "verify"),
- ):
- # Ensure make_password is called to standardize timing.
- check_password(password, encoded)
- self.assertEqual(hasher.verify.call_count, 0)
- self.assertEqual(mock_identify_hasher.mock_calls, [mock.call(encoded)])
- self.assertEqual(
- mock_make_password.mock_calls,
- [mock.call("x" * UNUSABLE_PASSWORD_SUFFIX_LENGTH)],
- )
+ ) as mock_identify_hasher:
+ with mock.patch(
+ "django.contrib.auth.hashers.make_password"
+ ) as mock_make_password:
+ with mock.patch(
+ "django.contrib.auth.hashers.get_random_string",
+ side_effect=lambda size: "x" * size,
+ ):
+ with mock.patch.object(hasher, "verify"):
+ # make_password() is called to standardize timing.
+ check_password(password, encoded)
+ self.assertEqual(hasher.verify.call_count, 0)
+ self.assertEqual(
+ mock_identify_hasher.mock_calls,
+ [mock.call(encoded)],
+ )
+ self.assertEqual(
+ mock_make_password.mock_calls,
+ [mock.call("x" * UNUSABLE_PASSWORD_SUFFIX_LENGTH)],
+ )
def test_encode_invalid_salt(self):
hasher_classes = [