def test_common_cache_host_memcached(self): PySmartCacheSettings.cache_host = ['127.0.0.1:11213', ] os.environ['PYSMARTCACHE_HOST'] = '127.0.0.1:11212' self.assertEquals( PySmartCacheSettings._get_cache_host(['127.0.0.1:11214', ], default=MemcachedClient._DEFAULT_HOST, use_list=True), ['127.0.0.1:11214', ] ) self.assertEquals( PySmartCacheSettings._get_cache_host(None, default=MemcachedClient._DEFAULT_HOST, use_list=True), ['127.0.0.1:11213', ] ) PySmartCacheSettings.reset() self.assertEquals( PySmartCacheSettings._get_cache_host(None, default=MemcachedClient._DEFAULT_HOST, use_list=True), ['127.0.0.1:11212', ] ) os.environ.pop('PYSMARTCACHE_HOST', None) self.assertEquals( PySmartCacheSettings._get_cache_host(None, default=MemcachedClient._DEFAULT_HOST, use_list=True), MemcachedClient._DEFAULT_HOST )
def test_common_cache_host_redis(self): PySmartCacheSettings.cache_host = '127.0.0.1:6373' os.environ['PYSMARTCACHE_HOST'] = '127.0.0.1:6372' self.assertEquals( PySmartCacheSettings._get_cache_host('127.0.0.1:6374', default=RedisClient._DEFAULT_HOST, use_list=False), '127.0.0.1:6374' ) self.assertEquals( PySmartCacheSettings._get_cache_host(None, default=RedisClient._DEFAULT_HOST, use_list=False), '127.0.0.1:6373' ) PySmartCacheSettings.reset() self.assertEquals( PySmartCacheSettings._get_cache_host(None, default=RedisClient._DEFAULT_HOST, use_list=False), '127.0.0.1:6372' ) os.environ.pop('PYSMARTCACHE_HOST', None) self.assertEquals( PySmartCacheSettings._get_cache_host(None, default=RedisClient._DEFAULT_HOST, use_list=False), RedisClient._DEFAULT_HOST )
def test_cache_host_boolean_false(self): with self.assertRaises(ImproperlyConfigured) as e: PySmartCacheSettings._get_cache_host('', default='') self.assertEquals(str(e.exception), 'PySmartCache cache host settings must not be empty') with self.assertRaises(ImproperlyConfigured) as e: PySmartCacheSettings._get_cache_host(None, default=None) self.assertEquals(str(e.exception), 'PySmartCache cache host settings must not be empty') with self.assertRaises(ImproperlyConfigured) as e: PySmartCacheSettings._get_cache_host([], default=[]) self.assertEquals(str(e.exception), 'PySmartCache cache host settings must not be empty')
def get_client(self, host=None): import redis host = PySmartCacheSettings._get_cache_host(host, default=self._DEFAULT_HOST, use_list=False) return redis.StrictRedis.from_url(host)
def get_client(self, host=None): import pylibmc host = PySmartCacheSettings._get_cache_host(host, default=self._DEFAULT_HOST, use_list=True) return pylibmc.Client(host)