diff --git a/google/cloud/_http.py b/google/cloud/_http.py index 12315c2..b6aedce 100644 --- a/google/cloud/_http.py +++ b/google/cloud/_http.py @@ -211,8 +211,12 @@ def build_api_url( ) query_params = query_params or {} - if query_params: - url += "?" + urlencode(query_params, doseq=True) + + if "prettyPrint" not in query_params: + query_params = query_params.copy() + query_params["prettyPrint"] = "false" + + url += "?" + urlencode(query_params, doseq=True) return url diff --git a/tests/unit/test__http.py b/tests/unit/test__http.py index 145e302..bd50b1e 100644 --- a/tests/unit/test__http.py +++ b/tests/unit/test__http.py @@ -184,9 +184,16 @@ def test_build_api_url_no_extra_query_params(self): client = object() conn = self._make_mock_one(client) # Intended to emulate self.mock_template - URI = "/".join([conn.API_BASE_URL, "mock", conn.API_VERSION, "foo"]) + URI = "/".join([conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=false"]) self.assertEqual(conn.build_api_url("/foo"), URI) + def test_build_api_url_w_pretty_print_query_params(self): + client = object() + conn = self._make_mock_one(client) + uri = conn.build_api_url("/foo", {"prettyPrint": "true"}) + URI = "/".join([conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=true"]) + self.assertEqual(uri, URI) + def test_build_api_url_w_extra_query_params(self): from six.moves.urllib.parse import parse_qs from six.moves.urllib.parse import urlsplit @@ -319,7 +326,7 @@ def test_api_request_defaults(self): "User-Agent": conn.user_agent, CLIENT_INFO_HEADER: conn.user_agent, } - expected_url = "{base}/mock/{version}{path}".format( + expected_url = "{base}/mock/{version}{path}?prettyPrint=false".format( base=conn.API_BASE_URL, version=conn.API_VERSION, path=path ) http.request.assert_called_once_with( @@ -481,7 +488,7 @@ def test_api_request_w_timeout(self): "User-Agent": conn.user_agent, CLIENT_INFO_HEADER: conn.user_agent, } - expected_url = "{base}/mock/{version}{path}".format( + expected_url = "{base}/mock/{version}{path}?prettyPrint=false".format( base=conn.API_BASE_URL, version=conn.API_VERSION, path=path ) http.request.assert_called_once_with(