From a9e942a48b349f9c6a5d24a6090f23b7a81f8ca3 Mon Sep 17 00:00:00 2001 From: nygeog Date: Thu, 2 Feb 2017 10:23:09 -0500 Subject: [PATCH 1/3] remove the search_type if its address from the params sent to mapzen remove the search_type if its address from the params sent to mapzen --- .../cartodb_services/cartodb_services/mapzen/geocoder.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/lib/python/cartodb_services/cartodb_services/mapzen/geocoder.py b/server/lib/python/cartodb_services/cartodb_services/mapzen/geocoder.py index 1209388..828554c 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapzen/geocoder.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapzen/geocoder.py @@ -25,6 +25,10 @@ class MapzenGeocoder(Traceable): @qps_retry(qps=20) def geocode(self, searchtext, city=None, state_province=None, country=None, search_type=None): + + if search_type.lower() == 'address': #remove the search_type if its address from the params sent to mapzen + search_type = None + request_params = self._build_requests_parameters(searchtext, city, state_province, country, search_type) From 82a7477d37a5022f98719fcb83a9342a0dc84897 Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Wed, 8 Mar 2017 10:14:37 +0100 Subject: [PATCH 2/3] Beautify code --- .../cartodb_services/cartodb_services/mapzen/geocoder.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/mapzen/geocoder.py b/server/lib/python/cartodb_services/cartodb_services/mapzen/geocoder.py index 828554c..0d56b38 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapzen/geocoder.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapzen/geocoder.py @@ -25,8 +25,9 @@ class MapzenGeocoder(Traceable): @qps_retry(qps=20) def geocode(self, searchtext, city=None, state_province=None, country=None, search_type=None): - - if search_type.lower() == 'address': #remove the search_type if its address from the params sent to mapzen + + # Remove the search_type if its address from the params sent to mapzen + if search_type.lower() == 'address': search_type = None request_params = self._build_requests_parameters(searchtext, city, From ffdb6524dae08d4aa2f3a0d5ee01303ebf3bc4d3 Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Wed, 8 Mar 2017 10:19:29 +0100 Subject: [PATCH 3/3] Fix bug: search_type can be None Found via unit test: ```sh $ nosetests -x test/ ....................................................................................E ====================================================================== ERROR: test_geocode_address_with_valid_params (test.test_mapzengeocoder.MapzenGeocoderTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/requests_mock/mocker.py", line 177, in inner return func(*args, **kwargs) File "/home/ubuntu/src/dataservices-api/server/lib/python/cartodb_services/test/test_mapzengeocoder.py", line 100, in test_geocode_address_with_valid_params country='ESP') File "/home/ubuntu/src/dataservices-api/server/lib/python/cartodb_services/cartodb_services/mapzen/qps.py", line 28, in wrapped_function return QPSService(retry_timeout=timeout, queries_per_second=qps).call(original_function, *args, **kwargs) File "/home/ubuntu/src/dataservices-api/server/lib/python/cartodb_services/cartodb_services/mapzen/qps.py", line 53, in call raise e AttributeError: 'NoneType' object has no attribute 'lower' ---------------------------------------------------------------------- Ran 85 tests in 0.140s FAILED (errors=1) ``` --- .../python/cartodb_services/cartodb_services/mapzen/geocoder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/mapzen/geocoder.py b/server/lib/python/cartodb_services/cartodb_services/mapzen/geocoder.py index 0d56b38..742acc0 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapzen/geocoder.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapzen/geocoder.py @@ -27,7 +27,7 @@ class MapzenGeocoder(Traceable): country=None, search_type=None): # Remove the search_type if its address from the params sent to mapzen - if search_type.lower() == 'address': + if search_type and search_type.lower() == 'address': search_type = None request_params = self._build_requests_parameters(searchtext, city,