示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 def test_reset_key_must_exist_true(self):
     rc = RedisCounter(TEST_REDIS)
     with self.assertRaises(KeyNotFound):
         rc.reset('some_key', must_exist=True)
示例#4
0
 def test_reset_key_must_exist_false(self):
     rc = RedisCounter(TEST_REDIS)
     rc.reset('some_key')
示例#5
0
 def setUp(self):
     rc = RedisCounter(TEST_REDIS)
     rc.clear('some_key')
示例#6
0
 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')
示例#7
0
 def test_get_key_must_exist_false(self):
     rc = RedisCounter(TEST_REDIS)
     rc.add('some_key', 10, 10)
     rc.get('some_key')
示例#8
0
 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)
示例#9
0
 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')
示例#10
0
 def test_key_unique(self):
     rc = RedisCounter(TEST_REDIS)
     rc.add('some_key', 10, 10)
     with self.assertRaises(KeyExist):
         rc.add('some_key', 10, 20)
示例#11
0
 def test_basic(self):
     rc = RedisCounter(TEST_REDIS)
     rc.add('some_key', 10, 10)
     rc.remove('some_key')
示例#12
0
 def test_sanity(self):
     rc = RedisCounter(TEST_REDIS)