本文整理汇总了Python中django.contrib.auth.forms.AuthenticationForm.non_field_errors方法的典型用法代码示例。如果您正苦于以下问题:Python AuthenticationForm.non_field_errors方法的具体用法?Python AuthenticationForm.non_field_errors怎么用?Python AuthenticationForm.non_field_errors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.forms.AuthenticationForm
的用法示例。
在下文中一共展示了AuthenticationForm.non_field_errors方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invalid_username
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import non_field_errors [as 别名]
def test_invalid_username(self):
# The user submits an invalid username.
data = {"username": "jsmith_does_not_exist", "password": "test123"}
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
self.assertEqual(form.non_field_errors(), [force_unicode(form.error_messages["invalid_login"])])
示例2: test_inactive_user_i18n
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import non_field_errors [as 别名]
def test_inactive_user_i18n(self):
with self.settings(USE_I18N=True), translation.override("pt-br", deactivate=True):
# The user is inactive.
data = {"username": "inactive", "password": "password"}
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
self.assertEqual(form.non_field_errors(), [force_text(form.error_messages["inactive"])])
示例3: test_success
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import non_field_errors [as 别名]
def test_success(self):
# The success case
data = {
'username': 'testclient',
'password': 'password',
}
form = AuthenticationForm(None, data)
self.assertTrue(form.is_valid())
self.assertEqual(form.non_field_errors(), [])
示例4: test_unicode_username
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import non_field_errors [as 别名]
def test_unicode_username(self):
User.objects.create_user(username='Σαρα', password='pwd')
data = {
'username': 'Σαρα',
'password': 'pwd',
}
form = AuthenticationForm(None, data)
self.assertTrue(form.is_valid())
self.assertEqual(form.non_field_errors(), [])
示例5: test_inactive_user
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import non_field_errors [as 别名]
def test_inactive_user(self):
# The user is inactive.
data = {
'username': 'inactive',
'password': 'password',
}
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
self.assertEqual(form.non_field_errors(), [str(form.error_messages['inactive'])])
示例6: test_inactive_user_i18n
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import non_field_errors [as 别名]
def test_inactive_user_i18n(self):
with self.settings(USE_I18N=True), translation.override('pt-br', deactivate=True):
# The user is inactive.
data = {
'username': 'inactive',
'password': 'password',
}
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
self.assertEqual(form.non_field_errors(), [str(form.error_messages['inactive'])])
示例7: test_invalid_username
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import non_field_errors [as 别名]
def test_invalid_username(self):
# The user submits an invalid username.
data = {
'username': 'jsmith_does_not_exist',
'password': 'test123',
}
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
self.assertEqual(form.non_field_errors(),
[u'Please enter a correct username and password. Note that both fields are case-sensitive.'])
示例8: test_invalid_username
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import non_field_errors [as 别名]
def test_invalid_username(self):
# The user submits an invalid username.
data = {
'username': 'jsmith_does_not_exist',
'password': 'test123',
}
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
self.assertEqual(form.non_field_errors(),
[force_text(form.error_messages['invalid_login'])])
示例9: test_invalid_username
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import non_field_errors [as 别名]
def test_invalid_username(self):
# The user submits an invalid username.
data = {"username": "jsmith_does_not_exist", "password": "test123"}
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
self.assertEqual(
form.non_field_errors(),
[
force_text(
form.error_messages["invalid_login"] % {"username": User._meta.get_field("username").verbose_name}
)
],
)
示例10: test_inactive_user_incorrect_password
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import non_field_errors [as 别名]
def test_inactive_user_incorrect_password(self):
"""An invalid login doesn't leak the inactive status of a user."""
data = {
'username': 'inactive',
'password': 'incorrect',
}
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
self.assertEqual(
form.non_field_errors(), [
form.error_messages['invalid_login'] % {
'username': User._meta.get_field('username').verbose_name
}
]
)
示例11: login
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import non_field_errors [as 别名]
def login(request, template_name='registration/login.html'):
form = AuthenticationForm(data=request.POST)
if request.method == "POST":
if not form.is_valid():
non_field_errors = form.non_field_errors()
if non_field_errors:
# test if the account is not active
user_inactive = non_field_errors[0].find(_("This account is inactive.")) != -1
# user_inactive = User.objects.filter(username=request.POST.get('username'), is_active=0).count() == 1
if user_inactive:
return render(request, template_name, {'form': form, 'user_inactive': user_inactive, })
return django_login(request)
示例12: test_success
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import non_field_errors [as 别名]
def test_success(self):
# The success case
data = {"username": "testclient", "password": "password"}
form = AuthenticationForm(None, data)
self.assertTrue(form.is_valid())
self.assertEqual(form.non_field_errors(), [])
示例13: test_inactive_user
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import non_field_errors [as 别名]
def test_inactive_user(self):
# The user is inactive.
data = {"username": "inactive", "password": "password"}
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
self.assertEqual(form.non_field_errors(), [force_unicode(form.error_messages["inactive"])])