Beispiel #1
0
def test_base_url():
    client = _http_client.HttpClient(base_url=_TEST_URL)
    assert client.session is not None
    assert client.base_url == _TEST_URL
    recorder = _instrument(client, 'body')
    resp = client.request('get', 'foo')
    assert resp.status_code == 200
    assert resp.text == 'body'
    assert len(recorder) == 1
    assert recorder[0].method == 'GET'
    assert recorder[0].url == _TEST_URL + 'foo'
Beispiel #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'
Beispiel #3
0
def test_http_client_custom_session():
    session = requests.Session()
    client = _http_client.HttpClient(session=session)
    assert client.session is session
    assert client.base_url == ''
    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