2018-06-28 19:06:52 +08:00
|
|
|
\set VERBOSITY terse
|
|
|
|
|
2018-07-18 20:29:50 +08:00
|
|
|
ALTER FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch() RENAME TO cdb_service_quota_info_batch_mocked;
|
|
|
|
CREATE FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch ()
|
|
|
|
RETURNS SETOF cdb_dataservices_client.service_quota_info_batch AS $$
|
2018-07-11 01:06:49 +08:00
|
|
|
SELECT 'hires_geocoder'::cdb_dataservices_client.service_type AS service, 0::NUMERIC AS monthly_quota, 0::NUMERIC AS used_quota, FALSE AS soft_limit, 'google' AS provider, 1::NUMERIC AS max_batch_size;
|
|
|
|
$$ LANGUAGE SQL;
|
2018-06-28 19:06:52 +08:00
|
|
|
|
|
|
|
ALTER FUNCTION cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_size NUMERIC) RENAME TO cdb_enough_quota_mocked;
|
|
|
|
CREATE FUNCTION cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_size NUMERIC)
|
|
|
|
RETURNS BOOLEAN as $$
|
|
|
|
SELECT FALSE;
|
|
|
|
$$ LANGUAGE SQL;
|
|
|
|
|
2019-02-19 19:24:06 +08:00
|
|
|
ALTER FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point(searches jsonb) RENAME TO _cdb_bulk_geocode_street_point_mocked;
|
|
|
|
CREATE FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point(searches jsonb)
|
|
|
|
RETURNS SETOF cdb_dataservices_client.geocoding AS $$
|
|
|
|
BEGIN
|
|
|
|
RAISE NOTICE 'called with this searches: %', searches;
|
|
|
|
END;
|
2019-10-07 22:23:07 +08:00
|
|
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE SET search_path = pg_temp;
|
2019-02-19 19:24:06 +08:00
|
|
|
|
2018-09-06 22:40:05 +08:00
|
|
|
-- No permissions granted
|
2018-07-11 01:06:49 +08:00
|
|
|
-- Test bulk size not mandatory (it will get the optimal)
|
|
|
|
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''', null, null, null, null);
|
2018-09-06 22:40:05 +08:00
|
|
|
-- Test quota check by mocking quota 0
|
|
|
|
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
|
|
|
|
|
|
|
|
-- Grant other permissions but geocoding
|
2018-09-11 18:02:24 +08:00
|
|
|
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["routing", "isolines"]}');
|
2018-09-06 22:40:05 +08:00
|
|
|
-- Test bulk size not mandatory (it will get the optimal)
|
|
|
|
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''', null, null, null, null);
|
|
|
|
-- Test quota check by mocking quota 0
|
|
|
|
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
|
2018-06-28 19:06:52 +08:00
|
|
|
|
2018-09-06 22:40:05 +08:00
|
|
|
-- Grant geocoding permissions
|
2018-09-11 18:02:24 +08:00
|
|
|
SELECT CDB_Conf_SetConf('api_keys_postgres', '{"username": "test_user", "permissions": ["geocoding"]}');
|
2018-09-06 22:40:05 +08:00
|
|
|
-- Test bulk size not mandatory (it will get the optimal)
|
|
|
|
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''', null, null, null, null);
|
2018-07-11 01:06:49 +08:00
|
|
|
-- Test quota check by mocking quota 0
|
2018-06-28 19:06:52 +08:00
|
|
|
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
|
|
|
|
|
2019-02-19 19:24:06 +08:00
|
|
|
-- Check that when cdb_enough_quota returns true (ie. when soft_limit is set to true, even if not enough quota)
|
|
|
|
-- it is able to proceed with the bulk geocode
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_size NUMERIC)
|
|
|
|
RETURNS BOOLEAN as $$
|
|
|
|
SELECT TRUE;
|
|
|
|
$$ LANGUAGE SQL;
|
|
|
|
SELECT cdb_dataservices_client.cdb_bulk_geocode_street_point('select 1 as cartodb_id', '''Valladolid, Spain''');
|
|
|
|
|
2018-09-06 22:40:05 +08:00
|
|
|
-- Remove permissions
|
|
|
|
SELECT CDB_Conf_RemoveConf('api_keys_postgres');
|
|
|
|
|
2018-07-18 20:29:50 +08:00
|
|
|
DROP FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch;
|
2018-06-28 19:06:52 +08:00
|
|
|
DROP FUNCTION cdb_dataservices_client.cdb_enough_quota;
|
2019-02-19 19:24:06 +08:00
|
|
|
DROP FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point;
|
2018-06-28 19:06:52 +08:00
|
|
|
|
|
|
|
ALTER FUNCTION cdb_dataservices_client.cdb_enough_quota_mocked (service TEXT ,input_size NUMERIC) RENAME TO cdb_enough_quota;
|
2018-07-18 20:29:50 +08:00
|
|
|
ALTER FUNCTION cdb_dataservices_client.cdb_service_quota_info_batch_mocked() RENAME TO cdb_service_quota_info_batch;
|
2019-02-19 19:24:06 +08:00
|
|
|
ALTER FUNCTION cdb_dataservices_client._cdb_bulk_geocode_street_point_mocked(searches jsonb) RENAME TO _cdb_bulk_geocode_street_point;
|