test_validators.py 1.2 KB

123456789101112131415161718192021222324252627
  1. #-*- coding: utf-8 -*-
  2. from django.contrib.auth import get_user_model
  3. from django.core.exceptions import ValidationError
  4. from django.test import TransactionTestCase
  5. from misago.conf import settings
  6. from misago.users.validators import (validate_email, validate_email_available,
  7. validate_password,
  8. validate_username,
  9. validate_username_available,
  10. validate_username_content,
  11. validate_username_length)
  12. class ValidateUsernameLengthTests(TransactionTestCase):
  13. serialized_rollback = True
  14. def test_valid_name(self):
  15. """validate_username_length allows valid names"""
  16. validate_username_length('a' * settings.username_length_min)
  17. validate_username_length('a' * settings.username_length_max)
  18. def test_invalid_name(self):
  19. """validate_username_length disallows invalid names"""
  20. with self.assertRaises(ValidationError):
  21. validate_username_length('a' * (settings.username_length_min - 1))
  22. with self.assertRaises(ValidationError):
  23. validate_username_length('a' * (settings.username_length_max + 1))