Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions googlemaps/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def static_map(client, size,

:param style: defines a custom style to alter the presentation of
a specific feature (roads, parks, and other features) of the map.
:type style: list of dict
:type style: dict or list of dict

:rtype: iterator containing the raw image data, which typically can be
used to save an image file locally. For example:
Expand Down Expand Up @@ -236,7 +236,7 @@ def static_map(client, size,
params["visible"] = convert.location_list(visible)

if style:
params["style"] = convert.components(style)
params["style"] = [convert.components(s) for s in convert.as_list(style)]

response = client._request(
"/maps/api/staticmap",
Expand Down
67 changes: 67 additions & 0 deletions tests/test_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,70 @@ def test_download(self):
self.client.static_map(
size=(400, 400), center=(63.259591, -144.667969), zoom=6, maptype="test"
)

@responses.activate
def test_static_map_style_list(self):
url = "https://maps.googleapis.com/maps/api/staticmap"
responses.add(responses.GET, url, status=200)

styles = [
{"feature": "poi.business", "visibility": "off"},
{"feature": "poi.schools", "visibility": "off"},
{"feature": "poi.restaurants", "visibility": "on"},
]

response = self.client.static_map(
size=(400, 400),
center=(63.259591, -144.667969),
zoom=6,
style=styles,
)

self.assertTrue(isinstance(response, GeneratorType))
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"%s?center=63.259591%%2C-144.667969&size=400x400&"
"style=feature%%3Apoi.business%%7Cvisibility%%3Aoff&"
"style=feature%%3Apoi.schools%%7Cvisibility%%3Aoff&"
"style=feature%%3Apoi.restaurants%%7Cvisibility%%3Aon&"
"zoom=6&key=%s" % (url, self.key),
responses.calls[0].request.url,
)

@responses.activate
def test_static_map_style_dict(self):
url = "https://maps.googleapis.com/maps/api/staticmap"
responses.add(responses.GET, url, status=200)

response = self.client.static_map(
size=(400, 400),
center=(63.259591, -144.667969),
zoom=6,
style={"feature": "poi.business", "visibility": "off"},
)

self.assertTrue(isinstance(response, GeneratorType))
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"%s?center=63.259591%%2C-144.667969&size=400x400&"
"style=feature%%3Apoi.business%%7Cvisibility%%3Aoff&"
"zoom=6&key=%s" % (url, self.key),
responses.calls[0].request.url,
)

def test_static_map_style_invalid(self):
with self.assertRaises(TypeError):
self.client.static_map(
size=(400, 400),
center=(63.259591, -144.667969),
zoom=6,
style="feature:poi.business|visibility:off",
)

with self.assertRaises(TypeError):
self.client.static_map(
size=(400, 400),
center=(63.259591, -144.667969),
zoom=6,
style=[{"feature": "poi.business"}, "invalid"],
)