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