Skip to content
Permalink
Browse files
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 馃
  • Loading branch information
busunkim96 committed Mar 15, 2021
1 parent 6137c8c commit a9583f712d13c67aa282d14cd30e00999b530d7c
Showing with 18 additions and 4 deletions.
  1. +1 鈭1 googleapiclient/discovery.py
  2. +1 鈭1 setup.py
  3. +16 鈭2 tests/test_discovery.py
@@ -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)
@@ -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",
@@ -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_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")

0 comments on commit a9583f7

Please sign in to comment.