diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index 8064a4e..12debbe 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 | # The save method is overriden to raise an error when the username is blank. |
| 289 | # See ticket #17046 |
| 290 | def save(self, *args, **kwargs): |
| 291 | if self.username == '': |
| 292 | raise ValidationError(_('username cannot be an empty string.')) |
| 293 | super(User, self).save(*args, **kwargs) |
| 294 | |
287 | 295 | def get_group_permissions(self, obj=None): |
288 | 296 | """ |
289 | 297 | 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..0eacfe8 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, UserEmptyUsernameCase |
14 | 14 | from django.contrib.auth.tests.hashers import TestUtilsHashPass |
15 | 15 | from django.contrib.auth.tests.signals import SignalTestCase |
16 | 16 | 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..2fec66e 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 | |
| 41 | def test_empty_username(self): |
| 42 | with self.assertRaises(ValidationError): |
| 43 | User.objects.create_user(username='', password='password', email='e@e.com') |