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 (
|
15 | 15 | check_password, make_password, is_password_usable, UNUSABLE_PASSWORD) |
16 | 16 | from django.contrib.auth.signals import user_logged_in |
17 | 17 | from django.contrib.contenttypes.models import ContentType |
| 18 | from django.core.exceptions import ValidationError |
18 | 19 | |
19 | 20 | |
20 | 21 | def update_last_login(sender, user, **kwargs): |
… |
… |
class User(models.Model):
|
284 | 285 | def has_usable_password(self): |
285 | 286 | return is_password_usable(self.password) |
286 | 287 | |
| 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 | |
287 | 293 | def get_group_permissions(self, obj=None): |
288 | 294 | """ |
289 | 295 | Returns a list of permission strings that this user has through his/her |
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,
|
10 | 10 | from django.contrib.auth.tests.remote_user import (RemoteUserTest, |
11 | 11 | RemoteUserNoCreateTest, RemoteUserCustomTest) |
12 | 12 | from django.contrib.auth.tests.management import GetDefaultUsernameTestCase |
13 | | from django.contrib.auth.tests.models import ProfileTestCase |
| 13 | from django.contrib.auth.tests.models import (ProfileTestCase, |
| 14 | UserEmptyUsernameCase) |
14 | 15 | from django.contrib.auth.tests.hashers import TestUtilsHashPass |
15 | 16 | from django.contrib.auth.tests.signals import SignalTestCase |
16 | 17 | from django.contrib.auth.tests.tokens import TokenGeneratorTest |
diff --git a/django/contrib/auth/tests/models.py b/django/contrib/auth/tests/models.py
index 754c6db..ac9696c 100644
a
|
b
|
|
1 | 1 | from django.conf import settings |
2 | 2 | from django.test import TestCase |
3 | 3 | from django.contrib.auth.models import User, SiteProfileNotAvailable |
| 4 | from django.core.exceptions import ValidationError |
4 | 5 | |
5 | 6 | class ProfileTestCase(TestCase): |
6 | 7 | fixtures = ['authtestdata.json'] |
… |
… |
class ProfileTestCase(TestCase):
|
33 | 34 | # module that doesn't exist |
34 | 35 | settings.AUTH_PROFILE_MODULE = 'foo.bar' |
35 | 36 | self.assertRaises(SiteProfileNotAvailable, user.get_profile) |
| 37 | |
| 38 | |
| 39 | class 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='') |