New tests for restructuration - client

This commit is contained in:
Carla Iriberri 2016-09-01 15:46:23 +02:00
parent cf2f86136b
commit 78add220cd
2 changed files with 49 additions and 54 deletions

View File

@ -3,65 +3,63 @@ SET search_path TO public,cartodb,cdb_dataservices_client;
CREATE TABLE my_table(cartodb_id int); CREATE TABLE my_table(cartodb_id int);
INSERT INTO my_table (cartodb_id) VALUES (1); INSERT INTO my_table (cartodb_id) VALUES (1);
-- Mock the server functions -- Mock the server functions
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_ConnectUserTable(username text, orgname text, user_db_role text, input_schema text, dbname text, table_name text) CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_ConnectUserTable(username text, orgname text, user_db_role text, input_schema text, dbname text, table_name text)
RETURNS cdb_dataservices_client.ds_fdw_metadata AS $$ RETURNS cdb_dataservices_client.ds_fdw_metadata AS $$
BEGIN BEGIN
RETURN ('dummy_schema'::text, 'dummy_table'::text, 'dummy_server'::text); RETURN ('dummy_schema'::text, 'dummy_table'::text, 'dummy_server'::text);
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetReturnMetadata(username text, orgname text, function_name text, params json) CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_GetReturnMetadata(username text, orgname text, function_name text, params json)
RETURNS cdb_dataservices_client.ds_return_metadata AS $$ RETURNS cdb_dataservices_client.ds_return_metadata AS $$
BEGIN BEGIN
RETURN (Array['total_pop'], Array['double precision']); RETURN (Array['total_pop'], Array['double precision']);
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_FetchJoinFdwTableData(username text, orgname text, table_schema text, table_name text, function_name text, params json) CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_FetchJoinFdwTableData(username text, orgname text, table_schema text, table_name text, function_name text, params json)
RETURNS RECORD AS $$ RETURNS RECORD AS $$
BEGIN BEGIN
RETURN (23.4::double precision, 1::int); RETURN (23.4::double precision, 1::int);
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_DisconnectUserTable(username text, orgname text, table_schema text, table_name text, servername text) CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_DisconnectUserTable(username text, orgname text, table_schema text, table_name text, servername text)
RETURNS boolean AS $$ RETURNS boolean AS $$
BEGIN BEGIN
RETURN true; RETURN true;
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql';
-- Augment a table with the total_pop column -- Create a sample user table
SELECT cdb_dataservices_client._OBS_AugmentTable('my_table', 'dummy', '{"dummy":"dummy"}'::json); CREATE TABLE user_table (cartodb_id int, the_geom geometry);
_obs_augmenttable INSERT INTO user_table(cartodb_id, the_geom) VALUES (1, '0101000020E6100000F74FC902E07D52C05FE24CC7654B4440');
------------------- INSERT INTO user_table(cartodb_id, the_geom) VALUES (2, '0101000020E6100000F74FC902E07D52C05FE24CC7654B4440');
INSERT INTO user_table(cartodb_id, the_geom) VALUES (3, '0101000020E6100000F74FC902E07D52C05FE24CC7654B4440');
-- Prepare a table with the total_pop column
SELECT cdb_dataservices_client._DST_PrepareTableOBS_GetMeasure('my_table_dst', '{"dummy":"dummy"}'::json);
_dst_preparetableobs_getmeasure
---------------------------------
t t
(1 row) (1 row)
-- The results of the table should return the mocked value of 23.4 in the total_pop column -- The table should now exist and be empty
SELECT * FROM my_table; SELECT * FROM my_table_dst;
cartodb_id | total_pop cartodb_id | the_geom | total_pop
------------+----------- ------------+----------+-----------
1 | 23.4 (0 rows)
(1 row)
-- Mock again the function for it to return a different value now -- Populate the table with measurement data
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_FetchJoinFdwTableData(username text, orgname text, table_schema text, table_name text, function_name text, params json) SELECT cdb_dataservices_client._DST_PopulateTableOBS_GetMeasure('user_table', 'my_table_dst', '{"dummy":"dummy"}'::json);
RETURNS RECORD AS $$ _dst_populatetableobs_getmeasure
BEGIN ----------------------------------
RETURN (577777.4::double precision, 1::int);
END;
$$ LANGUAGE 'plpgsql';
-- Augment a new table with total_pop
SELECT cdb_dataservices_client._OBS_GetTable('my_table', 'my_table_new', 'dummy', '{"dummy":"dummy"}'::json);
_obs_gettable
---------------
t t
(1 row) (1 row)
-- Check that the table contains the new value for total_pop and not the value already existent in the table -- The table should now show the results
SELECT * FROM my_table_new; SELECT * FROM my_table_dst;
total_pop | cartodb_id cartodb_id | the_geom | total_pop
-----------+------------ ------------+----------------------------------------------------+-----------
577777.4 | 1 1 | 0101000020E6100000F74FC902E07D52C05FE24CC7654B4440 | 23.4
(1 row) 2 | 0101000020E6100000F74FC902E07D52C05FE24CC7654B4440 |
3 | 0101000020E6100000F74FC902E07D52C05FE24CC7654B4440 |
(3 rows)
-- Clean tables -- Clean tables
DROP TABLE my_table; DROP TABLE my_table_dst;
DROP TABLE my_table_new;

