From cb2d62c45a8cd15aad2d1068a0c5d22ceacf7181 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Thu, 27 Jul 2017 11:21:30 -0700 Subject: [PATCH] Remove httplib2, replace with Requests (#3674) * Core: remove httplib2, replace with Requests Additionally remove make_exception in favor of from_http_status and from_http_response. * Datastore: replace httplib2 with Requests * DNS: replace httplib2 with Requests * Error Reporting: replace httplib2 with requests * Language: replace httplib2 with Requests * Logging: replace httplib2 with requests * Monitoring: replace httplib2 with Requests * Pubsub: replace httplib2 with Requests * Resource Manager: replace httplib2 with Requests * Runtimeconfig: replace httplib2 with Requests * Speech: replace httplib2 with Requests * Storage: replace httplib2 with Requests * BigQuery: replace httplib2 with Requests * Translate: replace httplib2 with Requests * Vision: replace httplib2 with Requests --- .../google/cloud/speech/client.py | 4 ++-- .../tests/unit/test__http.py | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/google-cloud-speech/google/cloud/speech/client.py b/packages/google-cloud-speech/google/cloud/speech/client.py index 7c066d48cb9d..df0bee95461b 100644 --- a/packages/google-cloud-speech/google/cloud/speech/client.py +++ b/packages/google-cloud-speech/google/cloud/speech/client.py @@ -39,10 +39,10 @@ class Client(BaseClient): passed), falls back to the default inferred from the environment. - :type _http: :class:`~httplib2.Http` + :type _http: :class:`~requests.Session` :param _http: (Optional) HTTP object to make requests. Can be any object that defines ``request()`` with the same interface as - :meth:`~httplib2.Http.request`. If not passed, an + :meth:`requests.Session.request`. If not passed, an ``_http`` object is created that is bound to the ``credentials`` for the current object. This parameter should be considered private, and could diff --git a/packages/google-cloud-speech/tests/unit/test__http.py b/packages/google-cloud-speech/tests/unit/test__http.py index fd39428ffdbb..4aa7613910e9 100644 --- a/packages/google-cloud-speech/tests/unit/test__http.py +++ b/packages/google-cloud-speech/tests/unit/test__http.py @@ -40,13 +40,17 @@ def test_build_api_url(self): self.assertEqual(conn.build_api_url(method), uri) def test_extra_headers(self): + import requests + from google.cloud import _http as base_http from google.cloud.speech import _http as MUT - http = mock.Mock(spec=['request']) - response = mock.Mock(status=200, spec=['status']) + http = mock.create_autospec(requests.Session, instance=True) + response = requests.Response() + response.status_code = 200 data = b'brent-spiner' - http.request.return_value = response, data + response._content = data + http.request.return_value = response client = mock.Mock(_http=http, spec=['_http']) conn = self._make_one(client) @@ -56,12 +60,14 @@ def test_extra_headers(self): self.assertEqual(result, data) expected_headers = { - 'Content-Length': str(len(req_data)), 'Accept-Encoding': 'gzip', base_http.CLIENT_INFO_HEADER: MUT._CLIENT_INFO, 'User-Agent': conn.USER_AGENT, } expected_uri = conn.build_api_url('/rainbow') http.request.assert_called_once_with( - body=req_data, headers=expected_headers, method='GET', - uri=expected_uri) + data=req_data, + headers=expected_headers, + method='GET', + url=expected_uri, + )