当前位置: 首页>>代码示例>>Python>>正文


Python user_logged_in.connect方法代码示例

本文整理汇总了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) 
开发者ID:nesdis,项目名称:djongo,代码行数:14,代码来源:tests.py

示例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) 
开发者ID:nesdis,项目名称:djongo,代码行数:17,代码来源:tests.py

示例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) 
开发者ID:nesdis,项目名称:djongo,代码行数:17,代码来源:tests.py

示例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) 
开发者ID:nesdis,项目名称:djongo,代码行数:16,代码来源:tests.py

示例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) 
开发者ID:nesdis,项目名称:djongo,代码行数:13,代码来源:tests.py


注:本文中的django.contrib.auth.signals.user_logged_in.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。