diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 6912783451..02a496730a 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -495,13 +495,6 @@ def test_ResourceMethodParameters_zoo_animals_patch(self): self.assertEqual(parameters.enum_params, {}) -class Discovery(unittest.TestCase): - def test_discovery_http_is_closed(self): - http = HttpMock(datafile("malformed.json"), {"status": "200"}) - service = build("plus", "v1", credentials=mock.sentinel.credentials) - http.close.assert_called_once() - - class DiscoveryErrors(unittest.TestCase): def test_tests_should_be_run_with_strict_positional_enforcement(self): try: @@ -1549,6 +1542,20 @@ def test_file_based_cache(self): class Discovery(unittest.TestCase): + @mock.patch("httplib2.Http") + def test_discovery_http_is_closed(self, http_class): + discovery_http = http_class.return_value + discovery_http.request.return_value = ( + httplib2.Response({"status": "200"}), + read_datafile("plus.json", "rb"), + ) + + build("plus", "v1", cache_discovery=False, static_discovery=False) + + # build() creates a temporary http client to fetch the discovery + # document and must close it so the connection is not leaked. + discovery_http.close.assert_called_once() + def test_method_error_checking(self): self.http = HttpMock(datafile("plus.json"), {"status": "200"}) plus = build("plus", "v1", http=self.http, static_discovery=False)