Merge branch 'development'
This commit is contained in:
commit
500d860f46
@ -40,7 +40,11 @@ OK
|
||||
```
|
||||
|
||||
## Running the integration tests
|
||||
TBD
|
||||
See the [[../../../../test/README.md]]. Basically, move to the `/test` directory at the top level of this repo and execute the `run_tests.py` script:
|
||||
```sh
|
||||
cd $(git rev-parse --show-toplevel)/test
|
||||
python run_tests.py --host=$YOUR_HOST $YOUR_USERNAME $YOUR_API_KEY
|
||||
```
|
||||
|
||||
## TODO
|
||||
- Move dependencies expressed in `requirements.txt` to `setup.py`
|
||||
|
@ -8,6 +8,7 @@ class UserMetricsService:
|
||||
SERVICE_GEOCODER_NOKIA = 'geocoder_here'
|
||||
SERVICE_GEOCODER_CACHE = 'geocoder_cache'
|
||||
SERVICE_HERE_ISOLINES = 'here_isolines'
|
||||
DAY_OF_MONTH_ZERO_PADDED = '%d'
|
||||
|
||||
def __init__(self, user_geocoder_config, redis_connection):
|
||||
self._user_geocoder_config = user_geocoder_config
|
||||
@ -85,7 +86,7 @@ class UserMetricsService:
|
||||
service, metric, date)
|
||||
score = self._redis_connection.zscore(redis_prefix, date.day)
|
||||
aggregated_metric += score if score else 0
|
||||
zero_padded_day = date.strftime('%d')
|
||||
zero_padded_day = date.strftime(self.DAY_OF_MONTH_ZERO_PADDED)
|
||||
if str(date.day) != zero_padded_day:
|
||||
score = self._redis_connection.zscore(redis_prefix, zero_padded_day)
|
||||
aggregated_metric += score if score else 0
|
||||
@ -97,12 +98,16 @@ class UserMetricsService:
|
||||
def __increment_user_uses(self, service_type, metric, date, amount):
|
||||
redis_prefix = self.__parse_redis_prefix("user", self._username,
|
||||
service_type, metric, date)
|
||||
self._redis_connection.zincrby(redis_prefix, date.day, amount)
|
||||
self._redis_connection.zincrby(redis_prefix,
|
||||
date.strftime(self.DAY_OF_MONTH_ZERO_PADDED),
|
||||
amount)
|
||||
|
||||
def __increment_organization_uses(self, service_type, metric, date, amount):
|
||||
redis_prefix = self.__parse_redis_prefix("org", self._orgname,
|
||||
service_type, metric, date)
|
||||
self._redis_connection.zincrby(redis_prefix, date.day, amount)
|
||||
self._redis_connection.zincrby(redis_prefix,
|
||||
date.strftime(self.DAY_OF_MONTH_ZERO_PADDED),
|
||||
amount)
|
||||
|
||||
def __parse_redis_prefix(self, prefix, entity_name, service_type, metric,
|
||||
date):
|
||||
|
@ -10,7 +10,7 @@ from setuptools import setup, find_packages
|
||||
setup(
|
||||
name='cartodb_services',
|
||||
|
||||
version='0.6.3',
|
||||
version='0.6.4',
|
||||
|
||||
description='CartoDB Services API Python Library',
|
||||
|
||||
|
@ -116,6 +116,21 @@ class TestUserService(TestCase):
|
||||
#('user:test_user:geocoder_cache:success_responses:201506', 15)
|
||||
assert self.redis_conn.zscore_counter() == 3
|
||||
|
||||
def test_should_write_zero_padded_dates(self):
|
||||
us = self.__build_user_service('test_user')
|
||||
us.increment_service_use(self.NOKIA_GEOCODER, 'success_responses',
|
||||
date=date(2015,6,1))
|
||||
assert self.redis_conn.zscore('user:test_user:geocoder_here:success_responses:201506', '01') == 1
|
||||
assert self.redis_conn.zscore('user:test_user:geocoder_here:success_responses:201506', '1') == None
|
||||
|
||||
def test_orgs_should_write_zero_padded_dates(self):
|
||||
us = self.__build_user_service('test_user', orgname='test_org')
|
||||
us.increment_service_use(self.NOKIA_GEOCODER, 'success_responses',
|
||||
amount=400,
|
||||
date=date(2015,6,1))
|
||||
assert self.redis_conn.zscore('org:test_org:geocoder_here:success_responses:201506', '01') == 400
|
||||
assert self.redis_conn.zscore('org:test_org:geocoder_here:success_responses:201506', '1') == None
|
||||
|
||||
|
||||
def __build_user_service(self, username, quota=100, service='heremaps',
|
||||
orgname=None, soft_limit=False,
|
||||
|
Loading…
Reference in New Issue
Block a user