Fix test: make it independent of current date #281
This commit is contained in:
@@ -14,40 +14,41 @@ class RoutingConfigMock(object):
|
|||||||
|
|
||||||
class TestQuotaChecker(TestCase):
|
class TestQuotaChecker(TestCase):
|
||||||
|
|
||||||
USERNAME = 'my_test_user'
|
def setUp(self):
|
||||||
PERIOD_END_DATE = datetime(2016,10,20)
|
self.username = 'my_test_user'
|
||||||
SERVICE_TYPE = 'routing_mapzen'
|
self.period_end_date = datetime.today()
|
||||||
REDIS_KEY = 'user:{0}:{1}:success_responses:{2}{3}'.format(
|
self.service_type = 'routing_mapzen'
|
||||||
USERNAME,
|
self.redis_key = 'user:{0}:{1}:success_responses:{2}{3}'.format(
|
||||||
SERVICE_TYPE,
|
self.username,
|
||||||
PERIOD_END_DATE.year,
|
self.service_type,
|
||||||
PERIOD_END_DATE.month
|
self.period_end_date.year,
|
||||||
)
|
self.period_end_date.month
|
||||||
|
)
|
||||||
|
|
||||||
def test_routing_quota_check_passes_when_enough_quota(self):
|
def test_routing_quota_check_passes_when_enough_quota(self):
|
||||||
user_service_config = RoutingConfigMock(
|
user_service_config = RoutingConfigMock(
|
||||||
username = self.USERNAME,
|
username = self.username,
|
||||||
organization = None,
|
organization = None,
|
||||||
service_type = self.SERVICE_TYPE,
|
service_type = self.service_type,
|
||||||
monthly_quota = 1000,
|
monthly_quota = 1000,
|
||||||
period_end_date = datetime.today(),
|
period_end_date = datetime.today(),
|
||||||
soft_limit = False
|
soft_limit = False
|
||||||
)
|
)
|
||||||
redis_conn = MockRedis()
|
redis_conn = MockRedis()
|
||||||
redis_conn.zincrby(self.REDIS_KEY, self.PERIOD_END_DATE.day, 999)
|
redis_conn.zincrby(self.redis_key, self.period_end_date.day, 999)
|
||||||
assert QuotaChecker(user_service_config, redis_conn).check() == True
|
assert QuotaChecker(user_service_config, redis_conn).check() == True
|
||||||
|
|
||||||
def test_routing_quota_check_fails_when_quota_exhausted(self):
|
def test_routing_quota_check_fails_when_quota_exhausted(self):
|
||||||
user_service_config = RoutingConfigMock(
|
user_service_config = RoutingConfigMock(
|
||||||
username = self.USERNAME,
|
username = self.username,
|
||||||
organization = None,
|
organization = None,
|
||||||
service_type = self.SERVICE_TYPE,
|
service_type = self.service_type,
|
||||||
monthly_quota = 1000,
|
monthly_quota = 1000,
|
||||||
period_end_date = datetime.today(),
|
period_end_date = datetime.today(),
|
||||||
soft_limit = False
|
soft_limit = False
|
||||||
)
|
)
|
||||||
redis_conn = MockRedis()
|
redis_conn = MockRedis()
|
||||||
redis_conn.zincrby(self.REDIS_KEY, self.PERIOD_END_DATE.day, 1001)
|
redis_conn.zincrby(self.redis_key, self.period_end_date.day, 1001)
|
||||||
checker = QuotaChecker(user_service_config, redis_conn)
|
checker = QuotaChecker(user_service_config, redis_conn)
|
||||||
assert checker.check() == False
|
assert checker.check() == False
|
||||||
|
|
||||||
@@ -57,28 +58,28 @@ class TestQuotaChecker(TestCase):
|
|||||||
the check to perform the 1001th routing operation.
|
the check to perform the 1001th routing operation.
|
||||||
"""
|
"""
|
||||||
user_service_config = RoutingConfigMock(
|
user_service_config = RoutingConfigMock(
|
||||||
username = self.USERNAME,
|
username = self.username,
|
||||||
organization = None,
|
organization = None,
|
||||||
service_type = self.SERVICE_TYPE,
|
service_type = self.service_type,
|
||||||
monthly_quota = 1000,
|
monthly_quota = 1000,
|
||||||
period_end_date = datetime.today(),
|
period_end_date = datetime.today(),
|
||||||
soft_limit = False
|
soft_limit = False
|
||||||
)
|
)
|
||||||
redis_conn = MockRedis()
|
redis_conn = MockRedis()
|
||||||
redis_conn.zincrby(self.REDIS_KEY, self.PERIOD_END_DATE.day, 1000)
|
redis_conn.zincrby(self.redis_key, self.period_end_date.day, 1000)
|
||||||
checker = QuotaChecker(user_service_config, redis_conn)
|
checker = QuotaChecker(user_service_config, redis_conn)
|
||||||
assert checker.check() == False
|
assert checker.check() == False
|
||||||
|
|
||||||
def test_routing_quota_check_passes_if_no_quota_but_soft_limit(self):
|
def test_routing_quota_check_passes_if_no_quota_but_soft_limit(self):
|
||||||
user_service_config = RoutingConfigMock(
|
user_service_config = RoutingConfigMock(
|
||||||
username = self.USERNAME,
|
username = self.username,
|
||||||
organization = None,
|
organization = None,
|
||||||
service_type = self.SERVICE_TYPE,
|
service_type = self.service_type,
|
||||||
monthly_quota = 1000,
|
monthly_quota = 1000,
|
||||||
period_end_date = datetime.today(),
|
period_end_date = datetime.today(),
|
||||||
soft_limit = True
|
soft_limit = True
|
||||||
)
|
)
|
||||||
redis_conn = MockRedis()
|
redis_conn = MockRedis()
|
||||||
redis_conn.zincrby(self.REDIS_KEY, self.PERIOD_END_DATE.day, 1001)
|
redis_conn.zincrby(self.redis_key, self.period_end_date.day, 1001)
|
||||||
checker = QuotaChecker(user_service_config, redis_conn)
|
checker = QuotaChecker(user_service_config, redis_conn)
|
||||||
assert checker.check() == True
|
assert checker.check() == True
|
||||||
|
|||||||
Reference in New Issue
Block a user