Skip to content

Commit

Permalink
fix: fix .close() (#1231)
Browse files Browse the repository at this point in the history
Call `self._http.close()`, since `google_auth_httplib2.AuthorizedHttp` (googleapis/google-auth-library-python-httplib2@feda187) has been fixed to also have a `close` method like `httplib2.Http()`


Fixes #1046 馃
  • Loading branch information
busunkim96 committed Mar 15, 2021
1 parent 6137c8c commit a9583f7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion googleapiclient/discovery.py
Expand Up @@ -1361,7 +1361,7 @@ def close(self):
# httplib2 leaves sockets open by default.
# Cleanup using the `close` method.
# https://github.com/httplib2/httplib2/issues/148
self._http.http.close()
self._http.close()

def _set_service_methods(self):
self._add_basic_methods(self._resourceDesc, self._rootDesc, self._schema)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -34,7 +34,7 @@
install_requires = [
"httplib2>=0.15.0,<1dev",
"google-auth>=1.16.0,<2dev",
"google-auth-httplib2>=0.0.3",
"google-auth-httplib2>=0.1.0",
"google-api-core>=1.21.0,<2dev",
"six>=1.13.0,<2dev",
"uritemplate>=3.0.0,<4dev",
Expand Down
18 changes: 16 additions & 2 deletions tests/test_discovery.py
Expand Up @@ -87,6 +87,7 @@
from oauth2client import GOOGLE_TOKEN_URI
from oauth2client.client import OAuth2Credentials, GoogleCredentials


from googleapiclient import _helpers as util

import uritemplate
Expand Down Expand Up @@ -591,14 +592,27 @@ def test_building_with_context_manager(self):

def test_resource_close(self):
discovery = read_datafile("plus.json")
with mock.patch("httplib2.Http") as http:

with mock.patch("httplib2.Http", autospec=True) as httplib2_http:
http = httplib2_http()
plus = build_from_document(
discovery,
base="https://www.googleapis.com/",
http=http,
)
plus.close()
http.close.assert_called_once()

def test_resource_close_authorized_http(self):
discovery = read_datafile("plus.json")
with mock.patch("google_auth_httplib2.AuthorizedHttp", autospec=True):
plus = build_from_document(
discovery,
base="https://www.googleapis.com/",
credentials=self.MOCK_CREDENTIALS,
)
plus.close()
plus._http.http.close.assert_called_once()
plus._http.close.assert_called_once()

def test_api_endpoint_override_from_client_options(self):
discovery = read_datafile("plus.json")
Expand Down

0 comments on commit a9583f7

Please sign in to comment.