This commit is contained in:
@@ -26,12 +26,9 @@ class PasswordScoreValidatorTestCase(SimpleTestCase):
|
||||
validator = PasswordScoreValidator(min_classes=0)
|
||||
|
||||
for password in passwords:
|
||||
try:
|
||||
with self.assertRaises(ValidationError, msg=password) as cm:
|
||||
validator.validate(password)
|
||||
except ValidationError as e:
|
||||
self.assertEqual('too_little_score', e.code)
|
||||
else:
|
||||
self.fail('%s: no validation error was raised' % password)
|
||||
self.assertEqual('too_little_score', cm.exception.code)
|
||||
|
||||
def test_too_few_classes(self):
|
||||
passwords = [
|
||||
@@ -49,12 +46,9 @@ class PasswordScoreValidatorTestCase(SimpleTestCase):
|
||||
validator = PasswordScoreValidator(min_score=0, min_classes=4)
|
||||
|
||||
for password in passwords:
|
||||
try:
|
||||
with self.assertRaises(ValidationError, msg=password) as cm:
|
||||
validator.validate(password)
|
||||
except ValidationError as e:
|
||||
self.assertEqual('too_few_classes', e.code)
|
||||
else:
|
||||
self.fail('%s: no validation error was raised' % password)
|
||||
self.assertEqual('too_few_classes', cm.exception.code)
|
||||
|
||||
def test_valid(self):
|
||||
passwords = [
|
||||
@@ -75,8 +69,15 @@ class PasswordScoreValidatorTestCase(SimpleTestCase):
|
||||
for password in passwords:
|
||||
try:
|
||||
validator.validate(password)
|
||||
except ValidationError as e:
|
||||
self.fail(e)
|
||||
except ValidationError as e: # pragma: no cover
|
||||
self.fail('%s: %s' % (password, e))
|
||||
|
||||
def test_help_text(self):
|
||||
validator = PasswordScoreValidator()
|
||||
help_text = validator.get_help_text()
|
||||
self.assertIn('The password must get a minimum score of 18 points.', help_text)
|
||||
self.assertIn('Also the password must contain characters from 2 different character classes'
|
||||
' (i.e. lower, upper, digits, others).', help_text)
|
||||
|
||||
|
||||
class CustomWordlistPasswordValidatorTestCase(SimpleTestCase):
|
||||
@@ -114,7 +115,7 @@ class CustomWordlistPasswordValidatorTestCase(SimpleTestCase):
|
||||
for error in errors:
|
||||
self.assertIn(error, expected_errors)
|
||||
else:
|
||||
self.fail('%s: no validation error was raised' % password)
|
||||
self.fail('%s: no validation error was raised' % password) # pragma: no cover
|
||||
|
||||
def test_valid(self):
|
||||
passwords = [
|
||||
@@ -128,9 +129,15 @@ class CustomWordlistPasswordValidatorTestCase(SimpleTestCase):
|
||||
for password in passwords:
|
||||
try:
|
||||
validator.validate(password)
|
||||
except ValidationError as e:
|
||||
except ValidationError as e: # pragma: no cover
|
||||
self.fail(e)
|
||||
|
||||
def test_help_text(self):
|
||||
validator = CustomWordlistPasswordValidator()
|
||||
help_text = validator.get_help_text()
|
||||
self.assertIn('The password must not contain some specific words,', help_text)
|
||||
self.assertIn('All words are matched case insensitive.', help_text)
|
||||
|
||||
|
||||
class CharacterClassPasswordValidatorTestCase(SimpleTestCase):
|
||||
def setUp(self):
|
||||
@@ -215,7 +222,7 @@ class CharacterClassPasswordValidatorTestCase(SimpleTestCase):
|
||||
for error in errors:
|
||||
self.assertIn(error, expected_errors)
|
||||
else:
|
||||
self.fail('%s: no validation error was raised' % password)
|
||||
self.fail('%s: no validation error was raised' % password) # pragma: no cover
|
||||
|
||||
def test_valid(self):
|
||||
valid_passwords = ['abCD12+-']
|
||||
@@ -223,5 +230,14 @@ class CharacterClassPasswordValidatorTestCase(SimpleTestCase):
|
||||
for password in valid_passwords:
|
||||
try:
|
||||
validator.validate(password)
|
||||
except ValidationError as e:
|
||||
except ValidationError as e: # pragma: no cover
|
||||
self.fail(e)
|
||||
|
||||
def test_help_text(self):
|
||||
validator = self.validator
|
||||
help_text = validator.get_help_text()
|
||||
self.assertIn('The password must contain at least 2 characters from a-z.', help_text)
|
||||
self.assertIn('The password must contain at least 2 characters from A-Z.', help_text)
|
||||
self.assertIn('The password must contain at least 2 digits from 0-9.', help_text)
|
||||
self.assertIn('The password must contain at least 2 non alpha numeric characters.', help_text)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user