Test refactor and Here serial batch
This commit is contained in:
parent
18e2349713
commit
fc610313bf
@ -68,9 +68,10 @@ class HereMapsGeocoder(Traceable, StreetPointBulkGeocoder):
|
|||||||
def _bulk_geocode(self, searches):
|
def _bulk_geocode(self, searches):
|
||||||
results = []
|
results = []
|
||||||
for search in searches:
|
for search in searches:
|
||||||
result = ()
|
(search_id, address, city, state, country) = search
|
||||||
|
coordinates = self.geocode(searchtext=address, city=city, state=state, country=country)
|
||||||
|
results.append((search_id, coordinates, []))
|
||||||
return results
|
return results
|
||||||
coordinates = geocoder.geocode(searchtext=searchtext, city=city, state=state_province, country=country)
|
|
||||||
|
|
||||||
def geocode(self, **kwargs):
|
def geocode(self, **kwargs):
|
||||||
params = {}
|
params = {}
|
||||||
|
@ -40,6 +40,52 @@ class TestStreetFunctions(TestStreetFunctionsSetUp):
|
|||||||
|
|
||||||
|
|
||||||
class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
|
class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
|
||||||
|
provider = None
|
||||||
|
fixture_points = None
|
||||||
|
|
||||||
|
GOOGLE_POINTS = {
|
||||||
|
'Plaza Mayor, Valladolid': [-4.728252, 41.6517025],
|
||||||
|
'Paseo Zorrilla, Valladolid': [-4.7404453, 41.6314339],
|
||||||
|
'1900 amphitheatre parkway': [-122.0875324, 37.4227968],
|
||||||
|
'1901 amphitheatre parkway': [-122.0885504, 37.4238657],
|
||||||
|
'1902 amphitheatre parkway': [-122.0876674, 37.4235729],
|
||||||
|
'Valladolid': [-4.7245321, 41.652251],
|
||||||
|
'Valladolid, Spain': [-4.7245321, 41.652251],
|
||||||
|
'Valladolid, Mexico': [-88.2022488, 20.68964],
|
||||||
|
'Madrid': [-3.7037902, 40.4167754],
|
||||||
|
'Logroño, Spain': [-2.4449852, 42.4627195],
|
||||||
|
'Logroño, Argentina': [-61.6961807, -29.5031057]
|
||||||
|
}
|
||||||
|
|
||||||
|
HERE_POINTS = {
|
||||||
|
'Plaza Mayor, Valladolid': [-4.72979, 41.65258],
|
||||||
|
'Paseo Zorrilla, Valladolid': [-4.73869, 41.63817],
|
||||||
|
'1900 amphitheatre parkway': [-122.0879468, 37.4234763],
|
||||||
|
'1901 amphitheatre parkway': [-122.0879253, 37.4238725],
|
||||||
|
'1902 amphitheatre parkway': [-122.0879531, 37.4234775],
|
||||||
|
'Valladolid': [-4.73214, 41.6542],
|
||||||
|
'Valladolid, Spain': [-4.73214, 41.6542],
|
||||||
|
'Valladolid, Mexico': [-88.20117, 20.69021],
|
||||||
|
'Madrid': [-3.70578, 40.42028],
|
||||||
|
'Logroño, Spain': [-2.45194, 42.46592],
|
||||||
|
'Logroño, Argentina': [-61.69604, -29.50425]
|
||||||
|
}
|
||||||
|
|
||||||
|
FIXTURE_POINTS = {
|
||||||
|
'google': GOOGLE_POINTS,
|
||||||
|
'heremaps': HERE_POINTS
|
||||||
|
}
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
TestStreetFunctionsSetUp.setUp(self)
|
||||||
|
|
||||||
|
if not self.fixture_points:
|
||||||
|
query = "select provider from " \
|
||||||
|
"cdb_dataservices_client.cdb_service_quota_info() " \
|
||||||
|
"where service = 'hires_geocoder'"
|
||||||
|
response = self._run_authenticated(query)
|
||||||
|
provider = response['rows'][0]['provider']
|
||||||
|
self.fixture_points = self.FIXTURE_POINTS[provider]
|
||||||
|
|
||||||
def test_full_spec(self):
|
def test_full_spec(self):
|
||||||
query = "select cartodb_id, st_x(the_geom), st_y(the_geom) " \
|
query = "select cartodb_id, st_x(the_geom), st_y(the_geom) " \
|
||||||
@ -54,11 +100,11 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
|
|||||||
", 'street', 'city', 'state', 'country')"
|
", 'street', 'city', 'state', 'country')"
|
||||||
response = self._run_authenticated(query)
|
response = self._run_authenticated(query)
|
||||||
|
|
||||||
assert_equal(response['total_rows'], 2)
|
points_by_cartodb_id = {
|
||||||
|
1: self.fixture_points['Plaza Mayor, Valladolid'],
|
||||||
row_by_cartodb_id = self._row_by_cartodb_id(response)
|
2: self.fixture_points['Paseo Zorrilla, Valladolid']
|
||||||
self._assert_x_y(row_by_cartodb_id[1], -4.728252, 41.6517025);
|
}
|
||||||
self._assert_x_y(row_by_cartodb_id[2], -4.7404453, 41.6314339)
|
assert_equal(self._x_y_by_cartodb_id(response), points_by_cartodb_id)
|
||||||
|
|
||||||
def test_empty_columns(self):
|
def test_empty_columns(self):
|
||||||
query = "select *, st_x(the_geom), st_y(the_geom) " \
|
query = "select *, st_x(the_geom), st_y(the_geom) " \
|
||||||
@ -69,10 +115,8 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
|
|||||||
"'address', '''''', '''''', '''''')"
|
"'address', '''''', '''''', '''''')"
|
||||||
response = self._run_authenticated(query)
|
response = self._run_authenticated(query)
|
||||||
|
|
||||||
assert_equal(response['total_rows'], 1)
|
assert_equal(self._x_y_by_cartodb_id(response)[1],
|
||||||
|
self.fixture_points['1901 amphitheatre parkway'])
|
||||||
row_by_cartodb_id = self._row_by_cartodb_id(response)
|
|
||||||
self._assert_x_y(row_by_cartodb_id[1], -122.0885504, 37.4238657)
|
|
||||||
|
|
||||||
def test_null_columns(self):
|
def test_null_columns(self):
|
||||||
query = "select *, st_x(the_geom), st_y(the_geom) " \
|
query = "select *, st_x(the_geom), st_y(the_geom) " \
|
||||||
@ -83,10 +127,8 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
|
|||||||
"'address')"
|
"'address')"
|
||||||
response = self._run_authenticated(query)
|
response = self._run_authenticated(query)
|
||||||
|
|
||||||
assert_equal(response['total_rows'], 1)
|
assert_equal(self._x_y_by_cartodb_id(response)[1],
|
||||||
|
self.fixture_points['1901 amphitheatre parkway'])
|
||||||
row_by_cartodb_id = self._row_by_cartodb_id(response)
|
|
||||||
self._assert_x_y(row_by_cartodb_id[1], -122.0885504, 37.4238657)
|
|
||||||
|
|
||||||
def test_batching(self):
|
def test_batching(self):
|
||||||
query = "select *, st_x(the_geom), st_y(the_geom) " \
|
query = "select *, st_x(the_geom), st_y(the_geom) " \
|
||||||
@ -99,12 +141,12 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
|
|||||||
"'address', null, null, null, 2)"
|
"'address', null, null, null, 2)"
|
||||||
response = self._run_authenticated(query)
|
response = self._run_authenticated(query)
|
||||||
|
|
||||||
assert_equal(response['total_rows'], 3)
|
points_by_cartodb_id = {
|
||||||
|
1: self.fixture_points['1900 amphitheatre parkway'],
|
||||||
row_by_cartodb_id = self._row_by_cartodb_id(response)
|
2: self.fixture_points['1901 amphitheatre parkway'],
|
||||||
self._assert_x_y(row_by_cartodb_id[1], -122.0875324, 37.4227968)
|
3: self.fixture_points['1902 amphitheatre parkway'],
|
||||||
self._assert_x_y(row_by_cartodb_id[2], -122.0885504, 37.4238657)
|
}
|
||||||
self._assert_x_y(row_by_cartodb_id[3], -122.0876674, 37.4235729)
|
assert_equal(self._x_y_by_cartodb_id(response), points_by_cartodb_id)
|
||||||
|
|
||||||
def test_city_column_geocoding(self):
|
def test_city_column_geocoding(self):
|
||||||
query = "select *, st_x(the_geom), st_y(the_geom) " \
|
query = "select *, st_x(the_geom), st_y(the_geom) " \
|
||||||
@ -118,9 +160,11 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
|
|||||||
|
|
||||||
assert_equal(response['total_rows'], 2)
|
assert_equal(response['total_rows'], 2)
|
||||||
|
|
||||||
row_by_cartodb_id = self._row_by_cartodb_id(response)
|
points_by_cartodb_id = {
|
||||||
self._assert_x_y(row_by_cartodb_id[1], -4.7245321, 41.652251)
|
1: self.fixture_points['Valladolid'],
|
||||||
self._assert_x_y(row_by_cartodb_id[2], -3.7037902, 40.4167754)
|
2: self.fixture_points['Madrid']
|
||||||
|
}
|
||||||
|
assert_equal(self._x_y_by_cartodb_id(response), points_by_cartodb_id)
|
||||||
|
|
||||||
def test_free_text_geocoding(self):
|
def test_free_text_geocoding(self):
|
||||||
query = "select *, st_x(the_geom), st_y(the_geom) " \
|
query = "select *, st_x(the_geom), st_y(the_geom) " \
|
||||||
@ -132,10 +176,8 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
|
|||||||
"'''Logroño, La Rioja, Spain''')"
|
"'''Logroño, La Rioja, Spain''')"
|
||||||
response = self._run_authenticated(query)
|
response = self._run_authenticated(query)
|
||||||
|
|
||||||
assert_equal(response['total_rows'], 1)
|
assert_equal(self._x_y_by_cartodb_id(response)[1],
|
||||||
|
self.fixture_points['Logroño, Spain'])
|
||||||
row_by_cartodb_id = self._row_by_cartodb_id(response)
|
|
||||||
self._assert_x_y(row_by_cartodb_id[1], -2.4449852, 42.4627195)
|
|
||||||
|
|
||||||
def test_templating_geocoding(self):
|
def test_templating_geocoding(self):
|
||||||
query = "SELECT cartodb_id, st_x(the_geom), st_y(the_geom) from " \
|
query = "SELECT cartodb_id, st_x(the_geom), st_y(the_geom) from " \
|
||||||
@ -149,11 +191,11 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
|
|||||||
"'city || '', '' || ''Argentina''')"
|
"'city || '', '' || ''Argentina''')"
|
||||||
response = self._run_authenticated(query)
|
response = self._run_authenticated(query)
|
||||||
|
|
||||||
assert_equal(response['total_rows'], 2)
|
points_by_cartodb_id = {
|
||||||
|
1: self.fixture_points['Logroño, Spain'],
|
||||||
row_by_cartodb_id = self._row_by_cartodb_id(response)
|
2: self.fixture_points['Logroño, Argentina']
|
||||||
self._assert_x_y(row_by_cartodb_id[1], -2.4449852, 42.4627195)
|
}
|
||||||
self._assert_x_y(row_by_cartodb_id[2], -61.6961807, -29.5031057)
|
assert_equal(self._x_y_by_cartodb_id(response), points_by_cartodb_id)
|
||||||
|
|
||||||
def test_template_with_two_columns_geocoding(self):
|
def test_template_with_two_columns_geocoding(self):
|
||||||
query = "SELECT cartodb_id, st_x(the_geom), st_y(the_geom) from " \
|
query = "SELECT cartodb_id, st_x(the_geom), st_y(the_geom) from " \
|
||||||
@ -165,14 +207,12 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
|
|||||||
" ') _x'," \
|
" ') _x'," \
|
||||||
"'city || '', '' || country')"
|
"'city || '', '' || country')"
|
||||||
response = self._run_authenticated(query)
|
response = self._run_authenticated(query)
|
||||||
# from nose.tools import set_trace; set_trace()
|
|
||||||
|
|
||||||
assert_equal(response['total_rows'], 2)
|
|
||||||
|
|
||||||
row_by_cartodb_id = self._row_by_cartodb_id(response)
|
|
||||||
self._assert_x_y(row_by_cartodb_id[1], -88.2022488, 20.68964)
|
|
||||||
self._assert_x_y(row_by_cartodb_id[2], -4.7245321, 41.652251)
|
|
||||||
|
|
||||||
|
points_by_cartodb_id = {
|
||||||
|
1: self.fixture_points['Valladolid, Mexico'],
|
||||||
|
2: self.fixture_points['Valladolid, Spain']
|
||||||
|
}
|
||||||
|
assert_equal(self._x_y_by_cartodb_id(response), points_by_cartodb_id)
|
||||||
|
|
||||||
def _run_authenticated(self, query):
|
def _run_authenticated(self, query):
|
||||||
authenticated_query = "{}&api_key={}".format(query,
|
authenticated_query = "{}&api_key={}".format(query,
|
||||||
@ -181,10 +221,8 @@ class TestBulkStreetFunctions(TestStreetFunctionsSetUp):
|
|||||||
return IntegrationTestHelper.execute_query_raw(self.sql_api_url,
|
return IntegrationTestHelper.execute_query_raw(self.sql_api_url,
|
||||||
authenticated_query)
|
authenticated_query)
|
||||||
|
|
||||||
def _row_by_cartodb_id(self, response):
|
@staticmethod
|
||||||
return {r['cartodb_id']: r for r in response['rows']}
|
def _x_y_by_cartodb_id(response):
|
||||||
|
return {r['cartodb_id']: [r['st_x'], r['st_y']]
|
||||||
def _assert_x_y(self, row, expected_x, expected_y):
|
for r in response['rows']}
|
||||||
assert_equal(row['st_x'], expected_x)
|
|
||||||
assert_equal(row['st_y'], expected_y)
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user