本文整理汇总了Python中oauth2client.gce.AppAssertionCredentials.refresh方法的典型用法代码示例。如果您正苦于以下问题:Python AppAssertionCredentials.refresh方法的具体用法?Python AppAssertionCredentials.refresh怎么用?Python AppAssertionCredentials.refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client.gce.AppAssertionCredentials
的用法示例。
在下文中一共展示了AppAssertionCredentials.refresh方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_good_refresh
# 需要导入模块: from oauth2client.gce import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.gce.AppAssertionCredentials import refresh [as 别名]
def test_good_refresh(self):
http = mock.MagicMock()
http.request = mock.MagicMock(
return_value=(mock.Mock(status=200),
'{"accessToken": "this-is-a-token"}'))
c = AppAssertionCredentials(scope=['http://example.com/a',
'http://example.com/b'])
self.assertEquals(None, c.access_token)
c.refresh(http)
self.assertEquals('this-is-a-token', c.access_token)
http.request.assert_called_exactly_once_with(
'http://metadata.google.internal/0.1/meta-data/service-accounts/'
'default/acquire'
'?scope=http%3A%2F%2Fexample.com%2Fa%20http%3A%2F%2Fexample.com%2Fb')
示例2: test_refresh_failure_400
# 需要导入模块: from oauth2client.gce import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.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)
示例3: test_refresh_failure_404
# 需要导入模块: from oauth2client.gce import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.gce.AppAssertionCredentials import refresh [as 别名]
def test_refresh_failure_404(self):
http = mock.MagicMock()
content = '{}'
http.request = mock.MagicMock(
return_value=(mock.Mock(status=404), 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)
expanded_content = content + (' This can occur if a VM was created'
' with no service account or scopes.')
self.assertEqual(str(exception_caught), expanded_content)
示例4: _refresh_success_helper
# 需要导入模块: from oauth2client.gce import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.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)