Adding tests for new json returning utility functions

This commit is contained in:
Stuart Lynn 2016-04-22 16:10:30 -04:00
parent 3394483a45
commit 69ac0d25f2
2 changed files with 29 additions and 57 deletions

View File

@ -46,44 +46,15 @@ SELECT
(1 row)
-- future test: give back nulls when geometry doesn't intersect
-- SELECT
-- cdb_observatory._OBS_GeomTable(
-- CDB_LatLng(0,0), -- should give back null since it's in the ocean?
-- '"us.census.tiger".census_tract'
-- );
-- OBS_GetColumnData
-- should give back:
-- colname | tablename | aggregate
-- -----------|-----------------|-----------
-- geoid | obs_{hex table} | null
-- total_pop | obs_{hex table} | sum
SELECT
(unnest(cdb_observatory._OBS_GetColumnData(
'"us.census.tiger".census_tract',
Array['"us.census.tiger".census_tract_geoid', '"us.census.acs".B01001001'],
'2009 - 2013'
))).*
ORDER BY colname, tablename ASC;
colname | tablename | aggregate
-----------+----------------------------------------------+-----------
geoid | obs_11ee8b82c877c073438bc935a91d3dfccef875d1 |
geoid | obs_ab038198aaab3f3cb055758638ee4de28ad70146 |
geoid | obs_d34555209878e8c4b37cf0b2b3d072ff129ec470 |
total_pop | obs_ab038198aaab3f3cb055758638ee4de28ad70146 | sum
(4 rows)
test_get_obs_column_with_geoid_and_census_1 | test_get_obs_column_with_geoid_and_census_2 | test_get_obs_column_with_geoid_and_census_3
---------------------------------------------+---------------------------------------------+---------------------------------------------
t | t | t
(1 row)
-- should be null-valued
SELECT
(unnest(cdb_observatory._OBS_GetColumnData(
'"us.census.tiger".census_tract',
Array['"us.census.tiger".baloney'], -- entry not in catalog
'2009 - 2013'
))).*
ORDER BY 1 ASC;
colname | tablename | aggregate
---------+-----------+-----------
(0 rows)
obs_getcolumndatajson_missing_measure
---------------------------------------
t
(1 row)
-- OBS_LookupCensusHuman
-- should give back: {"\"us.census.acs\".B19083001"}
@ -127,17 +98,11 @@ SELECT
SELECT vals[1] As mandarin_orange
(1 row)
SELECT cdb_observatory._OBS_GetRelatedColumn(
Array[
'"es.ine".pop_0_4',
'"us.census.acs".B01001001',
'"us.census.acs".B01001002'
],
'denominator'
);
_obs_getrelatedcolumn
-------------------------------------------------------------
{"\"es.ine\".total_pop",NULL,"\"us.census.acs\".B01001001"}
-- should give back a normalized name
SELECT cdb_observatory._OBS_NormalizeMeasureName('test 343 %% 2 qqq }}{{}}');
_obs_normalizemeasurename
---------------------------
test_343_2_qqq
(1 row)
\i test/sql/drop_fixtures.sql

View File

@ -32,22 +32,29 @@ SELECT
-- -----------|-----------------|-----------
-- geoid | obs_{hex table} | null
-- total_pop | obs_{hex table} | sum
WITH result as (
SELECT
(unnest(cdb_observatory._OBS_GetColumnData(
array_agg(a) expected from cdb_observatory._OBS_GetColumnData(
'"us.census.tiger".census_tract',
Array['"us.census.tiger".census_tract_geoid', '"us.census.acs".B01001001'],
'2009 - 2013'
))).*
ORDER BY colname, tablename ASC;
'2009 - 2013') a
)
select (expected)[1]::text = '{"colname":"geoid","tablename":"obs_d34555209878e8c4b37cf0b2b3d072ff129ec470","aggregate":null,"name":"US Census Tract Geoids","type":"Text","description":""}' as test_get_obs_column_with_geoid_and_census_1,
(expected)[2]::text = '{"colname":"geoid","tablename":"obs_ab038198aaab3f3cb055758638ee4de28ad70146","aggregate":null,"name":"US Census Tract Geoids","type":"Text","description":""}' as test_get_obs_column_with_geoid_and_census_2,
(expected)[3]::text = '{"colname":"geoid","tablename":"obs_65f29658e096ca1485bf683f65fdbc9f05ec3c5d","aggregate":null,"name":"US Census Tract Geoids","type":"Text","description":""}' as test_get_obs_column_with_geoid_and_census_3
from result;
-- should be null-valued
WITH result as (
SELECT
(unnest(cdb_observatory._OBS_GetColumnData(
array_agg(a) expected from cdb_observatory._OBS_GetColumnData(
'"us.census.tiger".census_tract',
Array['"us.census.tiger".baloney'], -- entry not in catalog
'2009 - 2013'
))).*
ORDER BY 1 ASC;
Array['"us.census.tiger".baloney'],
'2009 - 2013') a
)
select expected is null as OBS_GetColumnDataJSON_missing_measure
from result;
-- OBS_LookupCensusHuman
-- should give back: {"\"us.census.acs\".B19083001"}