Skip to content

Commit a9583f7

Browse files
authored
fix: fix .close() (#1231)
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 🦕
1 parent 6137c8c commit a9583f7

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

googleapiclient/discovery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ def close(self):
13611361
# httplib2 leaves sockets open by default.
13621362
# Cleanup using the `close` method.
13631363
# https://github.com/httplib2/httplib2/issues/148
1364-
self._http.http.close()
1364+
self._http.close()
13651365

13661366
def _set_service_methods(self):
13671367
self._add_basic_methods(self._resourceDesc, self._rootDesc, self._schema)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
install_requires = [
3535
"httplib2>=0.15.0,<1dev",
3636
"google-auth>=1.16.0,<2dev",
37-
"google-auth-httplib2>=0.0.3",
37+
"google-auth-httplib2>=0.1.0",
3838
"google-api-core>=1.21.0,<2dev",
3939
"six>=1.13.0,<2dev",
4040
"uritemplate>=3.0.0,<4dev",

tests/test_discovery.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
from oauth2client import GOOGLE_TOKEN_URI
8888
from oauth2client.client import OAuth2Credentials, GoogleCredentials
8989

90+
9091
from googleapiclient import _helpers as util
9192

9293
import uritemplate
@@ -591,14 +592,27 @@ def test_building_with_context_manager(self):
591592

592593
def test_resource_close(self):
593594
discovery = read_datafile("plus.json")
594-
with mock.patch("httplib2.Http") as http:
595+
596+
with mock.patch("httplib2.Http", autospec=True) as httplib2_http:
597+
http = httplib2_http()
598+
plus = build_from_document(
599+
discovery,
600+
base="https://www.googleapis.com/",
601+
http=http,
602+
)
603+
plus.close()
604+
http.close.assert_called_once()
605+
606+
def test_resource_close_authorized_http(self):
607+
discovery = read_datafile("plus.json")
608+
with mock.patch("google_auth_httplib2.AuthorizedHttp", autospec=True):
595609
plus = build_from_document(
596610
discovery,
597611
base="https://www.googleapis.com/",
598612
credentials=self.MOCK_CREDENTIALS,
599613
)
600614
plus.close()
601-
plus._http.http.close.assert_called_once()
615+
plus._http.close.assert_called_once()
602616

603617
def test_api_endpoint_override_from_client_options(self):
604618
discovery = read_datafile("plus.json")

0 commit comments

Comments
 (0)