Пример #1
0
 def test_get(self):
     """
     Test 'get' command for positive outcome (without ttl)
     :return:
     """
     parser = RedisCommandParser()
     self.assertEqual(BulkStringNone, parser.parse('get 1'.split(' ')))
     parser.storage.set('1', 'one')
     self.assertEqual('one', parser.parse('get 1'.split(' ')))
Пример #2
0
 def test_hset(self):
     """
     Test 'hset' positive outcome
     :return:
     """
     parser = RedisCommandParser()
     self.assertEqual(2, parser.parse('hset dict1 1 one 2 two'.split(' ')))
     self.assertEqual(1,
                      parser.parse('hset dict1 1 one 3 three'.split(' ')))
Пример #3
0
 def test_rpush(self):
     """
     Test 'rpush' positive outcome
     :return:
     """
     parser = RedisCommandParser()
     self.assertEqual(3, parser.parse('rpush list1 1 2 3'.split(' ')))
     self.assertEqual(5, parser.parse('rpush list1 4 5'.split(' ')))
     self.assertEqual(['1', '2', '3', '4', '5'],
                      parser.storage.get('list1'))
Пример #4
0
 def test_hget(self):
     """
     Test 'hget' positive outcome
     :return:
     """
     parser = RedisCommandParser()
     parser.storage.set('dict1', {'1': 'one', '2': 'two'})
     self.assertEqual('one', parser.parse('hget dict1 1'.split(' ')))
     self.assertEqual('two', parser.parse('hget dict1 2'.split(' ')))
     self.assertEqual(BulkStringNone,
                      parser.parse('hget dict1 3'.split(' ')))
Пример #5
0
 def test_lrange(self):
     """
     Test 'lrange' command positive outcome
     :return:
     """
     parser = RedisCommandParser()
     parser.storage.set('1', [1, 2, 3])
     self.assertEqual([1, 2, 3], parser.parse('lrange 1 0 -1'.split(' ')))
     self.assertEqual([1, 2], parser.parse('lrange 1 0 1'.split(' ')))
     self.assertEqual([2, 3], parser.parse('lrange 1 -2 -1'.split(' ')))
     self.assertEqual([1], parser.parse('lrange 1 0 0'.split(' ')))
Пример #6
0
 def test_expire(self):
     """
     Test 'expire' positive outcome
     :return:
     """
     self.now = time.time()
     with patch('time.time', self.fake_time):
         parser = RedisCommandParser()
         parser.storage.set('1', 'one')
         self.assertEqual(1, parser.parse(['expire', '1', '5']))
         self.assertEqual(0, parser.parse('expire 2 5'.split(' ')))
         self.now += 6
         self.assertEqual(BulkStringNone, parser.parse(['get', '1']))
Пример #7
0
 def test_del(self):
     """
     Test 'del' command for positive outcome (without ttl)
     :return:
     """
     parser = RedisCommandParser()
     self.assertEqual(0, parser.parse('del 1'.split(' ')))
     parser.storage.set('1', 'one')
     self.assertEqual(1, parser.parse('del 1'.split(' ')))
     self.assertEqual(0, parser.parse('del 1'.split(' ')))
     parser.storage.set('1', 'one')
     parser.storage.set('2', 'two')
     self.assertEqual(2, parser.parse('del 1 2 3'.split(' ')))
Пример #8
0
 def test_persist(self):
     """
     Test 'persist' positive outcome
     :return:
     """
     self.now = time.time()
     with patch('time.time', self.fake_time):
         parser = RedisCommandParser()
         parser.storage.set('1', 'one', self.now + 5)
         parser.storage.set('2', 'two')
         self.assertEqual(1, parser.parse(['persist', '1']))
         self.assertEqual(0, parser.parse(['persist', '2']))
         self.assertEqual(0, parser.parse(['persist', '3']))
         self.now += 6
         self.assertEqual('one', parser.parse(['get', '1']))
Пример #9
0
 def test_lget(self):
     """
     Test 'lget' positive outcome
     :return:
     """
     parser = RedisCommandParser()
     parser.storage.set('list1', ['1', '2', '3'])
     self.assertEqual('2', parser.parse(['lget', 'list1', '1']))
Пример #10
0
 def test_lset(self):
     """
     Test 'lset' positive outcome
     :return:
     """
     parser = RedisCommandParser()
     parser.storage.set('list1', ['1', '2', '3'])
     self.assertEqual(CommandParserSuccess,
                      parser.parse(['lset', 'list1', '1', '42']))
     self.assertEqual(['1', '42', '3'], parser.storage.get('list1'))
