Exemplo n.º 1
0
 def test_retry_on_503(self, httpserver):
     httpserver.serve_content({}, 503)
     client = _http_client.JsonHttpClient(
         credential=testutils.MockGoogleCredential(),
         base_url=httpserver.url)
     with pytest.raises(requests.exceptions.HTTPError) as excinfo:
         client.request('get', '/')
     assert excinfo.value.response.status_code == 503
     assert len(httpserver.requests) == 5
Exemplo n.º 2
0
def test_credential():
    client = _http_client.HttpClient(
        credential=testutils.MockGoogleCredential())
    assert client.session is not None
    recorder = _instrument(client, 'body')
    resp = client.request('get', _TEST_URL)
    assert resp.status_code == 200
    assert resp.text == 'body'
    assert len(recorder) == 1
    assert recorder[0].method == 'GET'
    assert recorder[0].url == _TEST_URL
    assert recorder[0].headers['Authorization'] == 'Bearer mock-token'
Exemplo n.º 3
0
 def test_retry_on_500(self, httpserver, method):
     httpserver.serve_content({}, 500)
     client = _http_client.JsonHttpClient(
         credential=testutils.MockGoogleCredential(),
         base_url=httpserver.url)
     body = None
     if method in self.ENTITY_ENCLOSING_METHODS:
         body = {'key': 'value'}
     with pytest.raises(requests.exceptions.HTTPError) as excinfo:
         client.request(method, '/', json=body)
     assert excinfo.value.response.status_code == 500
     assert len(httpserver.requests) == 5
Exemplo n.º 4
0
 def __init__(self):
     self._g_credential = testutils.MockGoogleCredential()