本文整理汇总了Python中auth.models.User.is_active方法的典型用法代码示例。如果您正苦于以下问题:Python User.is_active方法的具体用法?Python User.is_active怎么用?Python User.is_active使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类auth.models.User
的用法示例。
在下文中一共展示了User.is_active方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_login_form
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import is_active [as 别名]
def test_login_form(self):
# Set up a test user.
email = '[email protected]'
user = User(email=email)
user.set_password('password')
user.save()
# Missing required data
form = auth_forms.LoginForm({'redirect': '/'})
self.assertFalse(form.is_valid())
form = auth_forms.LoginForm({'redirect': '/', 'email': email})
self.assertFalse(form.is_valid())
# Form should fail to validate if password is incorrect.
form = auth_forms.LoginForm({'redirect': '/',
'email': email,
'password': 'incorrect password'})
self.assertFalse(form.is_valid())
# This should succeed.
form = auth_forms.LoginForm({'redirect': '/',
'email': email,
'password': 'password'})
self.assertTrue(form.is_valid())
# The form should reject inactive users.
user.is_active = False
user.save()
form = auth_forms.LoginForm({'redirect': '/',
'email': email,
'password': 'password'})
self.assertFalse(form.is_valid())
# The form should reject unknown users.
form = auth_forms.LoginForm({'redirect': '/',
'email': '[email protected]',
'password': 'password'})
self.assertFalse(form.is_valid())
示例2: test_get_current_user
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import is_active [as 别名]
def test_get_current_user(self):
# Set up a test user.
email = '[email protected]'
user = User(email=email)
user.save()
# Create some security tokens.
expired_token = auth._create_security_token(user)
self.now += 0.75 * auth._TOKEN_TIMEOUT_S
stale_token = auth._create_security_token(user)
self.now += 0.75 * auth._TOKEN_TIMEOUT_S
good_token = auth._create_security_token(user)
# Create a test HttpRequest, and test using it against our
# various tokens.
request = http.HttpRequest()
request.COOKIES[auth._CHIRP_SECURITY_TOKEN_COOKIE] = expired_token
self.assertEqual(None, auth.get_current_user(request))
request.COOKIES[auth._CHIRP_SECURITY_TOKEN_COOKIE] = stale_token
user = auth.get_current_user(request)
self.assertEqual(email, user.email)
self.assertTrue(user._credentials.security_token_is_stale)
request.COOKIES[auth._CHIRP_SECURITY_TOKEN_COOKIE] = good_token
user = auth.get_current_user(request)
self.assertEqual(email, user.email)
self.assertFalse(user._credentials.security_token_is_stale)
# Test that a password reset token can be used to authenticate
# when POSTed in a variable named CHIRP_Auth.
request = http.HttpRequest()
request.method = "POST"
self.assertEqual(None, auth.get_current_user(request))
request.POST["CHIRP_Auth"] = base64.urlsafe_b64encode(expired_token)
self.assertEqual(None, auth.get_current_user(request))
request.POST["CHIRP_Auth"] = "bogus!!!"
self.assertEqual(None, auth.get_current_user(request))
request.POST["CHIRP_Auth"] = base64.urlsafe_b64encode(good_token)
user = auth.get_current_user(request)
self.assertEqual(email, user.email)
# Check that we will reject an inactive user.
user.is_active = False
user.save()
self.assertRaises(auth.UserNotAllowedError,
auth.get_current_user, request)
user.is_active = True
user.save()