当前位置: 首页>>代码示例>>Python>>正文


Python AppAssertionCredentials.refresh方法代码示例

本文整理汇总了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')
开发者ID:dulaccc,项目名称:oauth2client,代码行数:18,代码来源:test_gce.py

示例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)
开发者ID:JasOXIII,项目名称:oauth2client,代码行数:19,代码来源:test_gce.py

示例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)
开发者ID:JasOXIII,项目名称:oauth2client,代码行数:21,代码来源:test_gce.py

示例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)
开发者ID:JasOXIII,项目名称:oauth2client,代码行数:22,代码来源:test_gce.py


注:本文中的oauth2client.gce.AppAssertionCredentials.refresh方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。