Skip to content

Commit 7253932

Browse files
authored
Merge pull request #107 from Bernardoow/removing_check_from_add_marker_function
Removed check of variable on dict.
2 parents 40b271d + 169f6f1 commit 7253932

File tree

4 files changed

+204
-14
lines changed

4 files changed

+204
-14
lines changed

flask_googlemaps/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,10 @@ def build_marker_dict(self, marker, icon=None):
129129
marker_dict["icon"] = marker[3]
130130
return marker_dict
131131

132-
def add_marker(self, lat=None, lng=None, **kwargs):
133-
if lat is not None:
134-
kwargs["lat"] = lat
135-
if lng is not None:
136-
kwargs["lng"] = lng
132+
def add_marker(self, **kwargs):
137133
if "lat" not in kwargs or "lng" not in kwargs:
138134
raise AttributeError("lat and lng required")
135+
139136
self.markers.append(kwargs)
140137

141138
def build_rectangles(self, rectangles):

flask_googlemaps/tests/__init__.py

Whitespace-only changes.

flask_googlemaps/tests/test_map.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pytest
2+
from flask_googlemaps import Map
3+
4+
5+
class TestFunctionAddMarker:
6+
"""
7+
This Class is to test function add marker.
8+
"""
9+
10+
google_map = None
11+
12+
@pytest.fixture(autouse=True)
13+
def config_test(self):
14+
self.google_map = Map(
15+
identifier="view-side", # for DOM element
16+
varname="mymap", # for JS object name
17+
lat=37.4419,
18+
lng=-122.1419,
19+
)
20+
21+
@pytest.mark.parametrize("marker", [{}, {"lat": 1}, {"lng": 1}])
22+
def test_should_raise_attribute_error_when_is_missing_params(self, marker):
23+
"""
24+
Test check the validation of marker.
25+
This should raise expetion when the lat, lng or both are missing.
26+
"""
27+
with pytest.raises(AttributeError) as error:
28+
self.google_map.add_marker(**marker)
29+
30+
assert str(error.value) == "lat and lng required"
31+
32+
@pytest.mark.parametrize(
33+
"marker",
34+
[
35+
{"lat": 10, "lng": 20, "icon": "red"},
36+
{"lat": 10, "lng": 20, "icon": "red", "infobox": "teste"},
37+
],
38+
)
39+
def test_it_should_add_to_marker_list_a_new_valid_marker(self, marker):
40+
"""
41+
Test check if add_marker is adding a new market to markers_list.
42+
"""
43+
self.google_map.add_marker(**marker)
44+
assert len(self.google_map.markers) == 1

poetry.lock

Lines changed: 158 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)