Skip to content

Commit 409adf3

Browse files
committed
Removed check of variable on dict.
1 parent a02a730 commit 409adf3

File tree

5 files changed

+200
-7
lines changed

5 files changed

+200
-7
lines changed

flask_googlemaps/__init__.py

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

117-
def add_marker(self, lat=None, lng=None, **kwargs):
118-
if lat is not None:
119-
kwargs["lat"] = lat
120-
if lng is not None:
121-
kwargs["lng"] = lng
117+
def add_marker(self, **kwargs):
122118
if "lat" not in kwargs or "lng" not in kwargs:
123119
raise AttributeError("lat and lng required")
120+
124121
self.markers.append(kwargs)
125122

126123
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_it_should_raise_a_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: 153 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ flake8 = "^3.7.9"
3333
black = "^19.10b0"
3434
gitchangelog = "^3.0.4"
3535
pylint = "^2.4.4"
36+
pytest = "5.3.5"
3637

3738
[build-system]
3839
requires = ["poetry>=0.12"]

0 commit comments

Comments
 (0)