use data_geoid_colname with data table, reenable area-based measure tests that can catch this bug

This commit is contained in:
John Krauss 2016-06-27 11:55:03 -04:00
parent 7733529ff5
commit ca4327d3cd
2 changed files with 26 additions and 23 deletions

View File

@ -24,8 +24,9 @@ def query(q, is_meta=False, **options):
params['api_key'] = META_API_KEY if is_meta else API_KEY params['api_key'] = META_API_KEY if is_meta else API_KEY
return requests.get(url, params=params) return requests.get(url, params=params)
MEASURE_COLUMNS = [(r['id'], ) for r in query(''' MEASURE_COLUMNS = [(r['id'], r['point_only'], ) for r in query('''
SELECT id FROM obs_column SELECT id, aggregate NOT ILIKE 'sum' as point_only
FROM obs_column
WHERE type ILIKE 'numeric' WHERE type ILIKE 'numeric'
AND weight > 0 AND weight > 0
''', is_meta=True).json()['rows']] ''', is_meta=True).json()['rows']]
@ -98,14 +99,14 @@ def default_point(column_id):
return 'CDB_LatLng(40.7, -73.9)' return 'CDB_LatLng(40.7, -73.9)'
#def default_area(column_id): def default_area(column_id):
# ''' '''
# Returns default test area for the column_id Returns default test area for the column_id
# ''' '''
# point = default_point(column_id) point = default_point(column_id)
# area = 'ST_Transform(ST_Buffer(ST_Transform({point}, 3857), 1000), 4326)'.format( area = 'ST_Transform(ST_Buffer(ST_Transform({point}, 3857), 1000), 4326)'.format(
# point=point) point=point)
# return area return area
@parameterized(US_CENSUS_MEASURE_COLUMNS) @parameterized(US_CENSUS_MEASURE_COLUMNS)
def test_get_us_census_measure_points(name): def test_get_us_census_measure_points(name):
@ -120,21 +121,23 @@ SELECT * FROM {schema}OBS_GetUSCensusMeasure({point}, '{name}')
assert_is_not_none(rows[0].values()[0]) assert_is_not_none(rows[0].values()[0])
#@parameterized(MEASURE_COLUMNS) @parameterized(MEASURE_COLUMNS)
#def test_get_measure_areas(column_id): def test_get_measure_areas(column_id, point_only):
# resp = query(''' if point_only:
#SELECT * FROM {schema}OBS_GetMeasure({area}, '{column_id}') return
# '''.format(column_id=column_id, resp = query('''
# schema='cdb_observatory.' if USE_SCHEMA else '', SELECT * FROM {schema}OBS_GetMeasure({area}, '{column_id}')
# area=default_area(column_id))) '''.format(column_id=column_id,
# assert_equal(resp.status_code, 200) schema='cdb_observatory.' if USE_SCHEMA else '',
# rows = resp.json()['rows'] area=default_area(column_id)))
# assert_equal(1, len(rows)) assert_equal(resp.status_code, 200)
# assert_is_not_none(rows[0].values()[0]) rows = resp.json()['rows']
assert_equal(1, len(rows))
assert_is_not_none(rows[0].values()[0])
@parameterized(MEASURE_COLUMNS) @parameterized(MEASURE_COLUMNS)
def test_get_measure_points(column_id): def test_get_measure_points(column_id, point_only):
resp = query(''' resp = query('''
SELECT * FROM {schema}OBS_GetMeasure({point}, '{column_id}') SELECT * FROM {schema}OBS_GetMeasure({point}, '{column_id}')
'''.format(column_id=column_id, '''.format(column_id=column_id,

View File

@ -633,7 +633,7 @@ BEGIN
q := q || q_select || format('FROM observatory.%I ', ((data_table_info)[1]->>'tablename')); q := q || q_select || format('FROM observatory.%I ', ((data_table_info)[1]->>'tablename'));
q := format(q || ' ) ' || q_sum || ' ]::numeric[] FROM _overlaps, values q := format(q || ' ) ' || q_sum || ' ]::numeric[] FROM _overlaps, values
WHERE values.%I = _overlaps.%I', geom_geoid_colname, geom_geoid_colname); WHERE values.%I = _overlaps.%I', data_geoid_colname, geom_geoid_colname);
EXECUTE EXECUTE
q q