diff options
| author | Claude Paroz <claude@2xlibre.net> | 2016-04-22 19:39:13 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2016-05-16 19:37:57 +0200 |
| commit | 526575c64150e10dd8666d1ed3f86eedd00df2ed (patch) | |
| tree | 175e0889a9ef03f53ed9273fb659918eea01fe2d /tests/auth_tests/test_validators.py | |
| parent | 2265ff3710ae244a6f01640972571979543282c6 (diff) | |
Fixed #21379 -- Created auth-specific username validators
Thanks Tim Graham for the review.
Diffstat (limited to 'tests/auth_tests/test_validators.py')
| -rw-r--r-- | tests/auth_tests/test_validators.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auth_tests/test_validators.py b/tests/auth_tests/test_validators.py index 5d758cd342..49a3c5395b 100644 --- a/tests/auth_tests/test_validators.py +++ b/tests/auth_tests/test_validators.py @@ -1,7 +1,9 @@ +# -*- coding: utf-8 -*- from __future__ import unicode_literals import os +from django.contrib.auth import validators from django.contrib.auth.models import User from django.contrib.auth.password_validation import ( CommonPasswordValidator, MinimumLengthValidator, NumericPasswordValidator, @@ -174,3 +176,29 @@ class NumericPasswordValidatorTest(TestCase): NumericPasswordValidator().get_help_text(), "Your password can't be entirely numeric." ) + + +class UsernameValidatorsTests(TestCase): + def test_unicode_validator(self): + valid_usernames = ['joe', 'René', 'ᴮᴵᴳᴮᴵᴿᴰ', 'أحمد'] + invalid_usernames = [ + "o'connell", "عبد ال", + "zerowidth\u200Bspace", "nonbreaking\u00A0space", + "en\u2013dash", + ] + v = validators.UnicodeUsernameValidator() + for valid in valid_usernames: + v(valid) + for invalid in invalid_usernames: + with self.assertRaises(ValidationError): + v(invalid) + + def test_ascii_validator(self): + valid_usernames = ['glenn', 'GLEnN', 'jean-marc'] + invalid_usernames = ["o'connell", 'Éric', 'jean marc', "أحمد"] + v = validators.ASCIIUsernameValidator() + for valid in valid_usernames: + v(valid) + for invalid in invalid_usernames: + with self.assertRaises(ValidationError): + v(invalid) |
