From 247034c21e1d14d8f6eb0d1fa1579c931f7edaa7 Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Wed, 19 Oct 2016 18:11:37 +0200 Subject: [PATCH] Some tests for RoutingConfig #281 --- .../cartodb_services/test/metrics/__init__.py | 0 .../test/metrics/test_config.py | 50 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 server/lib/python/cartodb_services/test/metrics/__init__.py create mode 100644 server/lib/python/cartodb_services/test/metrics/test_config.py diff --git a/server/lib/python/cartodb_services/test/metrics/__init__.py b/server/lib/python/cartodb_services/test/metrics/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server/lib/python/cartodb_services/test/metrics/test_config.py b/server/lib/python/cartodb_services/test/metrics/test_config.py new file mode 100644 index 0000000..62e3301 --- /dev/null +++ b/server/lib/python/cartodb_services/test/metrics/test_config.py @@ -0,0 +1,50 @@ +from unittest import TestCase +from mockredis import MockRedis +from cartodb_services.metrics import RoutingConfig +from ..test_helper import build_plpy_mock + +class TestRoutingConfig(TestCase): + + def setUp(self): + self._redis_conn = MockRedis() + self._db_conn = build_plpy_mock() + self._username = 'my_test_user' + self._user_key = "rails:users:{0}".format(self._username) + self._redis_conn.hset(self._user_key, 'period_end_date', '2016-10-10') + + def test_should_pick_quota_from_server_by_default(self): + orgname = None + config = RoutingConfig(self._redis_conn, self._db_conn, self._username, orgname) + assert config.monthly_quota == 1500000 + + def test_should_pick_quota_from_redis_if_present(self): + self._redis_conn.hset(self._user_key, 'mapzen_routing_quota', 1000) + orgname = None + config = RoutingConfig(self._redis_conn, self._db_conn, self._username, orgname) + assert config.monthly_quota == 1000 + + def test_org_quota_overrides_user_quota(self): + self._redis_conn.hset(self._user_key, 'mapzen_routing_quota', 1000) + orgname = 'my_test_org' + orgname_key = "rails:orgs:{0}".format(orgname) + self._redis_conn.hset(orgname_key, 'period_end_date', '2016-05-31') + self._redis_conn.hset(orgname_key, 'mapzen_routing_quota', 5000) + + # TODO: these are not too relevant for the routing config + self._redis_conn.hset(orgname_key, 'geocoding_quota', 0) + self._redis_conn.hset(orgname_key, 'here_isolines_quota', 0) + + config = RoutingConfig(self._redis_conn, self._db_conn, self._username, orgname) + assert config.monthly_quota == 5000 + + + def test_should_have_soft_limit_false_by_default(self): + orgname = None + config = RoutingConfig(self._redis_conn, self._db_conn, self._username, orgname) + assert config.soft_limit == False + + def test_can_set_soft_limit_in_user_conf(self): + self._redis_conn.hset(self._user_key, 'soft_mapzen_routing_limit', True) + orgname = None + config = RoutingConfig(self._redis_conn, self._db_conn, self._username, orgname) + assert config.soft_limit == True