Refactor to move logic from SQL functions to Python

- Moved the logic the retrieve the redis connection params to
  RedisDBConfig class
- Moved the logic that retrieve the services configuration to
  ServicesDBConfig
This commit is contained in:
Mario de Frutos
2016-03-08 12:24:27 +01:00
parent ac1627b5c5
commit b97e838416
13 changed files with 445 additions and 141 deletions

View File

@@ -1,4 +1,5 @@
from datetime import datetime, date
from mock import Mock
def build_redis_user_config(redis_conn, username, quota=100, soft_limit=False,
@@ -31,3 +32,18 @@ def increment_geocoder_uses(redis_conn, username, orgname=None,
redis_name = "{0}:{1}:{2}:{3}:{4}".format(prefix, entity_name,
service, metric, yearmonth)
redis_conn.zincrby(redis_name, date.day, amount)
def build_plpy_mock(empty=False):
plpy_mock = Mock()
if not empty:
plpy_mock.execute.side_effect = _plpy_execute_side_effect
return plpy_mock
def _plpy_execute_side_effect(*args, **kwargs):
if args[0] == 'SELECT cartodb.CDB_Conf_GetConf(heremaps_conf) as conf':
return [{'conf': '{"app_id": "app_id", "app_code": "code"}'}]
elif args[0] == 'SELECT cartodb.CDB_Conf_GetConf(mapzen_conf) as conf':
return [{'conf': '{"routing_app_key": "app_key"}'}]