diff options
| author | Ahmed Nassar <a.moh.nassar00@gmail.com> | 2025-04-16 17:02:56 +0200 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-04-17 12:32:24 +0200 |
| commit | adf2991d32c24f8b2e549a25a7eda52f317a91a6 (patch) | |
| tree | 770bab92deb1ae71ea6fa6ceaa41f1b2a46b1a3e /tests | |
| parent | cbdb1bed041a88a5e29cab5e60da928b2d9e6db5 (diff) | |
[5.2.x] Fixed #36314 -- Fixed MinimumLengthValidator error message translation.
Regression in ec7d69035a408b357f1803ca05a7c991cc358cfa.
Thank you Gabriel Trouvé for the report and Claude Paroz for the review.
Backport of d469db978ea6a705549b9519313d9adc198e4232 from main.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/auth_tests/test_validators.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/auth_tests/test_validators.py b/tests/auth_tests/test_validators.py index ea75c4a080..fdbf495ff5 100644 --- a/tests/auth_tests/test_validators.py +++ b/tests/auth_tests/test_validators.py @@ -1,4 +1,5 @@ import os +from unittest import mock from django.contrib.auth import validators from django.contrib.auth.models import User @@ -132,11 +133,16 @@ class MinimumLengthValidatorTest(SimpleTestCase): with self.assertRaises(ValidationError) as cm: MinimumLengthValidator().validate("1234567") self.assertEqual(cm.exception.messages, [expected_error % 8]) - self.assertEqual(cm.exception.error_list[0].code, "password_too_short") + error = cm.exception.error_list[0] + self.assertEqual(error.code, "password_too_short") + self.assertEqual(error.params, {"min_length": 8}) with self.assertRaises(ValidationError) as cm: MinimumLengthValidator(min_length=3).validate("12") self.assertEqual(cm.exception.messages, [expected_error % 3]) + error = cm.exception.error_list[0] + self.assertEqual(error.code, "password_too_short") + self.assertEqual(error.params, {"min_length": 3}) def test_help_text(self): self.assertEqual( @@ -144,6 +150,24 @@ class MinimumLengthValidatorTest(SimpleTestCase): "Your password must contain at least 8 characters.", ) + @mock.patch("django.contrib.auth.password_validation.ngettext") + def test_l10n(self, mock_ngettext): + with self.subTest("get_error_message"): + MinimumLengthValidator().get_error_message() + mock_ngettext.assert_called_with( + "This password is too short. It must contain at least %d character.", + "This password is too short. It must contain at least %d characters.", + 8, + ) + mock_ngettext.reset() + with self.subTest("get_help_text"): + MinimumLengthValidator().get_help_text() + mock_ngettext.assert_called_with( + "Your password must contain at least %(min_length)d " "character.", + "Your password must contain at least %(min_length)d " "characters.", + 8, + ) + def test_custom_error(self): class CustomMinimumLengthValidator(MinimumLengthValidator): def get_error_message(self): |
