本文整理汇总了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)