diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 6912783451..0d28e8a15b 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,32 @@ def test_file_based_cache(self): class Discovery(unittest.TestCase): + @mock.patch("googleapiclient.discovery.build_http") + def test_discovery_http_is_closed(self, mock_build_http): + mock_discovery_http = mock.Mock() + mock_service_http = mock.Mock() + + mock_discovery_http.request.return_value = ( + httplib2.Response({"status": "200"}), + read_datafile("plus.json", "rb"), + ) + mock_service_http.request.return_value = ( + httplib2.Response({"status": "200"}), + read_datafile("plus.json", "rb"), + ) + mock_build_http.side_effect = [ + mock_discovery_http, + mock_service_http, + ] + + build( + "plus", + "v1", + developerKey="test_key", + static_discovery=False, + ) + mock_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)