本文整理匯總了Python中oauth2client.contrib.gce.AppAssertionCredentials.refresh方法的典型用法代碼示例。如果您正苦於以下問題:Python AppAssertionCredentials.refresh方法的具體用法?Python AppAssertionCredentials.refresh怎麽用?Python AppAssertionCredentials.refresh使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類oauth2client.contrib.gce.AppAssertionCredentials
的用法示例。
在下文中一共展示了AppAssertionCredentials.refresh方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_refresh_failure_400
# 需要導入模塊: from oauth2client.contrib.gce import AppAssertionCredentials [as 別名]
# 或者: from oauth2client.contrib.gce.AppAssertionCredentials import refresh [as 別名]
def test_refresh_failure_400(self):
http = mock.MagicMock()
content = '{}'
http.request = mock.MagicMock(
return_value=(mock.Mock(status=http_client.BAD_REQUEST), content))
credentials = AppAssertionCredentials()
with self.assertRaises(HttpAccessTokenRefreshError):
credentials.refresh(http)
示例2: test_refresh_failure_400
# 需要導入模塊: from oauth2client.contrib.gce import AppAssertionCredentials [as 別名]
# 或者: from oauth2client.contrib.gce.AppAssertionCredentials import refresh [as 別名]
def test_refresh_failure_400(self):
http = mock.MagicMock()
content = '{}'
http.request = mock.MagicMock(
return_value=(mock.Mock(status=http_client.BAD_REQUEST), content))
credentials = AppAssertionCredentials()
exception_caught = None
try:
credentials.refresh(http)
except AccessTokenRefreshError as exc:
exception_caught = exc
self.assertNotEqual(exception_caught, None)
self.assertEqual(str(exception_caught), content)
示例3: test_refresh_failure_400
# 需要導入模塊: from oauth2client.contrib.gce import AppAssertionCredentials [as 別名]
# 或者: from oauth2client.contrib.gce.AppAssertionCredentials import refresh [as 別名]
def test_refresh_failure_400(self):
http = mock.MagicMock()
content = '{}'
http.request = mock.MagicMock(
return_value=(mock.Mock(status=400), content))
credentials = AppAssertionCredentials(
scope=['http://example.com/a', 'http://example.com/b'])
exception_caught = None
try:
credentials.refresh(http)
except AccessTokenRefreshError as exc:
exception_caught = exc
self.assertNotEqual(exception_caught, None)
self.assertEqual(str(exception_caught), content)
示例4: test_refresh_failure_404
# 需要導入模塊: from oauth2client.contrib.gce import AppAssertionCredentials [as 別名]
# 或者: from oauth2client.contrib.gce.AppAssertionCredentials import refresh [as 別名]
def test_refresh_failure_404(self):
http = mock.MagicMock()
content = '{}'
http.request = mock.MagicMock(
return_value=(mock.Mock(status=http_client.NOT_FOUND), content))
credentials = AppAssertionCredentials()
exception_caught = None
try:
credentials.refresh(http)
except AccessTokenRefreshError as exc:
exception_caught = exc
self.assertNotEqual(exception_caught, None)
expanded_content = content + (' This can occur if a VM was created'
' with no service account or scopes.')
self.assertEqual(str(exception_caught), expanded_content)
示例5: _refresh_success_helper
# 需要導入模塊: from oauth2client.contrib.gce import AppAssertionCredentials [as 別名]
# 或者: from oauth2client.contrib.gce.AppAssertionCredentials import refresh [as 別名]
def _refresh_success_helper(self, bytes_response=False):
access_token = u'this-is-a-token'
return_val = json.dumps({u'access_token': access_token})
if bytes_response:
return_val = _to_bytes(return_val)
http = mock.MagicMock()
http.request = mock.MagicMock(
return_value=(mock.Mock(status=http_client.OK), return_val))
credentials = AppAssertionCredentials()
self.assertEquals(None, credentials.access_token)
credentials.refresh(http)
self.assertEquals(access_token, credentials.access_token)
base_metadata_uri = (
'http://metadata.google.internal/computeMetadata/v1/instance/'
'service-accounts/default/token')
http.request.assert_called_once_with(
base_metadata_uri, headers={'Metadata-Flavor': 'Google'})
示例6: test_token_info
# 需要導入模塊: from oauth2client.contrib.gce import AppAssertionCredentials [as 別名]
# 或者: from oauth2client.contrib.gce.AppAssertionCredentials import refresh [as 別名]
def test_token_info(self):
credentials = AppAssertionCredentials([])
http = httplib2.Http()
# First refresh to get the access token.
self.assertIsNone(credentials.access_token)
credentials.refresh(http)
self.assertIsNotNone(credentials.access_token)
# Then check the access token against the token info API.
query_params = {'access_token': credentials.access_token}
token_uri = (GOOGLE_TOKEN_INFO_URI + '?' +
urllib.parse.urlencode(query_params))
response, content = http.request(token_uri)
self.assertEqual(response.status, http_client.OK)
content = content.decode('utf-8')
payload = json.loads(content)
self.assertEqual(payload['access_type'], 'offline')
self.assertLessEqual(int(payload['expires_in']), 3600)
示例7: _refresh_success_helper
# 需要導入模塊: from oauth2client.contrib.gce import AppAssertionCredentials [as 別名]
# 或者: from oauth2client.contrib.gce.AppAssertionCredentials import refresh [as 別名]
def _refresh_success_helper(self, bytes_response=False):
access_token = u'this-is-a-token'
return_val = json.dumps({u'accessToken': access_token})
if bytes_response:
return_val = _to_bytes(return_val)
http = mock.MagicMock()
http.request = mock.MagicMock(
return_value=(mock.Mock(status=200), return_val))
scopes = ['http://example.com/a', 'http://example.com/b']
credentials = AppAssertionCredentials(scope=scopes)
self.assertEquals(None, credentials.access_token)
credentials.refresh(http)
self.assertEquals(access_token, credentials.access_token)
base_metadata_uri = ('http://metadata.google.internal/0.1/meta-data/'
'service-accounts/default/acquire')
escaped_scopes = urllib.parse.quote(' '.join(scopes), safe='')
request_uri = base_metadata_uri + '?scope=' + escaped_scopes
http.request.assert_called_once_with(request_uri)