mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Refs #23919 -- Simplified assertRaisesRegex()'s that accounted for Python 2.
This commit is contained in:
parent
dc8834cad4
commit
109b33f64c
12 changed files with 43 additions and 42 deletions
|
@ -251,7 +251,7 @@ class TestUtilsHashPass(SimpleTestCase):
|
|||
self.assertFalse(check_password('', encoded))
|
||||
self.assertFalse(check_password('lètmein', encoded))
|
||||
self.assertFalse(check_password('lètmeinz', encoded))
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaisesMessage(ValueError, 'Unknown password hashing algorith'):
|
||||
identify_hasher(encoded)
|
||||
# Assert that the unusable passwords actually contain a random part.
|
||||
# This might fail one day due to a hash collision.
|
||||
|
@ -265,9 +265,13 @@ class TestUtilsHashPass(SimpleTestCase):
|
|||
self.assertFalse(check_password(None, make_password('lètmein')))
|
||||
|
||||
def test_bad_algorithm(self):
|
||||
with self.assertRaises(ValueError):
|
||||
msg = (
|
||||
"Unknown password hashing algorithm '%s'. Did you specify it in "
|
||||
"the PASSWORD_HASHERS setting?"
|
||||
)
|
||||
with self.assertRaisesMessage(ValueError, msg % 'lolcat'):
|
||||
make_password('lètmein', hasher='lolcat')
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaisesMessage(ValueError, msg % 'lolcat'):
|
||||
identify_hasher('lolcat$salt$hash')
|
||||
|
||||
def test_bad_encoded(self):
|
||||
|
@ -424,15 +428,15 @@ class TestUtilsHashPass(SimpleTestCase):
|
|||
self.assertEqual(hasher.harden_runtime.call_count, 1)
|
||||
|
||||
def test_load_library_no_algorithm(self):
|
||||
with self.assertRaises(ValueError) as e:
|
||||
msg = "Hasher 'BasePasswordHasher' doesn't specify a library attribute"
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
BasePasswordHasher()._load_library()
|
||||
self.assertEqual("Hasher 'BasePasswordHasher' doesn't specify a library attribute", str(e.exception))
|
||||
|
||||
def test_load_library_importerror(self):
|
||||
PlainHasher = type('PlainHasher', (BasePasswordHasher,), {'algorithm': 'plain', 'library': 'plain'})
|
||||
# Python 3 adds quotes around module name
|
||||
msg = "Couldn't load 'PlainHasher' algorithm library: No module named '?plain'?"
|
||||
with self.assertRaisesRegex(ValueError, msg):
|
||||
msg = "Couldn't load 'PlainHasher' algorithm library: No module named 'plain'"
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
PlainHasher()._load_library()
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue