Compare commits

...

14 Commits

Author SHA1 Message Date
Mario de Frutos
6f508b550d Merge pull request #441 from CartoDB/development
Release python library 0.16.3
2018-01-31 17:06:00 +01:00
Mario de Frutos
1462f87d97 Merge pull request #440 from CartoDB/439_filter_empty_requests_mapbox_geocoder
Improve empty requests treatment in geocoders
2018-01-31 16:31:11 +01:00
Mario de Frutos
6ae8aa45fd CR changes 2018-01-31 16:13:20 +01:00
Mario de Frutos
02cb4862f9 Update NEWS.md 2018-01-31 13:18:09 +01:00
Mario de Frutos
07f00cc0ae Added tests for the client/channel part of google 2018-01-31 13:17:36 +01:00
Mario de Frutos
544e0fa763 Going green with non empty request strings 2018-01-31 12:25:35 +01:00
Mario de Frutos
2bbd6bac91 Going red with non empty request string 2018-01-31 12:25:18 +01:00
Mario de Frutos
2f8dbbb5dc Dont raise exception when empty params passed to HERE geocoder 2018-01-31 12:16:13 +01:00
Mario de Frutos
3484cce88b Update NEWS.md 2018-01-31 12:13:02 +01:00
Mario de Frutos
56c90cc541 Bump version to 0.16.3 2018-01-31 12:12:52 +01:00
Mario de Frutos
3583cc6f47 Going green with empty requests that leads to 404 responses 2018-01-31 12:11:25 +01:00
Mario de Frutos
850dc09a4f Going green with empty responses 2018-01-31 12:11:25 +01:00
Mario de Frutos
876bae6b56 Going red with bad request parameters 2018-01-31 12:11:25 +01:00
Mario de Frutos
8f30359cc7 Added rate limits topic to the README 2018-01-30 15:02:40 +01:00
9 changed files with 75 additions and 17 deletions

View File

@@ -1,3 +1,11 @@
January 31th, 2018
==================
* Version `0.16.3` of the python library
* Fix for Mapbox geocoder to handle empty requests and empty responses
* Remove raising an exception when non parameters are passed to the HERE geocoder
* Fix for HERE geocoder with non empty requests
* Added more coverage to the google geocoder credentials parse logic
January 29th, 2018 January 29th, 2018
================== ==================
* Version `0.30.1` of server side * Version `0.30.1` of server side

View File

