Ticket #17046: patch_for_17046.diff

File patch_for_17046.diff, 2.8 KB (added by kwadrat, 12 years ago)
  • django/contrib/auth/models.py

    diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
    index 8064a4e..2a48894 100644
    a b from django.contrib.auth.hashers import (  
    1515    check_password, make_password, is_password_usable, UNUSABLE_PASSWORD)
    1616from django.contrib.auth.signals import user_logged_in
    1717from django.contrib.contenttypes.models import ContentType
     18from django.core.exceptions import ValidationError
    1819
    1920
    2021def update_last_login(sender, user, **kwargs):
    class User(models.Model):  
    284285    def has_usable_password(self):
    285286        return is_password_usable(self.password)
    286287
     288    def save(self, *args, **kwargs):
     289        if self.username == '':
     290            raise ValidationError(_('Username cannot be an empty string.'))
     291        super(User, self).save(*args, **kwargs)
     292
    287293    def get_group_permissions(self, obj=None):
    288294        """
    289295        Returns a list of permission strings that this user has through his/her
  • django/contrib/auth/tests/__init__.py

    diff --git a/django/contrib/auth/tests/__init__.py b/django/contrib/auth/tests/__init__.py
    index 883e4c9..719d3e5 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,
     14    UserEmptyUsernameCase)
    1415from django.contrib.auth.tests.hashers import TestUtilsHashPass
    1516from django.contrib.auth.tests.signals import SignalTestCase
    1617from django.contrib.auth.tests.tokens import TokenGeneratorTest
  • django/contrib/auth/tests/models.py

    diff --git a/django/contrib/auth/tests/models.py b/django/contrib/auth/tests/models.py
    index 754c6db..ac9696c 100644
    a b  
    11from django.conf import settings
    22from django.test import TestCase
    33from django.contrib.auth.models import User, SiteProfileNotAvailable
     4from django.core.exceptions import ValidationError
    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    def test_empty_username(self):
     41        self.assertRaisesMessage(ValidationError,
     42                                 "[u'Username cannot be an empty string.']",
     43                                 User.objects.create_user, username='')
Back to Top