Merge branch 'develop' into update-total-pop-column-ids
This commit is contained in:
commit
0d5e45fc98
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,3 +2,5 @@
|
|||||||
src/pg/observatory--current--dev.sql
|
src/pg/observatory--current--dev.sql
|
||||||
src/pg/observatory--dev--current.sql
|
src/pg/observatory--dev--current.sql
|
||||||
src/pg/observatory--dev.sql
|
src/pg/observatory--dev.sql
|
||||||
|
venv
|
||||||
|
*.pyc
|
||||||
|
15
scripts/README.md
Normal file
15
scripts/README.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
## Automatic tests and utilities
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
Python 2.7 should cover you. Virtualenv recommended.
|
||||||
|
|
||||||
|
virtualenv venv
|
||||||
|
source venv/bin/activate
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
### Execution
|
||||||
|
|
||||||
|
Run automated tests against a hostname:
|
||||||
|
|
||||||
|
(venv) OBS_HOSTNAME=<hostname.cartodb.com> OBS_API_KEY=foobar nosetests autotest.py
|
100
scripts/autotest.py
Normal file
100
scripts/autotest.py
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
from nose.tools import assert_equal, assert_is_not_none
|
||||||
|
from nose_parameterized import parameterized
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import requests
|
||||||
|
|
||||||
|
HOSTNAME = os.environ['OBS_HOSTNAME']
|
||||||
|
API_KEY = os.environ['OBS_API_KEY']
|
||||||
|
META_HOSTNAME = os.environ.get('OBS_META_HOSTNAME', HOSTNAME)
|
||||||
|
META_API_KEY = os.environ.get('OBS_META_API_KEY', API_KEY)
|
||||||
|
USE_SCHEMA = 'OBS_USE_SCHEMA' in os.environ
|
||||||
|
|
||||||
|
|
||||||
|
def query(q, is_meta=False, **options):
|
||||||
|
'''
|
||||||
|
Query the account. Returned is the response, wrapped by the requests
|
||||||
|
library.
|
||||||
|
'''
|
||||||
|
url = 'https://{hostname}/api/v2/sql'.format(
|
||||||
|
hostname=META_HOSTNAME if is_meta else HOSTNAME)
|
||||||
|
params = options.copy()
|
||||||
|
params['q'] = re.sub(r'\s+', ' ', q)
|
||||||
|
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 observatory.obs_column
|
||||||
|
WHERE type ILIKE 'numeric'
|
||||||
|
AND weight > 0
|
||||||
|
''', is_meta=True).json()['rows']]
|
||||||
|
|
||||||
|
CATEGORY_COLUMNS = [(r['id'], ) for r in query('''
|
||||||
|
SELECT id FROM observatory.obs_column
|
||||||
|
WHERE type ILIKE 'text'
|
||||||
|
AND weight > 0
|
||||||
|
''', is_meta=True).json()['rows']]
|
||||||
|
|
||||||
|
BOUNDARY_COLUMNS = [(r['id'], ) for r in query('''
|
||||||
|
SELECT id FROM observatory.obs_column
|
||||||
|
WHERE type ILIKE 'geometry'
|
||||||
|
AND weight > 0
|
||||||
|
''', is_meta=True).json()['rows']]
|
||||||
|
|
||||||
|
def default_point(column_id):
|
||||||
|
'''
|
||||||
|
Returns default test point for the column_id.
|
||||||
|
'''
|
||||||
|
if column_id == 'whosonfirst.wof_disputed_geom':
|
||||||
|
return 'CDB_LatLng(33.78, 76.57)'
|
||||||
|
elif column_id == 'whosonfirst.wof_marinearea_geom':
|
||||||
|
return 'CDB_LatLng(43.33, -68.47)'
|
||||||
|
elif column_id in ('us.census.tiger.school_district_elementary',
|
||||||
|
'us.census.tiger.school_district_secondary',
|
||||||
|
'us.census.tiger.school_district_elementary_clipped',
|
||||||
|
'us.census.tiger.school_district_secondary_clipped'):
|
||||||
|
return 'CDB_LatLng(40.7025, -73.7067)'
|
||||||
|
elif column_id.startswith('es.ine'):
|
||||||
|
return 'CDB_LatLng(40.39, -3.7)'
|
||||||
|
elif column_id.startswith('us.zillow'):
|
||||||
|
return 'CDB_LatLng(28.3305906291771, -81.3544048197256)'
|
||||||
|
else:
|
||||||
|
return 'CDB_LatLng(40.7, -73.9)'
|
||||||
|
|
||||||
|
|
||||||
|
@parameterized(MEASURE_COLUMNS)
|
||||||
|
def test_measure_points(column_id):
|
||||||
|
resp = query('''
|
||||||
|
SELECT * FROM {schema}OBS_GetMeasure({point}, '{column_id}')
|
||||||
|
'''.format(column_id=column_id,
|
||||||
|
schema='cdb_observatory.' if USE_SCHEMA else '',
|
||||||
|
point=default_point(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(CATEGORY_COLUMNS)
|
||||||
|
def test_category_points(column_id):
|
||||||
|
resp = query('''
|
||||||
|
SELECT * FROM {schema}OBS_GetCategory({point}, '{column_id}')
|
||||||
|
'''.format(column_id=column_id,
|
||||||
|
schema='cdb_observatory.' if USE_SCHEMA else '',
|
||||||
|
point=default_point(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(BOUNDARY_COLUMNS)
|
||||||
|
def test_boundary_points(column_id):
|
||||||
|
resp = query('''
|
||||||
|
SELECT * FROM {schema}OBS_GetBoundary({point}, '{column_id}')
|
||||||
|
'''.format(column_id=column_id,
|
||||||
|
schema='cdb_observatory.' if USE_SCHEMA else '',
|
||||||
|
point=default_point(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])
|
3
scripts/requirements.txt
Normal file
3
scripts/requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
requests
|
||||||
|
nose
|
||||||
|
nose_parameterized
|
@ -274,6 +274,7 @@ BEGIN
|
|||||||
THEN
|
THEN
|
||||||
RAISE NOTICE 'No boundaries found for bounding box ''%'' in ''%''', ST_AsText(geom), boundary_id;
|
RAISE NOTICE 'No boundaries found for bounding box ''%'' in ''%''', ST_AsText(geom), boundary_id;
|
||||||
RETURN QUERY SELECT NULL::geometry, NULL::text;
|
RETURN QUERY SELECT NULL::geometry, NULL::text;
|
||||||
|
RETURN;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
RAISE NOTICE 'target_table: %', target_table;
|
RAISE NOTICE 'target_table: %', target_table;
|
||||||
@ -286,6 +287,7 @@ BEGIN
|
|||||||
WHERE ST_%s($1, the_geom)
|
WHERE ST_%s($1, the_geom)
|
||||||
', geom_colname, geoid_colname, target_table, overlap_type)
|
', geom_colname, geoid_colname, target_table, overlap_type)
|
||||||
USING geom;
|
USING geom;
|
||||||
|
RETURN;
|
||||||
|
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
@ -328,6 +330,7 @@ BEGIN
|
|||||||
time_span,
|
time_span,
|
||||||
overlap_type
|
overlap_type
|
||||||
);
|
);
|
||||||
|
RETURN;
|
||||||
|
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
@ -380,6 +383,7 @@ BEGIN
|
|||||||
circle_boundary,
|
circle_boundary,
|
||||||
boundary_id,
|
boundary_id,
|
||||||
time_span);
|
time_span);
|
||||||
|
RETURN;
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
@ -416,6 +420,7 @@ BEGIN
|
|||||||
THEN
|
THEN
|
||||||
RAISE NOTICE 'No boundaries found for bounding box ''%'' in ''%''', ST_AsText(geom), boundary_id;
|
RAISE NOTICE 'No boundaries found for bounding box ''%'' in ''%''', ST_AsText(geom), boundary_id;
|
||||||
RETURN QUERY SELECT NULL::geometry, NULL::text;
|
RETURN QUERY SELECT NULL::geometry, NULL::text;
|
||||||
|
RETURN;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
RAISE NOTICE 'target_table: %', target_table;
|
RAISE NOTICE 'target_table: %', target_table;
|
||||||
@ -428,6 +433,7 @@ BEGIN
|
|||||||
WHERE ST_%s($1, the_geom)
|
WHERE ST_%s($1, the_geom)
|
||||||
', geom_colname, geom_colname, geoid_colname, target_table, overlap_type)
|
', geom_colname, geom_colname, geoid_colname, target_table, overlap_type)
|
||||||
USING geom;
|
USING geom;
|
||||||
|
RETURN;
|
||||||
|
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
@ -469,6 +475,7 @@ BEGIN
|
|||||||
boundary_id,
|
boundary_id,
|
||||||
time_span,
|
time_span,
|
||||||
overlap_type);
|
overlap_type);
|
||||||
|
RETURN;
|
||||||
|
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
@ -522,6 +529,7 @@ BEGIN
|
|||||||
boundary_id,
|
boundary_id,
|
||||||
time_span,
|
time_span,
|
||||||
overlap_type);
|
overlap_type);
|
||||||
|
RETURN;
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
@ -560,6 +568,7 @@ BEGIN
|
|||||||
-- AND geom_t.timespan = '%s' <-- put in requested year
|
-- AND geom_t.timespan = '%s' <-- put in requested year
|
||||||
-- TODO: filter by clipped vs. not so appropriate tablename are unique
|
-- TODO: filter by clipped vs. not so appropriate tablename are unique
|
||||||
-- so the limit 1 can be removed
|
-- so the limit 1 can be removed
|
||||||
|
RETURN;
|
||||||
|
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
Loading…
Reference in New Issue
Block a user