summaryrefslogtreecommitdiff
path: root/tests/auth_tests
diff options
context:
space:
mode:
authorSkyiesac <jainsachi1202@gmail.com>2025-11-17 00:46:37 +0530
committerJacob Walls <jacobtylerwalls@gmail.com>2025-12-03 09:18:10 -0500
commitd338c2243fa0786225e056c5d7003f7ad67d44de (patch)
tree9e1af2794830ffc04f8936027fb7e1ce747dd9c0 /tests/auth_tests
parentdba622ebc1f6a6700b75303a65f8a334bd46bd8e (diff)
Fixed #36280 -- Replaced exception checks with assertRaisesMessage().
Diffstat (limited to 'tests/auth_tests')
-rw-r--r--tests/auth_tests/test_validators.py24
1 files changed, 10 insertions, 14 deletions
diff --git a/tests/auth_tests/test_validators.py b/tests/auth_tests/test_validators.py
index 2a3a93efe8..3ce2611633 100644
--- a/tests/auth_tests/test_validators.py
+++ b/tests/auth_tests/test_validators.py
@@ -202,24 +202,24 @@ class UserAttributeSimilarityValidatorTest(TestCase):
self.assertEqual(cm.exception.messages, [expected_error % "username"])
self.assertEqual(cm.exception.error_list[0].code, "password_too_similar")
- with self.assertRaises(ValidationError) as cm:
+ msg = expected_error % "email address"
+ with self.assertRaisesMessage(ValidationError, msg):
UserAttributeSimilarityValidator().validate("example.com", user=user)
- self.assertEqual(cm.exception.messages, [expected_error % "email address"])
- with self.assertRaises(ValidationError) as cm:
+ msg = expected_error % "first name"
+ with self.assertRaisesMessage(ValidationError, msg):
UserAttributeSimilarityValidator(
user_attributes=["first_name"],
max_similarity=0.3,
).validate("testclient", user=user)
- self.assertEqual(cm.exception.messages, [expected_error % "first name"])
# max_similarity=1 doesn't allow passwords that are identical to the
# attribute's value.
- with self.assertRaises(ValidationError) as cm:
+ msg = expected_error % "first name"
+ with self.assertRaisesMessage(ValidationError, msg):
UserAttributeSimilarityValidator(
user_attributes=["first_name"],
max_similarity=1,
).validate(user.first_name, user=user)
- self.assertEqual(cm.exception.messages, [expected_error % "first name"])
# Very low max_similarity is rejected.
msg = "max_similarity must be at least 0.1"
with self.assertRaisesMessage(ValueError, msg):
@@ -240,11 +240,9 @@ class UserAttributeSimilarityValidatorTest(TestCase):
def username(self):
return "foobar"
- with self.assertRaises(ValidationError) as cm:
+ msg = "The password is too similar to the username."
+ with self.assertRaisesMessage(ValidationError, msg):
UserAttributeSimilarityValidator().validate("foobar", user=TestUser())
- self.assertEqual(
- cm.exception.messages, ["The password is too similar to the username."]
- )
def test_help_text(self):
self.assertEqual(
@@ -294,18 +292,16 @@ class CommonPasswordValidatorTest(SimpleTestCase):
expected_error = "This password is too common."
self.assertIsNone(CommonPasswordValidator().validate("a-safe-password"))
- with self.assertRaises(ValidationError) as cm:
+ with self.assertRaisesMessage(ValidationError, expected_error):
CommonPasswordValidator().validate("godzilla")
- self.assertEqual(cm.exception.messages, [expected_error])
def test_common_hexed_codes(self):
expected_error = "This password is too common."
common_hexed_passwords = ["asdfjkl:", "&#2336:"]
for password in common_hexed_passwords:
with self.subTest(password=password):
- with self.assertRaises(ValidationError) as cm:
+ with self.assertRaisesMessage(ValidationError, expected_error):
CommonPasswordValidator().validate(password)
- self.assertEqual(cm.exception.messages, [expected_error])
def test_validate_custom_list(self):
path = os.path.join(