fix: fix .close() (#1231)
Call `self._http.close()`, since `google_auth_httplib2.AuthorizedHttp` (https://github.com/googleapis/google-auth-library-python-httplib2/commit/feda187133beeb656fdd7f30ed124ed1e428a74a) has been fixed to also have a `close` method like `httplib2.Http()`
Fixes #1046 🦕
diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py
index 44473dc..a81ceca 100644
--- a/googleapiclient/discovery.py
+++ b/googleapiclient/discovery.py
@@ -1361,7 +1361,7 @@
# 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)
diff --git a/setup.py b/setup.py
index b95495b..80362d8 100644
--- a/setup.py
+++ b/setup.py
@@ -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",
diff --git a/tests/test_discovery.py b/tests/test_discovery.py
index 1a57ad3..fbb6475 100644
--- a/tests/test_discovery.py
+++ b/tests/test_discovery.py
@@ -87,6 +87,7 @@
from oauth2client import GOOGLE_TOKEN_URI
from oauth2client.client import OAuth2Credentials, GoogleCredentials
+
from googleapiclient import _helpers as util
import uritemplate
@@ -591,14 +592,27 @@
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")