2016-11-04 19:14:48 +08:00
|
|
|
from test_helper import *
|
2015-11-17 20:57:03 +08:00
|
|
|
from unittest import TestCase
|
|
|
|
from nose.tools import assert_raises
|
2016-01-22 01:07:27 +08:00
|
|
|
from mockredis import MockRedis
|
|
|
|
from datetime import datetime, timedelta
|
2016-11-04 19:14:48 +08:00
|
|
|
from cartodb_services.metrics import GeocoderConfig, ObservatorySnapshotConfig, ConfigException
|
2015-11-17 20:57:03 +08:00
|
|
|
|
|
|
|
|
2016-01-29 18:54:50 +08:00
|
|
|
class TestConfig(TestCase):
|
2015-11-17 20:57:03 +08:00
|
|
|
|
2016-01-22 01:07:27 +08:00
|
|
|
def setUp(self):
|
|
|
|
self.redis_conn = MockRedis()
|
2016-11-04 19:14:48 +08:00
|
|
|
plpy_mock_config()
|
2016-01-22 01:07:27 +08:00
|
|
|
|
|
|
|
def test_should_return_list_of_nokia_geocoder_config_if_its_ok(self):
|
2016-11-04 19:14:48 +08:00
|
|
|
build_redis_user_config(self.redis_conn, 'test_user')
|
|
|
|
geocoder_config = GeocoderConfig(self.redis_conn, plpy_mock,
|
2016-03-08 19:24:27 +08:00
|
|
|
'test_user', None)
|
2016-01-29 18:54:50 +08:00
|
|
|
assert geocoder_config.heremaps_geocoder is True
|
2016-01-22 01:07:27 +08:00
|
|
|
assert geocoder_config.geocoding_quota == 100
|
2016-01-29 18:54:50 +08:00
|
|
|
assert geocoder_config.soft_geocoding_limit is False
|
2016-01-22 01:07:27 +08:00
|
|
|
|
|
|
|
def test_should_return_list_of_nokia_geocoder_config_ok_for_org(self):
|
|
|
|
yesterday = datetime.today() - timedelta(days=1)
|
2016-11-04 19:14:48 +08:00
|
|
|
build_redis_user_config(self.redis_conn, 'test_user')
|
|
|
|
build_redis_org_config(self.redis_conn, 'test_org',
|
|
|
|
quota=200, end_date=yesterday)
|
|
|
|
geocoder_config = GeocoderConfig(self.redis_conn, plpy_mock,
|
2016-03-08 19:24:27 +08:00
|
|
|
'test_user', 'test_org')
|
2016-01-29 18:54:50 +08:00
|
|
|
assert geocoder_config.heremaps_geocoder is True
|
2016-01-22 01:07:27 +08:00
|
|
|
assert geocoder_config.geocoding_quota == 200
|
2016-01-29 18:54:50 +08:00
|
|
|
assert geocoder_config.soft_geocoding_limit is False
|
2016-01-22 01:07:27 +08:00
|
|
|
assert geocoder_config.period_end_date.date() == yesterday.date()
|
|
|
|
|
2016-04-22 22:43:28 +08:00
|
|
|
def test_should_return_config_for_obs_snapshot(self):
|
|
|
|
yesterday = datetime.today() - timedelta(days=1)
|
2016-11-04 19:14:48 +08:00
|
|
|
build_redis_user_config(self.redis_conn, 'test_user',
|
|
|
|
do_quota=100, soft_do_limit=True,
|
|
|
|
end_date=yesterday)
|
|
|
|
do_config = ObservatorySnapshotConfig(self.redis_conn, plpy_mock,
|
2016-04-22 22:43:28 +08:00
|
|
|
'test_user')
|
|
|
|
assert do_config.monthly_quota == 100
|
|
|
|
assert do_config.soft_limit is True
|
|
|
|
assert do_config.period_end_date.date() == yesterday.date()
|
|
|
|
|
|
|
|
def test_should_return_db_quota_if_not_redis_quota_config_obs_snapshot(self):
|
|
|
|
yesterday = datetime.today() - timedelta(days=1)
|
2016-11-04 19:14:48 +08:00
|
|
|
build_redis_user_config(self.redis_conn, 'test_user',
|
|
|
|
end_date=yesterday)
|
|
|
|
do_config = ObservatorySnapshotConfig(self.redis_conn, plpy_mock,
|
2016-04-22 22:43:28 +08:00
|
|
|
'test_user')
|
2016-05-11 17:50:21 +08:00
|
|
|
assert do_config.monthly_quota == 0
|
2016-04-22 22:43:28 +08:00
|
|
|
assert do_config.soft_limit is False
|
|
|
|
assert do_config.period_end_date.date() == yesterday.date()
|
|
|
|
|
2016-03-08 19:24:27 +08:00
|
|
|
def test_should_raise_exception_when_missing_parameters(self):
|
2016-11-04 19:14:48 +08:00
|
|
|
plpy_mock._reset()
|
|
|
|
build_redis_user_config(self.redis_conn, 'test_user')
|
2016-04-22 22:43:28 +08:00
|
|
|
assert_raises(ConfigException, GeocoderConfig, self.redis_conn,
|
|
|
|
plpy_mock, 'test_user', None)
|