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'
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'
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