@@ -296,3 +296,6 @@ ALTER ROLE "<USER_ROLE>" SET search_path="$user", public, cartodb, cdb_dataservi
#### Option 2 (from builder) #### Option 2 (from builder)
See [the **Configuring Dataservices** documentation](http://cartodb.readthedocs.io/en/latest/operations/configure_data_services.html) See [the **Configuring Dataservices** documentation](http://cartodb.readthedocs.io/en/latest/operations/configure_data_services.html)
### Rate limits
See [docs](https://github.com/CartoDB/dataservices-api/blob/master/doc/rate_limits.md)

View File

@@ -67,10 +67,10 @@ class HereMapsGeocoder(Traceable):
def geocode(self, **kwargs): def geocode(self, **kwargs):
params = {} params = {}
for key, value in kwargs.iteritems(): for key, value in kwargs.iteritems():
if value: if value and value.strip():
params[key] = value params[key] = value
if not params: if not params:
raise NoGeocodingParams() return []
return self._execute_geocode(params) return self._execute_geocode(params)
def _execute_geocode(self, params): def _execute_geocode(self, params):

View File

@@ -39,7 +39,7 @@ class MapboxGeocoder(Traceable):
def _parse_geocoder_response(self, response): def _parse_geocoder_response(self, response):
json_response = json.loads(response) json_response = json.loads(response)
if json_response: if json_response and json_response[ENTRY_FEATURES]:
feature = json_response[ENTRY_FEATURES][0] feature = json_response[ENTRY_FEATURES][0]
return self._extract_lng_lat_from_feature(feature) return self._extract_lng_lat_from_feature(feature)
@@ -60,11 +60,14 @@ class MapboxGeocoder(Traceable):
@qps_retry(qps=10) @qps_retry(qps=10)
def geocode(self, searchtext, city=None, state_province=None, def geocode(self, searchtext, city=None, state_province=None,
country=None): country=None):
address = [searchtext] if searchtext and searchtext.strip():
if city: address = [searchtext]
address.append(city) if city:
if state_province: address.append(city)
address.append(state_province) if state_province:
address.append(state_province)
else:
return []
country = [country] if country else None country = [country] if country else None

View File

@@ -10,7 +10,7 @@ from setuptools import setup, find_packages
setup( setup(
name='cartodb_services', name='cartodb_services',
version='0.16.2', version='0.16.3',
description='CartoDB Services API Python Library', description='CartoDB Services API Python Library',

View File

@@ -18,10 +18,10 @@ class GoogleMapsClientFactoryTestCase(unittest.TestCase):
GoogleMapsClientFactory.clients = {} GoogleMapsClientFactory.clients = {}
def test_consecutive_calls_with_same_params_return_same_client(self): def test_consecutive_calls_with_same_params_return_same_client(self):
id = 'any_id' client_id = 'any_id'
key = base64.b64encode('any_key') key = base64.b64encode('any_key')
client1 = GoogleMapsClientFactory.get(id, key) client1 = GoogleMapsClientFactory.get(client_id, key)
client2 = GoogleMapsClientFactory.get(id, key) client2 = GoogleMapsClientFactory.get(client_id, key)
self.assertEqual(client1, client2) self.assertEqual(client1, client2)
def test_consecutive_calls_with_different_key_return_different_clients(self): def test_consecutive_calls_with_different_key_return_different_clients(self):
@@ -29,11 +29,11 @@ class GoogleMapsClientFactoryTestCase(unittest.TestCase):
This requirement is important for security reasons as well as not to This requirement is important for security reasons as well as not to
cache a wrong key accidentally. cache a wrong key accidentally.
""" """
id = 'any_id' client_id = 'any_id'
key1 = base64.b64encode('any_key') key1 = base64.b64encode('any_key')
key2 = base64.b64encode('another_key') key2 = base64.b64encode('another_key')
client1 = GoogleMapsClientFactory.get(id, key1) client1 = GoogleMapsClientFactory.get(client_id, key1)
client2 = GoogleMapsClientFactory.get(id, key2) client2 = GoogleMapsClientFactory.get(client_id, key2)
self.assertNotEqual(client1, client2) self.assertNotEqual(client1, client2)
def test_consecutive_calls_with_different_ids_return_different_clients(self): def test_consecutive_calls_with_different_ids_return_different_clients(self):
@@ -59,3 +59,11 @@ class GoogleMapsClientFactoryTestCase(unittest.TestCase):
def test_credentials_with_underscores_can_be_valid(self): def test_credentials_with_underscores_can_be_valid(self):
client = GoogleMapsClientFactory.get('yet_another_dummy_client_id', 'Ola_k_ase___') client = GoogleMapsClientFactory.get('yet_another_dummy_client_id', 'Ola_k_ase___')
self.assertIsInstance(client, googlemaps.Client) self.assertIsInstance(client, googlemaps.Client)
def test_invalid_credentials(self):
with self.assertRaises(InvalidGoogleCredentials):
GoogleMapsClientFactory.get('dummy_client_id', 'lalala')
def test_credentials_with_channel(self):
client = GoogleMapsClientFactory.get('yet_another_dummy_client_id', 'Ola_k_ase___', 'channel')
self.assertIsInstance(client, googlemaps.Client)

View File

@@ -118,3 +118,18 @@ class GoogleGeocoderTestCase(unittest.TestCase):
searchtext='Calle Eloy Gonzalo 27', searchtext='Calle Eloy Gonzalo 27',
city='Madrid', city='Madrid',
country='España') country='España')
def test_client_data_extraction(self, req_mock):
client_id, channel = self.geocoder.parse_client_id('dummy_client_id')
self.assertEqual(client_id, 'dummy_client_id')
self.assertEqual(channel, None)
def test_client_data_extraction_with_client_parameter(self, req_mock):
client_id, channel = self.geocoder.parse_client_id('client=gme-test')
self.assertEqual(client_id, 'gme-test')
self.assertEqual(channel, None)
def test_client_data_extraction_with_client_and_channel_parameter(self, req_mock):
client_id, channel = self.geocoder.parse_client_id('client=gme-test&channel=testchannel')
self.assertEqual(client_id, 'gme-test')
self.assertEqual(channel, 'testchannel')

View File

@@ -128,8 +128,14 @@ class HereMapsGeocoderTestCase(unittest.TestCase):
def test_geocode_address_with_no_params(self, req_mock): def test_geocode_address_with_no_params(self, req_mock):
req_mock.register_uri('GET', HereMapsGeocoder.PRODUCTION_GEOCODE_JSON_URL, req_mock.register_uri('GET', HereMapsGeocoder.PRODUCTION_GEOCODE_JSON_URL,
text=self.GOOD_RESPONSE) text=self.GOOD_RESPONSE)
with self.assertRaises(NoGeocodingParams): result = self.geocoder.geocode()
self.geocoder.geocode() self.assertEqual(result, [])
def test_geocode_address_with_non_empty_string_params(self, req_mock):
req_mock.register_uri('GET', HereMapsGeocoder.PRODUCTION_GEOCODE_JSON_URL,
text=self.GOOD_RESPONSE)
result = self.geocoder.geocode(searchtext=" ", city=None, state=" ", country=" ")
self.assertEqual(result, [])
def test_geocode_address_empty_response(self, req_mock): def test_geocode_address_empty_response(self, req_mock):
req_mock.register_uri('GET', HereMapsGeocoder.PRODUCTION_GEOCODE_JSON_URL, req_mock.register_uri('GET', HereMapsGeocoder.PRODUCTION_GEOCODE_JSON_URL,

View File

@@ -34,3 +34,18 @@ class MapboxGeocoderTestCase(unittest.TestCase):
place = self.geocoder.geocode(searchtext='New York', country='us') place = self.geocoder.geocode(searchtext='New York', country='us')
assert place assert place
def test_empty_request(self):
place = self.geocoder.geocode(searchtext='', country=None, city=None, state_province=None)
assert place == []
def test_empty_search_text_request(self):
place = self.geocoder.geocode(searchtext=' ', country='us', city=None, state_province="")
assert place == []
def test_unknown_place_request(self):
place = self.geocoder.geocode(searchtext='[unknown]', country='ch', state_province=None, city=None)
assert place == []