From 4591cf3fd88fb13325ffce91279eae38e38c61cb Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Fri, 22 Jul 2016 11:51:38 +0300 Subject: Fixed #26909 -- Allowed UserAttributeSimilarityValidator to validate against model properties. --- tests/auth_tests/test_validators.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/auth_tests/test_validators.py') 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(), -- cgit v1.3