Compare commits
25 Commits
python-0.1
...
python-0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32010669e8 | ||
|
|
b0f10d1680 | ||
|
|
b5514aea60 | ||
|
|
53acd4d30e | ||
|
|
15438db59b | ||
|
|
0918f91bfa | ||
|
|
3c60f3e93b | ||
|
|
8692fb12ca | ||
|
|
4523b2e04d | ||
|
|
5c8dbe91eb | ||
|
|
99b76afc33 | ||
|
|
c97f03b2e3 | ||
|
|
cd653bc496 | ||
|
|
610cfaab57 | ||
|
|
58b1713a0d | ||
|
|
842be0ba85 | ||
|
|
4fc90626ab | ||
|
|
16cce3bddc | ||
|
|
dbd5911a2a | ||
|
|
e53a39875e | ||
|
|
4cd72616ca | ||
|
|
fae7889fe3 | ||
|
|
1f53af65b9 | ||
|
|
79fb796180 | ||
|
|
2953fda75c |
3
client/.gitignore
vendored
3
client/.gitignore
vendored
@@ -2,9 +2,10 @@ results/
|
|||||||
regression.diffs
|
regression.diffs
|
||||||
regression.out
|
regression.out
|
||||||
20_public_functions.sql
|
20_public_functions.sql
|
||||||
|
25_exception_safe_private_functions.sql
|
||||||
30_plproxy_functions.sql
|
30_plproxy_functions.sql
|
||||||
90_grant_execute.sql
|
90_grant_execute.sql
|
||||||
cdb_geocoder_client--0.0.1.sql
|
cdb_geocoder_client--0.0.1.sql
|
||||||
cdb_geocoder_client--0.1.0.sql
|
cdb_geocoder_client--0.1.0.sql
|
||||||
cdb_geocoder_client--0.2.0.sql
|
cdb_geocoder_client--0.2.0.sql
|
||||||
cdb_geocoder_client--0.3.0.sql
|
cdb_geocoder_client--0.3.0.sql
|
||||||
|
|||||||
@@ -57,9 +57,11 @@ all: $(DATA)
|
|||||||
.PHONY: release
|
.PHONY: release
|
||||||
release: $(EXTENSION).control $(SOURCES_DATA)
|
release: $(EXTENSION).control $(SOURCES_DATA)
|
||||||
test -n "$(NEW_VERSION)" # $$NEW_VERSION VARIABLE MISSING. Eg. make release NEW_VERSION=0.x.0
|
test -n "$(NEW_VERSION)" # $$NEW_VERSION VARIABLE MISSING. Eg. make release NEW_VERSION=0.x.0
|
||||||
mv *.sql old_versions
|
git mv *.sql old_versions
|
||||||
$(SED) $(REPLACEMENTS) $(EXTENSION).control
|
$(SED) $(REPLACEMENTS) $(EXTENSION).control
|
||||||
|
git add $(EXTENSION).control
|
||||||
cat $(SOURCES_DATA_DIR)/*.sql > $(EXTENSION)--$(NEW_VERSION).sql
|
cat $(SOURCES_DATA_DIR)/*.sql > $(EXTENSION)--$(NEW_VERSION).sql
|
||||||
|
git add $(EXTENSION)--$(NEW_VERSION).sql
|
||||||
$(ERB) version=$(NEW_VERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(EXTVERSION)--$(NEW_VERSION).sql
|
$(ERB) version=$(NEW_VERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(EXTVERSION)--$(NEW_VERSION).sql
|
||||||
$(ERB) version=$(EXTVERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(NEW_VERSION)--$(EXTVERSION).sql
|
$(ERB) version=$(EXTVERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(NEW_VERSION)--$(EXTVERSION).sql
|
||||||
|
|
||||||
|
|||||||
1782
client/cdb_dataservices_client--0.13.0--0.14.0.sql
Normal file
1782
client/cdb_dataservices_client--0.13.0--0.14.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
52
client/cdb_dataservices_client--0.14.0--0.13.0.sql
Normal file
52
client/cdb_dataservices_client--0.14.0--0.13.0.sql
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.13.0'" to load this file. \quit
|
||||||
|
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocode_admin0_polygon_exception_safe(country_name text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocode_admin1_polygon_exception_safe(admin1_name text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocode_admin1_polygon_exception_safe(admin1_name text, country_name text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocode_namedplace_point_exception_safe(city_name text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocode_namedplace_point_exception_safe(city_name text, country_name text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocode_namedplace_point_exception_safe(city_name text, admin1_name text, country_name text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocode_postalcode_polygon_exception_safe(postal_code text, country_name text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocode_postalcode_point_exception_safe(postal_code text, country_name text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocode_ipaddress_point_exception_safe(ip_address text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocode_street_point_exception_safe(searchtext text, city text, state_province text, country text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_here_geocode_street_point_exception_safe(searchtext text, city text, state_province text, country text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_google_geocode_street_point_exception_safe(searchtext text, city text, state_province text, country text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_mapzen_geocode_street_point_exception_safe(searchtext text, city text, state_province text, country text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_isodistance_exception_safe(source geometry(Geometry, 4326), mode text, range integer[], options text[]);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_isochrone_exception_safe(source geometry(Geometry, 4326), mode text, range integer[], options text[]);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_mapzen_isochrone_exception_safe(source geometry(Geometry, 4326), mode text, range integer[], options text[]);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_mapzen_isodistance_exception_safe(source geometry(Geometry, 4326), mode text, range integer[], options text[]);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_route_point_to_point_exception_safe(origin geometry(Point, 4326), destination geometry(Point, 4326), mode text, options text[], units text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_route_with_waypoints_exception_safe(waypoints geometry(Point, 4326)[], mode text, options text[], units text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_get_demographic_snapshot_exception_safe(geom geometry(Geometry, 4326), time_span text, geometry_level text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_get_segment_snapshot_exception_safe(geom geometry(Geometry, 4326), geometry_level text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getdemographicsnapshot_exception_safe(geom geometry(Geometry, 4326), time_span text, geometry_level text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getsegmentsnapshot_exception_safe(geom geometry(Geometry, 4326), geometry_level text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundary_exception_safe(geom geometry(Geometry, 4326), boundary_id text, time_span text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundaryid_exception_safe(geom geometry(Geometry, 4326), boundary_id text, time_span text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundarybyid_exception_safe(geometry_id text, boundary_id text, time_span text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundariesbygeometry_exception_safe(geom geometry(Geometry, 4326), boundary_id text, time_span text, overlap_type text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getboundariesbypointandradius_exception_safe(geom geometry(Geometry, 4326), radius numeric, boundary_id text, time_span text, overlap_type text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getpointsbygeometry_exception_safe(geom geometry(Geometry, 4326), boundary_id text, time_span text, overlap_type text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getpointsbypointandradius_exception_safe(geom geometry(Geometry, 4326), radius numeric, boundary_id text, time_span text, overlap_type text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getmeasure_exception_safe(geom Geometry, measure_id text, normalize text, boundary_id text, time_span text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getmeasurebyid_exception_safe(geom_ref text, measure_id text, boundary_id text, time_span text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getcategory_exception_safe(geom Geometry, category_id text, boundary_id text, time_span text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getuscensusmeasure_exception_safe(geom Geometry, name text, normalize text, boundary_id text, time_span text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getuscensuscategory_exception_safe(geom Geometry, name text, boundary_id text, time_span text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getpopulation_exception_safe(geom Geometry, normalize text, boundary_id text, time_span text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_search_exception_safe(search_term text, relevant_boundary text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailableboundaries_exception_safe(geom Geometry, timespan text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_dumpversion_exception_safe();
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailablenumerators_exception_safe(bounds geometry(Geometry, 4326), filter_tags text[], denom_id text, geom_id text, timespan text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailabledenominators_exception_safe(bounds geometry(Geometry, 4326), filter_tags text[], numer_id text, geom_id text, timespan text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailablegeometries_exception_safe(bounds geometry(Geometry, 4326), filter_tags text[], numer_id text, denom_id text, timespan text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailabletimespans_exception_safe(bounds geometry(Geometry, 4326), filter_tags text[], numer_id text, denom_id text, geom_id text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_legacybuildermetadata_exception_safe(aggregate_type text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_service_quota_info_exception_safe();
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_enough_quota_exception_safe(service TEXT, input_size NUMERIC);
|
||||||
|
|
||||||
3762
client/cdb_dataservices_client--0.14.0.sql
Normal file
3762
client/cdb_dataservices_client--0.14.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
comment = 'CartoDB dataservices client API extension'
|
comment = 'CartoDB dataservices client API extension'
|
||||||
default_version = '0.13.0'
|
default_version = '0.14.0'
|
||||||
requires = 'plproxy, cartodb'
|
requires = 'plproxy, cartodb'
|
||||||
superuser = true
|
superuser = true
|
||||||
schema = cdb_dataservices_client
|
schema = cdb_dataservices_client
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
--
|
||||||
|
-- Exception-safe private DataServices API function
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>_exception_safe (<%= params_with_type_and_default.join(' ,') %>)
|
||||||
|
RETURNS <%= return_type %> AS $$
|
||||||
|
DECLARE
|
||||||
|
<% if not multi_row %>ret <%= return_type %>;<% end %>
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
_returned_sqlstate TEXT;
|
||||||
|
_message_text TEXT;
|
||||||
|
_pg_exception_context TEXT;
|
||||||
|
BEGIN
|
||||||
|
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||||
|
RAISE EXCEPTION 'The api_key must be provided';
|
||||||
|
END IF;
|
||||||
|
SELECT u, o INTO username, orgname FROM <%= DATASERVICES_CLIENT_SCHEMA %>._cdb_entity_config() AS (u text, o text);
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
<% if multi_row %>
|
||||||
|
BEGIN
|
||||||
|
RETURN QUERY
|
||||||
|
SELECT * FROM <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= ['username', 'orgname'].concat(params).join(', ') %>);
|
||||||
|
EXCEPTION
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
GET STACKED DIAGNOSTICS _returned_sqlstate = RETURNED_SQLSTATE,
|
||||||
|
_message_text = MESSAGE_TEXT,
|
||||||
|
_pg_exception_context = PG_EXCEPTION_CONTEXT;
|
||||||
|
RAISE WARNING USING ERRCODE = _returned_sqlstate, MESSAGE = _message_text, DETAIL = _pg_exception_context;
|
||||||
|
END;
|
||||||
|
<% elsif multi_field %>
|
||||||
|
BEGIN
|
||||||
|
SELECT * FROM <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= ['username', 'orgname'].concat(params).join(', ') %>) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
GET STACKED DIAGNOSTICS _returned_sqlstate = RETURNED_SQLSTATE,
|
||||||
|
_message_text = MESSAGE_TEXT,
|
||||||
|
_pg_exception_context = PG_EXCEPTION_CONTEXT;
|
||||||
|
RAISE WARNING USING ERRCODE = _returned_sqlstate, MESSAGE = _message_text, DETAIL = _pg_exception_context;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
<% else %>
|
||||||
|
BEGIN
|
||||||
|
SELECT <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= ['username', 'orgname'].concat(params).join(', ') %>) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
GET STACKED DIAGNOSTICS _returned_sqlstate = RETURNED_SQLSTATE,
|
||||||
|
_message_text = MESSAGE_TEXT,
|
||||||
|
_pg_exception_context = PG_EXCEPTION_CONTEXT;
|
||||||
|
RAISE WARNING USING ERRCODE = _returned_sqlstate, MESSAGE = _message_text, DETAIL = _pg_exception_context;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
<% end %>
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
@@ -1 +1,2 @@
|
|||||||
GRANT EXECUTE ON FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %>(<%= params_with_type.join(', ') %>) TO publicuser;
|
GRANT EXECUTE ON FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %>(<%= params_with_type.join(', ') %>) TO publicuser;
|
||||||
|
GRANT EXECUTE ON FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>_exception_safe(<%= params_with_type.join(', ') %>) TO publicuser;
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
SET client_min_messages TO warning;
|
||||||
|
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||||
|
-- Mock the server functions to raise exceptions
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point (username text, orgname text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
BEGIN
|
||||||
|
RAISE EXCEPTION 'Not enough quota or any other exception whatsoever.';
|
||||||
|
RETURN NULL;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_isodistance(username text, orgname text, source geometry, mode text, range integer[], options text[] DEFAULT ARRAY[]::text[])
|
||||||
|
RETURNS SETOF isoline AS $$
|
||||||
|
BEGIN
|
||||||
|
RAISE EXCEPTION 'Not enough quota or any other exception whatsoever.';
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_point_to_point (username text, orgname text, origin geometry(Point, 4326), destination geometry(Point, 4326), mode TEXT, options text[] DEFAULT ARRAY[]::text[], units text DEFAULT 'kilometers')
|
||||||
|
RETURNS cdb_dataservices_client.simple_route AS $$
|
||||||
|
DECLARE
|
||||||
|
ret cdb_dataservices_client.simple_route;
|
||||||
|
BEGIN
|
||||||
|
RAISE EXCEPTION 'Not enough quota or any other exception whatsoever.';
|
||||||
|
|
||||||
|
-- This code shall never be reached
|
||||||
|
SELECT NULL, 5.33, 100 INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
-- Use regular user role
|
||||||
|
SET ROLE test_regular_user;
|
||||||
|
-- Exercise the exception safe and the proxied functions
|
||||||
|
SELECT _cdb_geocode_street_point_exception_safe('One street, 1');
|
||||||
|
WARNING: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE ERROR: Not enough quota or any other exception whatsoever.
|
||||||
|
DETAIL: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||||
|
PL/pgSQL function _cdb_geocode_street_point_exception_safe(text,text,text,text) line 21 at SQL statement
|
||||||
|
_cdb_geocode_street_point_exception_safe
|
||||||
|
------------------------------------------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT * FROM _cdb_isodistance_exception_safe('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300]::integer[]);
|
||||||
|
WARNING: cdb_dataservices_client._cdb_isodistance(6): [contrib_regression] REMOTE ERROR: Not enough quota or any other exception whatsoever.
|
||||||
|
DETAIL: PL/pgSQL function _cdb_isodistance_exception_safe(geometry,text,integer[],text[]) line 21 at RETURN QUERY
|
||||||
|
center | data_range | the_geom
|
||||||
|
--------+------------+----------
|
||||||
|
(0 rows)
|
||||||
|
|
||||||
|
SELECT * FROM _cdb_route_point_to_point_exception_safe('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
|
||||||
|
WARNING: cdb_dataservices_client._cdb_route_point_to_point(7): [contrib_regression] REMOTE ERROR: Not enough quota or any other exception whatsoever.
|
||||||
|
DETAIL: SQL statement "SELECT * FROM cdb_dataservices_client._cdb_route_point_to_point(username, orgname, origin, destination, mode, options, units)"
|
||||||
|
PL/pgSQL function _cdb_route_point_to_point_exception_safe(geometry,geometry,text,text[],text) line 21 at SQL statement
|
||||||
|
shape | length | duration
|
||||||
|
-------+--------+----------
|
||||||
|
| |
|
||||||
|
(1 row)
|
||||||
|
|
||||||
41
client/test/sql/25_exception_safe_private_functions_test.sql
Normal file
41
client/test/sql/25_exception_safe_private_functions_test.sql
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
SET client_min_messages TO warning;
|
||||||
|
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||||
|
|
||||||
|
-- Mock the server functions to raise exceptions
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point (username text, orgname text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
BEGIN
|
||||||
|
RAISE EXCEPTION 'Not enough quota or any other exception whatsoever.';
|
||||||
|
RETURN NULL;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_isodistance(username text, orgname text, source geometry, mode text, range integer[], options text[] DEFAULT ARRAY[]::text[])
|
||||||
|
RETURNS SETOF isoline AS $$
|
||||||
|
BEGIN
|
||||||
|
RAISE EXCEPTION 'Not enough quota or any other exception whatsoever.';
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_point_to_point (username text, orgname text, origin geometry(Point, 4326), destination geometry(Point, 4326), mode TEXT, options text[] DEFAULT ARRAY[]::text[], units text DEFAULT 'kilometers')
|
||||||
|
RETURNS cdb_dataservices_client.simple_route AS $$
|
||||||
|
DECLARE
|
||||||
|
ret cdb_dataservices_client.simple_route;
|
||||||
|
BEGIN
|
||||||
|
RAISE EXCEPTION 'Not enough quota or any other exception whatsoever.';
|
||||||
|
|
||||||
|
-- This code shall never be reached
|
||||||
|
SELECT NULL, 5.33, 100 INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Use regular user role
|
||||||
|
SET ROLE test_regular_user;
|
||||||
|
|
||||||
|
-- Exercise the exception safe and the proxied functions
|
||||||
|
SELECT _cdb_geocode_street_point_exception_safe('One street, 1');
|
||||||
|
SELECT * FROM _cdb_isodistance_exception_safe('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300]::integer[]);
|
||||||
|
SELECT * FROM _cdb_route_point_to_point_exception_safe('POINT(-3.70237112 40.41706163)'::geometry,'POINT(-3.69909883 40.41236875)'::geometry, 'car', ARRAY['mode_type=shortest']::text[]);
|
||||||
@@ -18,7 +18,7 @@ class HereMapsGeocoder(Traceable):
|
|||||||
DEFAULT_GEN = 9
|
DEFAULT_GEN = 9
|
||||||
READ_TIMEOUT = 60
|
READ_TIMEOUT = 60
|
||||||
CONNECT_TIMEOUT = 10
|
CONNECT_TIMEOUT = 10
|
||||||
MAX_RETRIES=3
|
MAX_RETRIES=1
|
||||||
|
|
||||||
ADDRESS_PARAMS = [
|
ADDRESS_PARAMS = [
|
||||||
'city',
|
'city',
|
||||||
@@ -92,7 +92,7 @@ class HereMapsGeocoder(Traceable):
|
|||||||
request_params.update(params)
|
request_params.update(params)
|
||||||
# TODO Extract HTTP client wrapper
|
# TODO Extract HTTP client wrapper
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.mount(self.host, HTTPAdapter(self.MAX_RETRIES))
|
session.mount(self.host, HTTPAdapter(max_retries=self.MAX_RETRIES))
|
||||||
response = session.get(self.host, params=request_params,
|
response = session.get(self.host, params=request_params,
|
||||||
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
self.add_response_data(response, self._logger)
|
self.add_response_data(response, self._logger)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class HereMapsRoutingIsoline(Traceable):
|
|||||||
ISOLINE_PATH = '/routing/7.2/calculateisoline.json'
|
ISOLINE_PATH = '/routing/7.2/calculateisoline.json'
|
||||||
READ_TIMEOUT = 60
|
READ_TIMEOUT = 60
|
||||||
CONNECT_TIMEOUT = 10
|
CONNECT_TIMEOUT = 10
|
||||||
MAX_RETRIES = 3
|
MAX_RETRIES = 1
|
||||||
|
|
||||||
ACCEPTED_MODES = {
|
ACCEPTED_MODES = {
|
||||||
"walk": "pedestrian",
|
"walk": "pedestrian",
|
||||||
@@ -57,7 +57,7 @@ class HereMapsRoutingIsoline(Traceable):
|
|||||||
parsed_options)
|
parsed_options)
|
||||||
# TODO Extract HTTP client wrapper
|
# TODO Extract HTTP client wrapper
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.mount(self._url, HTTPAdapter(self.MAX_RETRIES))
|
session.mount(self._url, HTTPAdapter(max_retries=self.MAX_RETRIES))
|
||||||
response = requests.get(self._url, params=request_params,
|
response = requests.get(self._url, params=request_params,
|
||||||
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
self.add_response_data(response, self._logger)
|
self.add_response_data(response, self._logger)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class MapzenGeocoder(Traceable):
|
|||||||
BASE_URL = 'https://search.mapzen.com/v1/search'
|
BASE_URL = 'https://search.mapzen.com/v1/search'
|
||||||
READ_TIMEOUT = 60
|
READ_TIMEOUT = 60
|
||||||
CONNECT_TIMEOUT = 10
|
CONNECT_TIMEOUT = 10
|
||||||
MAX_RETRIES = 3
|
MAX_RETRIES = 1
|
||||||
|
|
||||||
def __init__(self, app_key, logger, base_url=BASE_URL):
|
def __init__(self, app_key, logger, base_url=BASE_URL):
|
||||||
self._app_key = app_key
|
self._app_key = app_key
|
||||||
@@ -31,7 +31,7 @@ class MapzenGeocoder(Traceable):
|
|||||||
try:
|
try:
|
||||||
# TODO Extract HTTP client wrapper
|
# TODO Extract HTTP client wrapper
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.mount(self._url, HTTPAdapter(self.MAX_RETRIES))
|
session.mount(self._url, HTTPAdapter(max_retries=self.MAX_RETRIES))
|
||||||
response = session.get(self._url, params=request_params,
|
response = session.get(self._url, params=request_params,
|
||||||
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
self.add_response_data(response, self._logger)
|
self.add_response_data(response, self._logger)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class MapzenIsochrones:
|
|||||||
try:
|
try:
|
||||||
# TODO Extract HTTP client wrapper
|
# TODO Extract HTTP client wrapper
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.mount(self._url, HTTPAdapter(self.MAX_RETRIES))
|
session.mount(self._url, HTTPAdapter(max_retries=self.MAX_RETRIES))
|
||||||
response = session.get(self._url, params=request_params,
|
response = session.get(self._url, params=request_params,
|
||||||
timeout=(self.CONNECT_TIMEOUT,
|
timeout=(self.CONNECT_TIMEOUT,
|
||||||
self.READ_TIMEOUT))
|
self.READ_TIMEOUT))
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class MapzenRouting(Traceable):
|
|||||||
PRODUCTION_ROUTING_BASE_URL = 'https://valhalla.mapzen.com/route'
|
PRODUCTION_ROUTING_BASE_URL = 'https://valhalla.mapzen.com/route'
|
||||||
READ_TIMEOUT = 60
|
READ_TIMEOUT = 60
|
||||||
CONNECT_TIMEOUT = 10
|
CONNECT_TIMEOUT = 10
|
||||||
MAX_RETRIES=3
|
MAX_RETRIES=1
|
||||||
|
|
||||||
ACCEPTED_MODES = {
|
ACCEPTED_MODES = {
|
||||||
"walk": "pedestrian",
|
"walk": "pedestrian",
|
||||||
@@ -50,7 +50,7 @@ class MapzenRouting(Traceable):
|
|||||||
request_params = self.__parse_request_parameters(json_request_params)
|
request_params = self.__parse_request_parameters(json_request_params)
|
||||||
# TODO Extract HTTP client wrapper
|
# TODO Extract HTTP client wrapper
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.mount(self._url, HTTPAdapter(self.MAX_RETRIES))
|
session.mount(self._url, HTTPAdapter(max_retries=self.MAX_RETRIES))
|
||||||
response = session.get(self._url, params=request_params,
|
response = session.get(self._url, params=request_params,
|
||||||
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
self.add_response_data(response, self._logger)
|
self.add_response_data(response, self._logger)
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
|
from calendar import monthrange
|
||||||
|
|
||||||
|
def last_day_of_month(year, month):
|
||||||
|
"""last valid day of a month"""
|
||||||
|
return monthrange(year, month)[1]
|
||||||
|
|
||||||
|
def latest_valid_date(year, month, day):
|
||||||
|
"""latest date not later than the day specified"""
|
||||||
|
valid_day = min(day, last_day_of_month(year, month))
|
||||||
|
return date(year, month, valid_day)
|
||||||
|
|
||||||
class UserMetricsService:
|
class UserMetricsService:
|
||||||
""" Class to manage all the user info """
|
""" Class to manage all the user info """
|
||||||
@@ -143,9 +152,9 @@ class UserMetricsService:
|
|||||||
today = date.today()
|
today = date.today()
|
||||||
if end_period_day > today.day:
|
if end_period_day > today.day:
|
||||||
temp_date = today + relativedelta(months=-1)
|
temp_date = today + relativedelta(months=-1)
|
||||||
date_from = date(temp_date.year, temp_date.month, end_period_day)
|
date_from = latest_valid_date(temp_date.year, temp_date.month, end_period_day)
|
||||||
else:
|
else:
|
||||||
date_from = date(today.year, today.month, end_period_day)
|
date_from = latest_valid_date(today.year, today.month, end_period_day)
|
||||||
|
|
||||||
return date_from, today
|
return date_from, today
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from setuptools import setup, find_packages
|
|||||||
setup(
|
setup(
|
||||||
name='cartodb_services',
|
name='cartodb_services',
|
||||||
|
|
||||||
version='0.12.2',
|
version='0.12.4',
|
||||||
|
|
||||||
description='CartoDB Services API Python Library',
|
description='CartoDB Services API Python Library',
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ class TestUserService(TestCase):
|
|||||||
amount=400)
|
amount=400)
|
||||||
assert us.used_quota(self.NOKIA_GEOCODER, date.today()) == 400
|
assert us.used_quota(self.NOKIA_GEOCODER, date.today()) == 400
|
||||||
|
|
||||||
|
def test_user_quota_for_a_month_shorter_than_end_day(self):
|
||||||
|
us = self.__build_user_service('test_user', end_date=date(2016,1,31))
|
||||||
|
assert us.used_quota(self.NOKIA_GEOCODER, date(2016,2,10)) == 0
|
||||||
|
|
||||||
def test_org_used_quota_for_a_day(self):
|
def test_org_used_quota_for_a_day(self):
|
||||||
us = self.__build_user_service('test_user', orgname='test_org')
|
us = self.__build_user_service('test_user', orgname='test_org')
|
||||||
increment_service_uses(self.redis_conn, 'test_user',
|
increment_service_uses(self.redis_conn, 'test_user',
|
||||||
@@ -30,6 +34,10 @@ class TestUserService(TestCase):
|
|||||||
amount=400)
|
amount=400)
|
||||||
assert us.used_quota(self.NOKIA_GEOCODER, date.today()) == 400
|
assert us.used_quota(self.NOKIA_GEOCODER, date.today()) == 400
|
||||||
|
|
||||||
|
def test_org_quota_quota_for_a_month_shorter_than_end_day(self):
|
||||||
|
us = self.__build_user_service('test_user', orgname='test_org', end_date=date(2016,1,31))
|
||||||
|
assert us.used_quota(self.NOKIA_GEOCODER, date(2016,2,10)) == 0
|
||||||
|
|
||||||
def test_user_not_amount_in_used_quota_for_month_should_be_0(self):
|
def test_user_not_amount_in_used_quota_for_month_should_be_0(self):
|
||||||
us = self.__build_user_service('test_user')
|
us = self.__build_user_service('test_user')
|
||||||
assert us.used_quota(self.NOKIA_GEOCODER, date.today()) == 0
|
assert us.used_quota(self.NOKIA_GEOCODER, date.today()) == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user