diff --git a/core/utils.py b/core/utils.py index b6800a327..ef589f72f 100644 --- a/core/utils.py +++ b/core/utils.py @@ -15,7 +15,9 @@ def get_coordinates_for_city(city, country): try: data = req.json()[0] - return f'{data["lat"]}, {data["lon"]}' + formatted_lat = "{:.7f}".format(float(data["lat"])) + formatted_lon = "{:.7f}".format(float(data["lon"])) + return f"{formatted_lat}, {formatted_lon}" except (IndexError, KeyError): return None diff --git a/tests/core/test_utils.py b/tests/core/test_utils.py index 1036e60fa..c52852195 100644 --- a/tests/core/test_utils.py +++ b/tests/core/test_utils.py @@ -24,7 +24,9 @@ def test_get_coordinates_for_city(mock_get): "q": "London, UK", }, ) - assert result == "1.23, 4.56" + expected_lat = "{:.7f}".format(float("1.23")) + expected_lon = "{:.7f}".format(float("4.56")) + assert result == f"{expected_lat}, {expected_lon}" @mock.patch("requests.get")