本文整理匯總了Python中django.contrib.auth.signals.user_logged_in.connect方法的典型用法代碼示例。如果您正苦於以下問題:Python user_logged_in.connect方法的具體用法?Python user_logged_in.connect怎麽用?Python user_logged_in.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.contrib.auth.signals.user_logged_in
的用法示例。
在下文中一共展示了user_logged_in.connect方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_logout_with_user
# 需要導入模塊: from django.contrib.auth.signals import user_logged_in [as 別名]
# 或者: from django.contrib.auth.signals.user_logged_in import connect [as 別名]
def test_logout_with_user(self):
"""Logout should send user_logged_out signal if user was logged in."""
def listener(*args, **kwargs):
listener.executed = True
self.assertEqual(kwargs['sender'], User)
listener.executed = False
user_logged_out.connect(listener)
self.client.login(username='testclient', password='password')
self.client.logout()
user_logged_out.disconnect(listener)
self.assertTrue(listener.executed)
示例2: test_logout_with_custom_user
# 需要導入模塊: from django.contrib.auth.signals import user_logged_in [as 別名]
# 或者: from django.contrib.auth.signals.user_logged_in import connect [as 別名]
def test_logout_with_custom_user(self):
"""Logout should send user_logged_out signal if custom user was logged in."""
def listener(*args, **kwargs):
self.assertEqual(kwargs['sender'], CustomUser)
listener.executed = True
listener.executed = False
u = CustomUser.custom_objects.create(email='test@test.com')
u.set_password('password')
u.save()
user_logged_out.connect(listener)
self.client.login(username='test@test.com', password='password')
self.client.logout()
user_logged_out.disconnect(listener)
self.assertTrue(listener.executed)
示例3: test_logout_with_custom_auth_backend
# 需要導入模塊: from django.contrib.auth.signals import user_logged_in [as 別名]
# 或者: from django.contrib.auth.signals.user_logged_in import connect [as 別名]
def test_logout_with_custom_auth_backend(self):
"Request a logout after logging in with custom authentication backend"
def listener(*args, **kwargs):
self.assertEqual(kwargs['sender'], CustomUser)
listener.executed = True
listener.executed = False
u = CustomUser.custom_objects.create(email='test@test.com')
u.set_password('password')
u.save()
user_logged_out.connect(listener)
self.client.login(username='test@test.com', password='password')
self.client.logout()
user_logged_out.disconnect(listener)
self.assertTrue(listener.executed)
示例4: test_logout_without_user
# 需要導入模塊: from django.contrib.auth.signals import user_logged_in [as 別名]
# 或者: from django.contrib.auth.signals.user_logged_in import connect [as 別名]
def test_logout_without_user(self):
"""Logout should send signal even if user not authenticated."""
def listener(user, *args, **kwargs):
listener.user = user
listener.executed = True
listener.executed = False
user_logged_out.connect(listener)
self.client.login(username='incorrect', password='password')
self.client.logout()
user_logged_out.disconnect(listener)
self.assertTrue(listener.executed)
self.assertIsNone(listener.user)
示例5: test_login_with_user
# 需要導入模塊: from django.contrib.auth.signals import user_logged_in [as 別名]
# 或者: from django.contrib.auth.signals.user_logged_in import connect [as 別名]
def test_login_with_user(self):
"""Login should send user_logged_in signal on successful login."""
def listener(*args, **kwargs):
listener.executed = True
listener.executed = False
user_logged_in.connect(listener)
self.client.login(username='testclient', password='password')
user_logged_out.disconnect(listener)
self.assertTrue(listener.executed)