當前位置: 首頁>>代碼示例>>Python>>正文


Python decorators.oauth_enabled方法代碼示例

本文整理匯總了Python中oauth2client.contrib.django_util.decorators.oauth_enabled方法的典型用法代碼示例。如果您正苦於以下問題:Python decorators.oauth_enabled方法的具體用法?Python decorators.oauth_enabled怎麽用?Python decorators.oauth_enabled使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oauth2client.contrib.django_util.decorators的用法示例。


在下文中一共展示了decorators.oauth_enabled方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_has_credentials_in_storage

# 需要導入模塊: from oauth2client.contrib.django_util import decorators [as 別名]
# 或者: from oauth2client.contrib.django_util.decorators import oauth_enabled [as 別名]
def test_has_credentials_in_storage(self, OAuth2Credentials):
        request = self.factory.get('/test')
        request.session = mock.Mock()

        credentials_mock = mock.Mock(
            scopes=set(django.conf.settings.GOOGLE_OAUTH2_SCOPES))
        credentials_mock.has_scopes.return_value = True
        credentials_mock.invalid = False
        credentials_mock.scopes = set([])
        OAuth2Credentials.from_json.return_value = credentials_mock

        @decorators.oauth_enabled
        def test_view(request):
            return http.HttpResponse('test')

        response = test_view(request)
        self.assertEqual(response.status_code, http_client.OK)
        self.assertEqual(response.content, b'test')
        self.assertTrue(request.oauth.has_credentials())
        self.assertIsNotNone(request.oauth.http)
        self.assertSetEqual(
            request.oauth.scopes,
            set(django.conf.settings.GOOGLE_OAUTH2_SCOPES)) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:25,代碼來源:test_decorators.py

示例2: test_specified_scopes

# 需要導入模塊: from oauth2client.contrib.django_util import decorators [as 別名]
# 或者: from oauth2client.contrib.django_util.decorators import oauth_enabled [as 別名]
def test_specified_scopes(self, dictionary_storage_mock):
        request = self.factory.get('/test')
        request.session = mock.Mock()

        credentials_mock = mock.Mock(
            scopes=set(django.conf.settings.GOOGLE_OAUTH2_SCOPES))
        credentials_mock.has_scopes = mock.Mock(return_value=True)
        credentials_mock.is_valid = True
        dictionary_storage_mock.get.return_value = credentials_mock

        @decorators.oauth_enabled(scopes=['additional-scope'])
        def test_view(request):
            return http.HttpResponse('hello world')  # pragma: NO COVER

        response = test_view(request)
        self.assertEqual(response.status_code, http_client.OK)
        self.assertIsNotNone(request.oauth)
        self.assertFalse(request.oauth.has_credentials()) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:20,代碼來源:test_decorators.py

示例3: test_no_credentials_without_credentials

# 需要導入模塊: from oauth2client.contrib.django_util import decorators [as 別名]
# 或者: from oauth2client.contrib.django_util.decorators import oauth_enabled [as 別名]
def test_no_credentials_without_credentials(self):
        request = self.factory.get('/test')
        request.session = self.session

        @decorators.oauth_enabled
        def test_view(request):
            return http.HttpResponse("test")  # pragma: NO COVER

        response = test_view(request)
        self.assertEqual(response.status_code, http_client.OK)
        self.assertIsNotNone(request.oauth)
        self.assertFalse(request.oauth.has_credentials())
        self.assertIsNone(request.oauth.http) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:15,代碼來源:test_decorators.py


注:本文中的oauth2client.contrib.django_util.decorators.oauth_enabled方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。