Content-Length: 352896 | pFad | https://www.github.com/googleapis/python-cloud-core/commit/c407b5d617c04affbdb4f444c188edffb25d4336

248 perf: use prettyPrint=false by default (#28) · googleapis/python-cloud-core@c407b5d · GitHub
Skip to content

Commit c407b5d

Browse files
tswastbusunkim96
andauthored
perf: use prettyPrint=false by default (#28)
This tells One Platform APIs not to use excessive whitespace in responses. For some reason, the backend defaults to prettyPrint=true and does not provide a mechanism for overriding this. In response to internal customer issue 168522192. Tested locally against `google-cloud-bigquery` system and sample tests. Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
1 parent 2bdc50e commit c407b5d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

google/cloud/_http.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,12 @@ def build_api_url(
211211
)
212212

213213
query_params = query_params or {}
214-
if query_params:
215-
url += "?" + urlencode(query_params, doseq=True)
214+
215+
if "prettyPrint" not in query_params:
216+
query_params = query_params.copy()
217+
query_params["prettyPrint"] = "false"
218+
219+
url += "?" + urlencode(query_params, doseq=True)
216220

217221
return url
218222

tests/unit/test__http.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,16 @@ def test_build_api_url_no_extra_query_params(self):
184184
client = object()
185185
conn = self._make_mock_one(client)
186186
# Intended to emulate self.mock_template
187-
URI = "/".join([conn.API_BASE_URL, "mock", conn.API_VERSION, "foo"])
187+
URI = "/".join([conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=false"])
188188
self.assertEqual(conn.build_api_url("/foo"), URI)
189189

190+
def test_build_api_url_w_pretty_print_query_params(self):
191+
client = object()
192+
conn = self._make_mock_one(client)
193+
uri = conn.build_api_url("/foo", {"prettyPrint": "true"})
194+
URI = "/".join([conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=true"])
195+
self.assertEqual(uri, URI)
196+
190197
def test_build_api_url_w_extra_query_params(self):
191198
from six.moves.urllib.parse import parse_qs
192199
from six.moves.urllib.parse import urlsplit
@@ -319,7 +326,7 @@ def test_api_request_defaults(self):
319326
"User-Agent": conn.user_agent,
320327
CLIENT_INFO_HEADER: conn.user_agent,
321328
}
322-
expected_url = "{base}/mock/{version}{path}".format(
329+
expected_url = "{base}/mock/{version}{path}?prettyPrint=false".format(
323330
base=conn.API_BASE_URL, version=conn.API_VERSION, path=path
324331
)
325332
http.request.assert_called_once_with(
@@ -481,7 +488,7 @@ def test_api_request_w_timeout(self):
481488
"User-Agent": conn.user_agent,
482489
CLIENT_INFO_HEADER: conn.user_agent,
483490
}
484-
expected_url = "{base}/mock/{version}{path}".format(
491+
expected_url = "{base}/mock/{version}{path}?prettyPrint=false".format(
485492
base=conn.API_BASE_URL, version=conn.API_VERSION, path=path
486493
)
487494
http.request.assert_called_once_with(

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://www.github.com/googleapis/python-cloud-core/commit/c407b5d617c04affbdb4f444c188edffb25d4336

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy