Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_no_retry_over_query_limit(self):
responses.add(responses.GET,
"https://maps.googleapis.com/foo",
body='{"status":"OVER_QUERY_LIMIT"}',
status=200,
content_type="application/json")
client = googlemaps.Client(key="AIzaasdf",
retry_over_query_limit=False)
with self.assertRaises(googlemaps.exceptions.ApiError):
client._request("/foo", {})
self.assertEqual(1, len(responses.calls))
def test_clientid_not_accepted(self):
client = googlemaps.Client(client_id="asdf", client_secret="asdf")
with self.assertRaises(ValueError):
client.speed_limits("foo")
def test_auth_url_with_channel(self):
client = googlemaps.Client(key="AIzaasdf",
client_id="foo",
client_secret="a2V5",
channel="MyChannel_1")
# Check ordering of parameters + signature.
auth_url = client._generate_auth_url("/test",
{"param": "param"},
accepts_clientid=True)
self.assertEqual(auth_url, "/test?param=param"
"&channel=MyChannel_1"
"&client=foo"
"&signature=OH18GuQto_mEpxj99UimKskvo4k=")
# Check if added to requests to API with accepts_clientid=False
auth_url = client._generate_auth_url("/test",
{"param": "param"},
def setUp(self):
self.key = "AIzaasdf"
self.client = googlemaps.Client(self.key)
def test_latlng(self):
expected = "1,2"
ll = {"lat": 1, "lng": 2}
self.assertEqual(expected, convert.latlng(ll))
ll = [1, 2]
self.assertEqual(expected, convert.latlng(ll))
ll = (1, 2)
self.assertEqual(expected, convert.latlng(ll))
self.assertEqual(expected, convert.latlng(expected))
with self.assertRaises(TypeError):
convert.latlng(1)
self.assertEqual("country:US", convert.components(c))
c = {"country": "US", "foo": 1}
self.assertEqual("country:US|foo:1", convert.components(c))
c = {"country": ["US", "AU"], "foo": 1}
self.assertEqual("country:AU|country:US|foo:1", convert.components(c))
with self.assertRaises(TypeError):
convert.components("test")
with self.assertRaises(TypeError):
convert.components(1)
with self.assertRaises(TypeError):
convert.components(("c", "b"))
def test_latlng(self):
expected = "1,2"
ll = {"lat": 1, "lng": 2}
self.assertEqual(expected, convert.latlng(ll))
ll = [1, 2]
self.assertEqual(expected, convert.latlng(ll))
ll = (1, 2)
self.assertEqual(expected, convert.latlng(ll))
self.assertEqual(expected, convert.latlng(expected))
with self.assertRaises(TypeError):
convert.latlng(1)
def test_location_list(self):
expected = "1,2|1,2"
ll = [{"lat": 1, "lng": 2}, {"lat": 1, "lng": 2}]
self.assertEqual(expected, convert.location_list(ll))
ll = [[1, 2], [1, 2]]
self.assertEqual(expected, convert.location_list(ll))
ll = [(1, 2), [1, 2]]
self.assertEqual(expected, convert.location_list(ll))
self.assertEqual(expected, convert.location_list(expected))
with self.assertRaises(TypeError):
convert.latlng(1)
def test_transit_without_time(self):
# With mode of transit, we need a departure_time or an
# arrival_time specified
with self.assertRaises(googlemaps.exceptions.ApiError):
self.client.directions("Sydney Town Hall", "Parramatta, NSW",
mode="transit")
def test_elevation_along_path_single(self):
with self.assertRaises(googlemaps.exceptions.ApiError):
results = self.client.elevation_along_path(
[(40.714728, -73.998672)], 5)