本文整理匯總了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)