Esempio n. 1
0
 def testSetValuesWithPrefix(self):
     """L{BaseCache.setValues} uses the given prefix as key."""
     cache = BaseCache()
     cache.keyPrefix = 'prefix:'
     cache.setValues({'identifier1': 'test1', 'identifier2': 'test2'})
     self.assertEqual('test1', self.cache.get('prefix:identifier1'))
     self.assertEqual('test2', self.cache.get('prefix:identifier2'))
Esempio n. 2
0
 def testSetValuesWithPrefix(self):
     """L{BaseCache.setValues} uses the given prefix as key."""
     cache = BaseCache()
     cache.keyPrefix = 'prefix:'
     cache.setValues({'identifier1': 'test1', 'identifier2': 'test2'})
     self.assertEqual('test1', self.cache.get('prefix:identifier1'))
     self.assertEqual('test2', self.cache.get('prefix:identifier2'))
Esempio n. 3
0
 def testGetValuesWithPrefix(self):
     """L{BaseCache.getValues} uses the given prefix as key."""
     self.cache.set('prefix:identifier1', 'test1')
     self.cache.set('prefix:identifier2', 'test2')
     cache = BaseCache()
     cache.keyPrefix = 'prefix:'
     result = cache.getValues([u'identifier1', u'identifier2'])
     self.assertEqual([u'test1', u'test2'], result)
Esempio n. 4
0
 def testGetValuesWithPrefix(self):
     """L{BaseCache.getValues} uses the given prefix as key."""
     self.cache.set('prefix:identifier1', 'test1')
     self.cache.set('prefix:identifier2', 'test2')
     cache = BaseCache()
     cache.keyPrefix = 'prefix:'
     result = cache.getValues([u'identifier1', u'identifier2'])
     self.assertEqual([u'test1', u'test2'], result)
Esempio n. 5
0
 def testDeleteValuesWithPrefix(self):
     """L{BaseCache.deleteValues} uses the given prefix as key."""
     self.cache.set('prefix:identifier1', 'test1')
     self.cache.set('prefix:identifier2', 'test2')
     cache = BaseCache()
     cache.keyPrefix = 'prefix:'
     cache.deleteValues([u'identifier1', u'identifier2'])
     self.assertEqual([None, None],
                      self.cache.mget(
                          [u'prefix:identifier1', u'prefix:identifier2']))
Esempio n. 6
0
 def testDeleteValuesWithError(self):
     """
     Redis errors are ignored by L{BaseCache.deleteValues} and a line is
     written in the logs.
     """
     cache = BaseCache()
     cache._client.connection_pool = ConnectionPool(port=0)
     cache.deleteValues(['identifier'])
     self.assertEqual('Redis error: Error 111 connecting localhost:0. '
                      'Connection refused.\n', self.log.getvalue())
Esempio n. 7
0
 def testDeleteValuesWithPrefix(self):
     """L{BaseCache.deleteValues} uses the given prefix as key."""
     self.cache.set('prefix:identifier1', 'test1')
     self.cache.set('prefix:identifier2', 'test2')
     cache = BaseCache()
     cache.keyPrefix = 'prefix:'
     cache.deleteValues([u'identifier1', u'identifier2'])
     self.assertEqual([None, None],
                      self.cache.mget([u'prefix:identifier1',
                                       u'prefix:identifier2']))
Esempio n. 8
0
 def testDeleteValuesWithError(self):
     """
     Redis errors are ignored by L{BaseCache.deleteValues} and a line is
     written in the logs.
     """
     cache = BaseCache()
     cache._client.connection_pool = ConnectionPool(port=0)
     cache.deleteValues(['identifier'])
     self.assertEqual(
         'Redis error: Error 111 connecting localhost:0. '
         'Connection refused.\n', self.log.getvalue())
Esempio n. 9
0
 def testDeleteValuesWithEmpyIdentifiers(self):
     """
     L{BaseCache.deleteValues} doesn't show errors if an empty list of
     identifiers is given.
     """
     BaseCache().deleteValues([])
     self.assertEqual('', self.log.getvalue())
Esempio n. 10
0
 def testDeleteValues(self):
     """L{BaseCache.deleteValues} deletes values from the cache."""
     self.cache.set('identifier1', 'test1')
     self.cache.set('identifier2', 'test2')
     BaseCache().deleteValues([u'identifier1', u'identifier2'])
     self.assertEqual([None, None],
                      self.cache.mget([u'identifier1', u'identifier2']))
Esempio n. 11
0
 def testSetValuesWithTimeout(self):
     """L{BaseCache.setValues} set the expire timout of the values."""
     BaseCache().setValues({'identifier1': 'test1', 'identifier2': 'test2'})
     expectedTimeout = self.config.getint('cache', 'expire-timeout')
     self.assertAlmostEqual(expectedTimeout, self.cache.ttl('identifier1'))
     self.assertAlmostEqual(expectedTimeout, self.cache.ttl('identifier2'))
Esempio n. 12
0
 def testSetValues(self):
     """L{BaseCache.setValues} sets values in the cache."""
     BaseCache().setValues({'identifier1': 'test1', 'identifier2': 'test2'})
     self.assertEqual('test1', self.cache.get('identifier1'))
     self.assertEqual('test2', self.cache.get('identifier2'))
Esempio n. 13
0
 def testGetValuesWithEmptyIdentifiers(self):
     """
     L{BaseCache.getValues} returns an empty list if the list of identifiers
     is empty as well.
     """
     self.assertEqual([], BaseCache().getValues([]))
Esempio n. 14
0
 def testGetValuesWithUnknownValue(self):
     """L{BaseCache.getValues} returns L{None} for values not found."""
     self.cache.set('identifier1', 'test1')
     result = BaseCache().getValues([u'identifier1', u'identifier2'])
     self.assertEqual([u'test1', None], result)
Esempio n. 15
0
 def testGetValues(self):
     """L{BaseCache.getValues} returns values stored in the cache."""
     self.cache.set('identifier1', 'test1')
     self.cache.set('identifier2', 'test2')
     result = BaseCache().getValues([u'identifier1', u'identifier2'])
     self.assertEqual([u'test1', u'test2'], result)