mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #26909 -- Allowed UserAttributeSimilarityValidator to validate against model properties.
This commit is contained in:
parent
f5c6295797
commit
4591cf3fd8
2 changed files with 22 additions and 2 deletions
|
@ -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(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue