From ca4327d3cd328a57420bb63c651be1f0ca2db8e5 Mon Sep 17 00:00:00 2001 From: John Krauss Date: Mon, 27 Jun 2016 11:55:03 -0400 Subject: [PATCH] use data_geoid_colname with data table, reenable area-based measure tests that can catch this bug --- scripts/autotest.py | 47 ++++++++++++---------- src/pg/sql/41_observatory_augmentation.sql | 2 +- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/scripts/autotest.py b/scripts/autotest.py index 565ad9a..7c2426c 100644 --- a/scripts/autotest.py +++ b/scripts/autotest.py @@ -24,8 +24,9 @@ def query(q, is_meta=False, **options): params['api_key'] = META_API_KEY if is_meta else API_KEY return requests.get(url, params=params) -MEASURE_COLUMNS = [(r['id'], ) for r in query(''' -SELECT id FROM obs_column +MEASURE_COLUMNS = [(r['id'], r['point_only'], ) for r in query(''' +SELECT id, aggregate NOT ILIKE 'sum' as point_only +FROM obs_column WHERE type ILIKE 'numeric' AND weight > 0 ''', is_meta=True).json()['rows']] @@ -98,14 +99,14 @@ def default_point(column_id): return 'CDB_LatLng(40.7, -73.9)' -#def default_area(column_id): -# ''' -# Returns default test area for the column_id -# ''' -# point = default_point(column_id) -# area = 'ST_Transform(ST_Buffer(ST_Transform({point}, 3857), 1000), 4326)'.format( -# point=point) -# return area +def default_area(column_id): + ''' + Returns default test area for the column_id + ''' + point = default_point(column_id) + area = 'ST_Transform(ST_Buffer(ST_Transform({point}, 3857), 1000), 4326)'.format( + point=point) + return area @parameterized(US_CENSUS_MEASURE_COLUMNS) 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]) -#@parameterized(MEASURE_COLUMNS) -#def test_get_measure_areas(column_id): -# resp = query(''' -#SELECT * FROM {schema}OBS_GetMeasure({area}, '{column_id}') -# '''.format(column_id=column_id, -# schema='cdb_observatory.' if USE_SCHEMA else '', -# area=default_area(column_id))) -# assert_equal(resp.status_code, 200) -# rows = resp.json()['rows'] -# assert_equal(1, len(rows)) -# assert_is_not_none(rows[0].values()[0]) +@parameterized(MEASURE_COLUMNS) +def test_get_measure_areas(column_id, point_only): + if point_only: + return + resp = query(''' +SELECT * FROM {schema}OBS_GetMeasure({area}, '{column_id}') + '''.format(column_id=column_id, + schema='cdb_observatory.' if USE_SCHEMA else '', + area=default_area(column_id))) + assert_equal(resp.status_code, 200) + rows = resp.json()['rows'] + assert_equal(1, len(rows)) + assert_is_not_none(rows[0].values()[0]) @parameterized(MEASURE_COLUMNS) -def test_get_measure_points(column_id): +def test_get_measure_points(column_id, point_only): resp = query(''' SELECT * FROM {schema}OBS_GetMeasure({point}, '{column_id}') '''.format(column_id=column_id, diff --git a/src/pg/sql/41_observatory_augmentation.sql b/src/pg/sql/41_observatory_augmentation.sql index 544a18d..08a6208 100644 --- a/src/pg/sql/41_observatory_augmentation.sql +++ b/src/pg/sql/41_observatory_augmentation.sql @@ -633,7 +633,7 @@ BEGIN q := q || q_select || format('FROM observatory.%I ', ((data_table_info)[1]->>'tablename')); 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 q