def test_count_subkey(self): rc = RedisCounter(TEST_REDIS) rc.add('some_key', 10, 10) rc.count('some_key', 'one') rc.count('some_key', 'two') rc.count('some_key', 'two') self.assertEqual(rc.get('some_key', 'one'), 1) self.assertEqual(rc.get('some_key', 'two'), 2)
def test_clear(self): rc = RedisCounter(TEST_REDIS) rc.add('some_key', 5, 10) rc.count('some_key', 'one') rc.count('some_key', 'two') rc.count('some_key', 'three') rc.clear('some_key') #~ raise self.assertEqual(rc.get('some_key', 'one'), None) self.assertEqual(rc.get('some_key', 'two'), None) self.assertEqual(rc.get('some_key', 'three'), None)
def test_reset_key(self): rc = RedisCounter(TEST_REDIS) rc.add('some_key', 1, 10) rc.count('some_key') with self.assertRaises(CountLimit): rc.count('some_key') rc.reset('some_key') rc.count('some_key')
def test_count_weight(self): rc = RedisCounter(TEST_REDIS) rc.add('some_key', 5, 10) with self.assertRaises(CountLimit): rc.count('some_key', weight=6)
def test_count_key_must_exist(self): rc = RedisCounter(TEST_REDIS) with self.assertRaises(KeyNotFound): rc.count('some_key') rc.add('some_key', 10, 10) rc.count('some_key')