Skip to content

Commit

Permalink
Runtimeconfig: 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 b4ad989 commit f8c34ed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions runtimeconfig/google/cloud/runtimeconfig/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class Client(ClientWithProject):
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
2 changes: 1 addition & 1 deletion runtimeconfig/google/cloud/runtimeconfig/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _require_client(self, client):
def _set_properties(self, api_response):
"""Update properties from resource in body of ``api_response``
:type api_response: httplib2.Response
:type api_response: dict
:param api_response: response returned from an API call
"""
self._properties.clear()
Expand Down
15 changes: 9 additions & 6 deletions runtimeconfig/tests/unit/test__http.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ def test_default_url(self):
self.assertIs(conn._client, client)

def test_extra_headers(self):
import requests

from google.cloud import _http as base_http
from google.cloud.runtimeconfig 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 @@ -50,15 +54,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,
data=req_data,
headers=expected_headers,
method='GET',
uri=expected_uri,
url=expected_uri,
)

0 comments on commit f8c34ed

Please sign in to comment.