def test_urlopen_refresh(self):
credentials = mock.Mock(wraps=CredentialsStub())
final_response = ResponseStub(status=http_client.OK)
# First request will 401, second request will succeed.
http = HttpStub([
ResponseStub(status=http_client.UNAUTHORIZED),
final_response])
authed_http = google.auth.transport.urllib3.AuthorizedHttp(
credentials, http=http)
authed_http = authed_http.urlopen('GET', 'http://example.com')
assert authed_http == final_response
assert credentials.before_request.call_count == 2
assert credentials.refresh.called
assert http.requests == [
('GET', self.TEST_URL, None, {'authorization': 'token'}, {}),
('GET', self.TEST_URL, None, {'authorization': 'token1'}, {})]
test_urllib3.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录