当前位置: 首页>>代码示例>>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;未经允许,请勿转载。