Compare commits
14 Commits
0.14.0-cli
...
0.14.1-cli
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
439f604a04 | ||
|
|
9791a5bada | ||
|
|
629555e193 | ||
|
|
af993fde55 | ||
|
|
4be6c9f31d | ||
|
|
ed1386d571 | ||
|
|
32010669e8 | ||
|
|
b0f10d1680 | ||
|
|
18df3368ef | ||
|
|
b5514aea60 | ||
|
|
53acd4d30e | ||
|
|
6e134d1ea6 | ||
|
|
59ae4a5492 | ||
|
|
b3e67afd92 |
9
client/cdb_dataservices_client--0.14.0--0.14.1.sql
Normal file
9
client/cdb_dataservices_client--0.14.0--0.14.1.sql
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
--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.14.1'" to load this file. \quit
|
||||||
|
|
||||||
|
-- Make sure we have a sane search path to create/update the extension
|
||||||
|
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
|
||||||
|
|
||||||
|
-- This release introduces no changes other than the use of
|
||||||
|
-- search path in the install and migration scripts
|
||||||
9
client/cdb_dataservices_client--0.14.1--0.14.0.sql
Normal file
9
client/cdb_dataservices_client--0.14.1--0.14.0.sql
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
--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.14.0'" to load this file. \quit
|
||||||
|
|
||||||
|
-- Make sure we have a sane search path to create/update the extension
|
||||||
|
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
|
||||||
|
|
||||||
|
-- This release introduces no changes other than the use of
|
||||||
|
-- search path in the install and migration scripts
|
||||||
3765
client/cdb_dataservices_client--0.14.1.sql
Normal file
3765
client/cdb_dataservices_client--0.14.1.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.14.0'
|
default_version = '0.14.1'
|
||||||
requires = 'plproxy, cartodb'
|
requires = 'plproxy, cartodb'
|
||||||
superuser = true
|
superuser = true
|
||||||
schema = cdb_dataservices_client
|
schema = cdb_dataservices_client
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
\echo Use "CREATE EXTENSION cdb_dataservices_client" to load this file. \quit
|
\echo Use "CREATE EXTENSION cdb_dataservices_client" to load this file. \quit
|
||||||
|
|
||||||
|
-- Make sure we have a sane search path to create/update the extension
|
||||||
|
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
|
||||||
|
|||||||
@@ -2,4 +2,7 @@
|
|||||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '<%= version %>'" to load this file. \quit
|
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '<%= version %>'" to load this file. \quit
|
||||||
|
|
||||||
|
-- Make sure we have a sane search path to create/update the extension
|
||||||
|
SET search_path = "$user",cartodb,public,cdb_dataservices_client;
|
||||||
|
|
||||||
-- HERE goes your code to upgrade/downgrade
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
|||||||
36
doc/internal/exception_safe.md
Normal file
36
doc/internal/exception_safe.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Exception-Safe functions
|
||||||
|
|
||||||
|
The public API dataservices functions emit exceptions in general when an error occurs
|
||||||
|
or a limiting condition is met (e.g. quotas are exceeded).
|
||||||
|
|
||||||
|
For each public function `func` we have a internal function named `_func_exception_safe` which
|
||||||
|
acts as a wrapper to the public function, with the same signature, but captures
|
||||||
|
exceptions generated during its execution (except those due to incomplete configuration or
|
||||||
|
authentication issues) and returns NULL or empty set values in those cases.
|
||||||
|
|
||||||
|
Please note these functions are considered **not public** and therefore their API (including which exceptions are wrapped and which ones are not) may change.
|
||||||
|
|
||||||
|
Instead of raising an exception they raise warnings, hopefully containing the same information of the original exception.
|
||||||
|
|
||||||
|
## Intended Use
|
||||||
|
|
||||||
|
These functions are useful in cases when it is undesirable to rollback a transaction.
|
||||||
|
Fo example if a table is geocoded with:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
UPDATE table SET the_geom=cdb_geocode_street_point(user,NULL,address,city,NULL,country);
|
||||||
|
```
|
||||||
|
|
||||||
|
In case of the user geocoding quota being exhausted mid-process, the user could
|
||||||
|
incur in external service expenses but any geocoded data would be lost due to the
|
||||||
|
transaction rollback.
|
||||||
|
|
||||||
|
We can avoid the problem using the corresponding exception-safe function:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
UPDATE table SET the_geom=_cdb_geocode_street_point_exception_safe(user,NULL,address,city,NULL,country);
|
||||||
|
```
|
||||||
|
|
||||||
|
# Addition Information
|
||||||
|
|
||||||
|
See https://github.com/CartoDB/dataservices-api/issues/314 for more information.
|
||||||
@@ -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.3',
|
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