Skip to content

Commit

Permalink
fixed blank field string reversing
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-the-shark committed May 11, 2020
1 parent ead5f5b commit 539ccf7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mapbox_location_field/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@


def reverse_tuple_string(location_string):
if location_string == "":
return location_string
args = location_string.split(",")
return args[1] + "," + args[0]

Expand Down
6 changes: 5 additions & 1 deletion mapbox_location_field/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib.gis.geos import Point
from django.core.exceptions import ValidationError
from django.test import TestCase

from mapbox_location_field.forms import LocationField, AddressAutoHiddenField, reverse_tuple_string
Expand All @@ -25,6 +24,7 @@ def test_clean(self):
field = LocationField()
self.assertEqual("11,12", field.clean("12, 11"))


class SpatialLocationFieldTests(TestCase):

def test_widget(self):
Expand Down Expand Up @@ -67,6 +67,10 @@ def test_to_python(self):
def test_reverse_tuple_string(self):
self.assertEqual(reverse_tuple_string("1,2"), "2,1")

def test_empty_reverse_tuple_string(self):
self.assertEqual(reverse_tuple_string(""), "")


class AddressAutoHiddenFieldTests(TestCase):
def test_widget(self):
field = AddressAutoHiddenField()
Expand Down

0 comments on commit 539ccf7

Please sign in to comment.