Пример #11
0
 def test_set_get(self):
     """
     Test 'set' and 'get' commands together (without ttl)
     :return:
     """
     parser = RedisCommandParser()
     self.assertEqual(BulkStringNone, parser.parse('get 1'.split(' ')))
     self.assertEqual(CommandParserSuccess,
                      parser.parse('set 1 one'.split(' ')))
     self.assertEqual('one', parser.parse('get 1'.split(' ')))
     self.assertEqual(BulkStringNone,
                      parser.parse('set 1 two NX'.split(' ')))
     self.assertEqual('one', parser.parse('get 1'.split(' ')))
     self.assertEqual(BulkStringNone,
                      parser.parse('set 2 two XX'.split(' ')))
     self.assertEqual(BulkStringNone, parser.parse('get 2'.split(' ')))
     self.assertEqual(CommandParserSuccess,
                      parser.parse('set 1 two XX'.split(' ')))
     self.assertEqual('two', parser.parse('get 1'.split(' ')))
Пример #12
0
 def test_set(self):
     """
     Test 'set' command for positive outcome (without ttl)
     :return:
     """
     parser = RedisCommandParser()
     self.assertEqual(CommandParserSuccess,
                      parser.parse('set 1 one'.split(' ')))
     self.assertEqual('one', parser.parse('set 1 one GET'.split(' ')))
     self.assertEqual(BulkStringNone,
                      parser.parse('set 2 two GET'.split(' ')))
     self.assertEqual(CommandParserSuccess,
                      parser.parse('set 2 "two" EX 5'.split(' ')))
     self.assertEqual(BulkStringNone,
                      parser.parse('set 1 one NX'.split(' ')))
     self.assertEqual(CommandParserSuccess,
                      parser.parse('set 1 one XX'.split(' ')))
     self.assertEqual(CommandParserSuccess,
                      parser.parse('set 1 one KEEPTTL'.split(' ')))
     self.assertEqual(CommandParserSuccess,
                      parser.parse('SET 1 one keepttl'.split(' ')))
     self.assertEqual(CommandParserSuccess,
                      parser.parse('Set 1 one Keepttl'.split(' ')))
Пример #13
0
 def test_keys(self):
     """
     Test 'keys' command for positive outcome (without ttl)
     :return:
     """
     parser = RedisCommandParser()
     self.assertEqual([], parser.parse('keys *'.split(' ')))
     parser.storage.set('abc', 'one')
     parser.storage.set('abcd', 'two')
     parser.storage.set('abd', 'three')
     self.assertEqual([], parser.parse('keys ?'.split(' ')))
     self.assertEqual({'abc', 'abcd', 'abd'},
                      set(parser.parse(['keys', '*'])))
     self.assertEqual({'abc', 'abd'}, set(parser.parse(['keys', 'ab?'])))
     self.assertEqual({'abcd'}, set(parser.parse(['keys', 'abc?'])))
     self.assertEqual({'abc', 'abcd', 'abd'},
                      set(parser.parse(['keys', 'ab*'])))
     self.assertEqual({'abc', 'abcd', 'abd'},
                      set(parser.parse(['keys', 'ab*'])))
     self.assertEqual({'abc', 'abd'}, set(parser.parse(['keys', 'ab[cd]'])))
     self.assertEqual({'abc'}, set(parser.parse(['keys', 'ab[^d]'])))
     self.assertEqual({'abc', 'abcd'},
                      set(parser.parse(['keys', 'ab[^d-e]*'])))
     self.assertEqual({'abc', 'abd'}, set(parser.parse(['keys',
                                                        'ab[a-e]'])))
     self.assertEqual(set(), set(parser.parse(['keys', 'ab[^a-e]'])))
Пример #14
0
 def test_set_get_ttl(self):
     """
     Test 'set' and 'get' commands with ttl
     :return:
     """
     self.now = time.time()
     with patch('time.time', self.fake_time):
         parser = RedisCommandParser()
         parser.parse('set 1 one ex 5'.split(' '))
         parser.parse('set 2 two ex 10'.split(' '))
         parser.parse('set 3 three'.split(' '))
         self.assertEqual('one', parser.parse('get 1'.split(' ')))
         self.assertEqual('two', parser.parse('get 2'.split(' ')))
         self.assertEqual('three', parser.parse('get 3'.split(' ')))
         self.now += 6
         self.assertEqual(BulkStringNone, parser.parse('get 1'.split(' ')))
         self.assertEqual('two', parser.parse('get 2'.split(' ')))
         self.assertEqual('three', parser.parse('get 3'.split(' ')))
         self.now += 5
         self.assertEqual(BulkStringNone, parser.parse('get 1'.split(' ')))
         self.assertEqual(BulkStringNone, parser.parse('get 2'.split(' ')))
         self.assertEqual('three', parser.parse('get 3'.split(' ')))