Skip to content

Commit

Permalink
Speech: replace httplib2 with Requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott committed Jul 26, 2017
1 parent f8c34ed commit 2bc9846
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions speech/google/cloud/speech/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions speech/tests/unit/test__http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
)

0 comments on commit 2bc9846

Please sign in to comment.