예제 #1
0
class TestDailyRollingCounter(object):
    def setup(self):
        self.redis = Redis()
        self.redis.flushdb()
        self.counter = DailyRollingCounter(self.redis, 'foo')

    def teardown(self):
        self.redis.flushdb()
        self.redis.connection.disconnect()

    def test_full(self):
        self.counter.incr()
        actual_value = self.counter.value()
        assert actual_value == 1

    def test_prune(self):
        outdated_date = date.today() - timedelta(days=31)
        hashkey = 'counter@{0}'.format(outdated_date.strftime('%Y%m%d'))
        self.redis.hset('foo', hashkey, 1)
        self.counter.value()
        keyvalue = self.redis.hget('foo', hashkey)
        assert keyvalue is None

    def test_count0(self):
        assert self.counter.value() == 0