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