本文整理匯總了Python中oauth2client.contrib.django_util.decorators.oauth_required方法的典型用法代碼示例。如果您正苦於以下問題:Python decorators.oauth_required方法的具體用法?Python decorators.oauth_required怎麽用?Python decorators.oauth_required使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類oauth2client.contrib.django_util.decorators
的用法示例。
在下文中一共展示了decorators.oauth_required方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_redirects_without_credentials
# 需要導入模塊: from oauth2client.contrib.django_util import decorators [as 別名]
# 或者: from oauth2client.contrib.django_util.decorators import oauth_required [as 別名]
def test_redirects_without_credentials(self):
request = self.factory.get('/test')
request.session = self.session
@decorators.oauth_required
def test_view(request):
return http.HttpResponse('test') # pragma: NO COVER
response = test_view(request)
self.assertIsInstance(response, http.HttpResponseRedirect)
self.assertEqual(parse.urlparse(response['Location']).path,
'/oauth2/oauth2authorize/')
self.assertIn(
'return_url=%2Ftest', parse.urlparse(response['Location']).query)
self.assertEqual(response.status_code,
http.HttpResponseRedirect.status_code)
示例2: test_has_credentials_in_storage
# 需要導入模塊: from oauth2client.contrib.django_util import decorators [as 別名]
# 或者: from oauth2client.contrib.django_util.decorators import oauth_required [as 別名]
def test_has_credentials_in_storage(self, UserOAuth2):
request = self.factory.get('/test')
request.session = mock.Mock()
@decorators.oauth_required
def test_view(request):
return http.HttpResponse("test")
my_user_oauth = mock.Mock()
UserOAuth2.return_value = my_user_oauth
my_user_oauth.has_credentials.return_value = True
response = test_view(request)
self.assertEqual(response.status_code, http_client.OK)
self.assertEqual(response.content, b"test")
示例3: test_has_credentials_in_storage_no_scopes
# 需要導入模塊: from oauth2client.contrib.django_util import decorators [as 別名]
# 或者: from oauth2client.contrib.django_util.decorators import oauth_required [as 別名]
def test_has_credentials_in_storage_no_scopes(
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 = False
OAuth2Credentials.from_json.return_value = credentials_mock
@decorators.oauth_required
def test_view(request):
return http.HttpResponse("test") # pragma: NO COVER
response = test_view(request)
self.assertEqual(
response.status_code, django.http.HttpResponseRedirect.status_code)
示例4: test_specified_scopes
# 需要導入模塊: from oauth2client.contrib.django_util import decorators [as 別名]
# 或者: from oauth2client.contrib.django_util.decorators import oauth_required [as 別名]
def test_specified_scopes(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 = mock.Mock(return_value=False)
OAuth2Credentials.from_json.return_value = credentials_mock
@decorators.oauth_required(scopes=['additional-scope'])
def test_view(request):
return http.HttpResponse("hello world") # pragma: NO COVER
response = test_view(request)
self.assertEqual(
response.status_code, django.http.HttpResponseRedirect.status_code)
示例5: test_redirects_anonymous_to_login
# 需要導入模塊: from oauth2client.contrib.django_util import decorators [as 別名]
# 或者: from oauth2client.contrib.django_util.decorators import oauth_required [as 別名]
def test_redirects_anonymous_to_login(self):
request = self.factory.get('/test')
request.session = self.session
request.user = django_models.AnonymousUser()
@decorators.oauth_required
def test_view(request):
return http.HttpResponse("test") # pragma: NO COVER
response = test_view(request)
self.assertIsInstance(response, http.HttpResponseRedirect)
self.assertEqual(parse.urlparse(response['Location']).path,
django.conf.settings.LOGIN_URL)