Ticket #17046: prevent_empty_username.diff

File prevent_empty_username.diff, 2.6 KB (added by honza, 13 years ago)
  • django/contrib/auth/models.py

    diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
    index 04e68aa..4f25c42 100644
    a b import urllib  
    33
    44from django.core.exceptions import ImproperlyConfigured
    55from django.core.mail import send_mail
    6 from django.db import models
     6from django.db import models, IntegrityError
    77from django.db.models.manager import EmptyManager
    88from django.utils.encoding import smart_str
    99from django.utils.translation import ugettext_lazy as _
    class UserManager(models.Manager):  
    9393        """
    9494        now = datetime.datetime.now()
    9595
     96        if username == '':
     97            raise IntegrityError("Username can't be blank")
     98
    9699        # Normalize the address by lowercasing the domain part of the email
    97100        # address.
    98101        email = email or ''
  • django/contrib/auth/tests/__init__.py

    diff --git a/django/contrib/auth/tests/__init__.py b/django/contrib/auth/tests/__init__.py
    index 7cb0dcb..71d2bd4 100644
    a b from django.contrib.auth.tests.forms import (UserCreationFormTest,  
    1010from django.contrib.auth.tests.remote_user import (RemoteUserTest,
    1111    RemoteUserNoCreateTest, RemoteUserCustomTest)
    1212from django.contrib.auth.tests.management import GetDefaultUsernameTestCase
    13 from django.contrib.auth.tests.models import ProfileTestCase
     13from django.contrib.auth.tests.models import ProfileTestCase, UserEmptyUsernameCase
    1414from django.contrib.auth.tests.signals import SignalTestCase
    1515from django.contrib.auth.tests.tokens import TokenGeneratorTest
    1616from django.contrib.auth.tests.views import (AuthViewNamedURLTests, PasswordResetTest,
  • django/contrib/auth/tests/models.py

    diff --git a/django/contrib/auth/tests/models.py b/django/contrib/auth/tests/models.py
    index 754c6db..7ab947d 100644
    a b  
    11from django.conf import settings
    22from django.test import TestCase
    33from django.contrib.auth.models import User, SiteProfileNotAvailable
     4from django.db import IntegrityError
    45
    56class ProfileTestCase(TestCase):
    67    fixtures = ['authtestdata.json']
    class ProfileTestCase(TestCase):  
    3334        # module that doesn't exist
    3435        settings.AUTH_PROFILE_MODULE = 'foo.bar'
    3536        self.assertRaises(SiteProfileNotAvailable, user.get_profile)
     37
     38
     39class UserEmptyUsernameCase(TestCase):
     40
     41    def test_empty_username(self):
     42        with self.assertRaises(IntegrityError):
     43            User.objects.create_user(username='', password='passsword',
     44                    email='email@email.com')
Back to Top