diff options
| author | Olexander Yermakov <mannavard1611@gmail.com> | 2016-07-26 16:50:29 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-08-10 09:44:48 -0400 |
| commit | 975a76a96428bcc9da43d87e3f8433f498da2d68 (patch) | |
| tree | b403cc05d9117903bf46ef9c5b5ab91fd270f975 /tests/auth_tests/test_forms.py | |
| parent | 74bb013cc1edb0f2fcf24c750d4d942cae507765 (diff) | |
Fixed #26951 -- Allowed AuthenticationForm to work with a username of 0.
Diffstat (limited to 'tests/auth_tests/test_forms.py')
| -rw-r--r-- | tests/auth_tests/test_forms.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index fe22d1e20b..707d5b87ad 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -15,7 +15,7 @@ from django.contrib.auth.models import User from django.contrib.sites.models import Site from django.core import mail from django.core.mail import EmailMultiAlternatives -from django.forms.fields import CharField, Field +from django.forms.fields import CharField, Field, IntegerField from django.test import SimpleTestCase, TestCase, mock, override_settings from django.utils import six, translation from django.utils.encoding import force_text @@ -23,6 +23,7 @@ from django.utils.text import capfirst from django.utils.translation import ugettext as _ from .models.custom_user import CustomUser, ExtensionUser +from .models.with_integer_username import IntegerUsernameUser from .settings import AUTH_TEMPLATES @@ -351,6 +352,23 @@ class AuthenticationFormTest(TestDataMixin, TestCase): form.is_valid() # Not necessary to have valid credentails for the test. self.assertEqual(form.cleaned_data['password'], data['password']) + @override_settings(AUTH_USER_MODEL='auth_tests.IntegerUsernameUser') + def test_integer_username(self): + class CustomAuthenticationForm(AuthenticationForm): + username = IntegerField() + + user = IntegerUsernameUser.objects.create_user(username=0, password='pwd') + data = { + 'username': 0, + 'password': 'pwd', + } + form = CustomAuthenticationForm(None, data) + self.assertTrue(form.is_valid()) + self.assertEqual(form.cleaned_data['username'], data['username']) + self.assertEqual(form.cleaned_data['password'], data['password']) + self.assertEqual(form.errors, {}) + self.assertEqual(form.user_cache, user) + class SetPasswordFormTest(TestDataMixin, TestCase): |
