summaryrefslogtreecommitdiff
path: root/tests/auth_tests/test_validators.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auth_tests/test_validators.py')
-rw-r--r--tests/auth_tests/test_validators.py28
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)