Skip to content

Commit a7f2d02

Browse files
author
Jon Wayne Parrott
authored
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
1 parent 729564d commit a7f2d02

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

packages/google-cloud-translate/google/cloud/translate_v2/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ class Client(BaseClient):
4747
passed), falls back to the default inferred from the
4848
environment.
4949
50-
:type _http: :class:`~httplib2.Http`
50+
:type _http: :class:`~requests.Session`
5151
:param _http: (Optional) HTTP object to make requests. Can be any object
5252
that defines ``request()`` with the same interface as
53-
:meth:`~httplib2.Http.request`. If not passed, an
53+
:meth:`requests.Session.request`. If not passed, an
5454
``_http`` object is created that is bound to the
5555
``credentials`` for the current object.
5656
This parameter should be considered private, and could

packages/google-cloud-translate/tests/unit/test__http.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ def test_build_api_url_w_extra_query_params(self):
5656
self.assertEqual(params, query_params)
5757

5858
def test_extra_headers(self):
59+
import requests
60+
5961
from google.cloud import _http as base_http
6062
from google.cloud.translate_v2 import _http as MUT
6163

62-
http = mock.Mock(spec=['request'])
63-
response = mock.Mock(status=200, spec=['status'])
64+
http = mock.create_autospec(requests.Session, instance=True)
65+
response = requests.Response()
66+
response.status_code = 200
6467
data = b'brent-spiner'
65-
http.request.return_value = response, data
68+
response._content = data
69+
http.request.return_value = response
6670
client = mock.Mock(_http=http, spec=['_http'])
6771

6872
conn = self._make_one(client)
@@ -72,15 +76,14 @@ def test_extra_headers(self):
7276
self.assertEqual(result, data)
7377

7478
expected_headers = {
75-
'Content-Length': str(len(req_data)),
7679
'Accept-Encoding': 'gzip',
7780
base_http.CLIENT_INFO_HEADER: MUT._CLIENT_INFO,
7881
'User-Agent': conn.USER_AGENT,
7982
}
8083
expected_uri = conn.build_api_url('/rainbow')
8184
http.request.assert_called_once_with(
82-
body=req_data,
85+
data=req_data,
8386
headers=expected_headers,
8487
method='GET',
85-
uri=expected_uri,
88+
url=expected_uri,
8689
)

0 commit comments

Comments
 (0)