Skip to content

Commit 1a8af71

Browse files
authored
test: update tests to support latest google-cloud-core (#23)
`google-cloud-core` version 1.4.2 populates `prettyPrint=false` by default. Update the connection tests to expect a value for `prettyPrint`.
1 parent 1de1b56 commit 1a8af71

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

tests/unit/test__http.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,46 @@ def test_default_url(self):
3232
conn = self._make_one(client)
3333
self.assertIs(conn._client, client)
3434

35+
def test_build_api_url_no_extra_query_params(self):
36+
from six.moves.urllib.parse import parse_qsl
37+
from six.moves.urllib.parse import urlsplit
38+
39+
conn = self._make_one(object())
40+
uri = conn.build_api_url("/foo")
41+
scheme, netloc, path, qs, _ = urlsplit(uri)
42+
self.assertEqual("%s://%s" % (scheme, netloc), conn.API_BASE_URL)
43+
self.assertEqual(path, "/".join(["", conn.API_VERSION, "foo"]))
44+
parms = dict(parse_qsl(qs))
45+
pretty_print = parms.pop("prettyPrint", "false")
46+
self.assertEqual(pretty_print, "false")
47+
self.assertEqual(parms, {})
48+
3549
def test_build_api_url_w_custom_endpoint(self):
50+
from six.moves.urllib.parse import parse_qsl
51+
from six.moves.urllib.parse import urlsplit
52+
3653
custom_endpoint = "https://foo-runtimeconfig.googleapis.com"
3754
conn = self._make_one(object(), api_endpoint=custom_endpoint)
38-
URI = "/".join([custom_endpoint, conn.API_VERSION, "foo"])
39-
self.assertEqual(conn.build_api_url("/foo"), URI)
55+
uri = conn.build_api_url("/foo")
56+
scheme, netloc, path, qs, _ = urlsplit(uri)
57+
self.assertEqual("%s://%s" % (scheme, netloc), custom_endpoint)
58+
self.assertEqual(path, "/".join(["", conn.API_VERSION, "foo"]))
59+
parms = dict(parse_qsl(qs))
60+
pretty_print = parms.pop("prettyPrint", "false")
61+
self.assertEqual(pretty_print, "false")
62+
self.assertEqual(parms, {})
63+
64+
def test_build_api_url_w_extra_query_params(self):
65+
from six.moves.urllib.parse import parse_qsl
66+
from six.moves.urllib.parse import urlsplit
67+
68+
conn = self._make_one(object())
69+
uri = conn.build_api_url("/foo", {"bar": "baz"})
70+
scheme, netloc, path, qs, _ = urlsplit(uri)
71+
self.assertEqual("%s://%s" % (scheme, netloc), conn.API_BASE_URL)
72+
self.assertEqual(path, "/".join(["", conn.API_VERSION, "foo"]))
73+
parms = dict(parse_qsl(qs))
74+
self.assertEqual(parms["bar"], "baz")
4075

4176
def test_extra_headers(self):
4277
import requests

0 commit comments

Comments
 (0)