View File

@ -6,54 +6,51 @@ CREATE TABLE my_table(cartodb_id int);
INSERT INTO my_table (cartodb_id) VALUES (1); INSERT INTO my_table (cartodb_id) VALUES (1);
-- Mock the server functions -- Mock the server functions
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_ConnectUserTable(username text, orgname text, user_db_role text, input_schema text, dbname text, table_name text) CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_ConnectUserTable(username text, orgname text, user_db_role text, input_schema text, dbname text, table_name text)
RETURNS cdb_dataservices_client.ds_fdw_metadata AS $$ RETURNS cdb_dataservices_client.ds_fdw_metadata AS $$
BEGIN BEGIN
RETURN ('dummy_schema'::text, 'dummy_table'::text, 'dummy_server'::text); RETURN ('dummy_schema'::text, 'dummy_table'::text, 'dummy_server'::text);
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetReturnMetadata(username text, orgname text, function_name text, params json) CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_GetReturnMetadata(username text, orgname text, function_name text, params json)
RETURNS cdb_dataservices_client.ds_return_metadata AS $$ RETURNS cdb_dataservices_client.ds_return_metadata AS $$
BEGIN BEGIN
RETURN (Array['total_pop'], Array['double precision']); RETURN (Array['total_pop'], Array['double precision']);
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_FetchJoinFdwTableData(username text, orgname text, table_schema text, table_name text, function_name text, params json) CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_FetchJoinFdwTableData(username text, orgname text, table_schema text, table_name text, function_name text, params json)
RETURNS RECORD AS $$ RETURNS RECORD AS $$
BEGIN BEGIN
RETURN (23.4::double precision, 1::int); RETURN (23.4::double precision, 1::int);
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_DisconnectUserTable(username text, orgname text, table_schema text, table_name text, servername text) CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_DisconnectUserTable(username text, orgname text, table_schema text, table_name text, servername text)
RETURNS boolean AS $$ RETURNS boolean AS $$
BEGIN BEGIN
RETURN true; RETURN true;
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql';
-- Augment a table with the total_pop column -- Create a sample user table
SELECT cdb_dataservices_client._OBS_AugmentTable('my_table', 'dummy', '{"dummy":"dummy"}'::json); CREATE TABLE user_table (cartodb_id int, the_geom geometry);
INSERT INTO user_table(cartodb_id, the_geom) VALUES (1, '0101000020E6100000F74FC902E07D52C05FE24CC7654B4440');
INSERT INTO user_table(cartodb_id, the_geom) VALUES (2, '0101000020E6100000F74FC902E07D52C05FE24CC7654B4440');
INSERT INTO user_table(cartodb_id, the_geom) VALUES (3, '0101000020E6100000F74FC902E07D52C05FE24CC7654B4440');
-- The results of the table should return the mocked value of 23.4 in the total_pop column -- Prepare a table with the total_pop column
SELECT * FROM my_table; SELECT cdb_dataservices_client._DST_PrepareTableOBS_GetMeasure('my_table_dst', '{"dummy":"dummy"}'::json);
-- Mock again the function for it to return a different value now -- The table should now exist and be empty
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_FetchJoinFdwTableData(username text, orgname text, table_schema text, table_name text, function_name text, params json) SELECT * FROM my_table_dst;
RETURNS RECORD AS $$
BEGIN
RETURN (577777.4::double precision, 1::int);
END;
$$ LANGUAGE 'plpgsql';
-- Augment a new table with total_pop -- Populate the table with measurement data
SELECT cdb_dataservices_client._OBS_GetTable('my_table', 'my_table_new', 'dummy', '{"dummy":"dummy"}'::json); SELECT cdb_dataservices_client._DST_PopulateTableOBS_GetMeasure('user_table', 'my_table_dst', '{"dummy":"dummy"}'::json);
-- Check that the table contains the new value for total_pop and not the value already existent in the table -- The table should now show the results
SELECT * FROM my_table_new; SELECT * FROM my_table_dst;
-- Clean tables -- Clean tables
DROP TABLE my_table; DROP TABLE my_table_dst;
DROP TABLE my_table_new;