當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。