diff options
| author | Andrew Nester <andrew.nester.dev@gmail.com> | 2016-07-22 11:51:38 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-08-10 15:08:06 -0400 |
| commit | 4591cf3fd88fb13325ffce91279eae38e38c61cb (patch) | |
| tree | a9e77bc9ed71afac84b0237a4689e908aef96322 /tests/auth_tests/test_validators.py | |
| parent | f5c6295797b8332134fd89e0209a18a1d1d45e0c (diff) | |
Fixed #26909 -- Allowed UserAttributeSimilarityValidator to validate against model properties.
Diffstat (limited to 'tests/auth_tests/test_validators.py')
| -rw-r--r-- | tests/auth_tests/test_validators.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auth_tests/test_validators.py b/tests/auth_tests/test_validators.py index 49a3c5395b..97cf396b1a 100644 --- a/tests/auth_tests/test_validators.py +++ b/tests/auth_tests/test_validators.py @@ -13,7 +13,9 @@ from django.contrib.auth.password_validation import ( validate_password, ) from django.core.exceptions import ValidationError +from django.db import models from django.test import TestCase, override_settings +from django.test.utils import isolate_apps from django.utils._os import upath @@ -127,6 +129,19 @@ class UserAttributeSimilarityValidatorTest(TestCase): UserAttributeSimilarityValidator(user_attributes=['first_name']).validate('testclient', user=user) ) + @isolate_apps('auth_tests') + def test_validate_property(self): + class TestUser(models.Model): + pass + + @property + def username(self): + return 'foobar' + + with self.assertRaises(ValidationError) as cm: + 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( UserAttributeSimilarityValidator().get_help_text(), |
