def test_common_timeout(self): PySmartCacheSettings.timeout = 20 os.environ['PYSMARTCACHE_TIMEOUT'] = '30' self.assertEquals(PySmartCacheSettings._get_timeout(10), 10) self.assertEquals(PySmartCacheSettings._get_timeout(None), 20) PySmartCacheSettings.reset() self.assertEquals(PySmartCacheSettings._get_timeout(None), 30) os.environ.pop('PYSMARTCACHE_TIMEOUT', None) self.assertEquals(PySmartCacheSettings._get_timeout(None), PySmartCacheSettings._DEFAULT_TIMEOUT)
def __init__(self, func, keys, function_args, function_kwargs, timeout=None, cache_backend=None, cache_host=None, verbose=None): self.timeout = PySmartCacheSettings._get_timeout(timeout) self.cache_backend = PySmartCacheSettings._get_cache_backend(cache_backend) self.verbose = PySmartCacheSettings._get_verbose(verbose) self.func = func self.keys = keys self.function_args = function_args self.function_kwargs = function_kwargs self.function_arguments = inspect.getcallargs(self.func, *self.function_args, **self.function_kwargs) self.now_reference = datetime.datetime.now() self.cache_client = CacheClient.instantiate(self.cache_backend, cache_host) self._create_func_full_qualified_name() self._create_cache_key() self.stored_info = self.info() self.stored_value = self.stored_info['value'] if self.stored_info else None self.stored_at = self.stored_info['date added'] if self.stored_info else None if self.verbose: print '-' * 50 print 'KEY: {}'.format(self.cache_key)
def __init__(self, func, keys, function_args, function_kwargs, timeout=None, cache_backend=None, cache_host=None, verbose=None): self.timeout = PySmartCacheSettings._get_timeout(timeout) self.cache_backend = PySmartCacheSettings._get_cache_backend( cache_backend) self.verbose = PySmartCacheSettings._get_verbose(verbose) self.func = func self.keys = keys self.function_args = function_args self.function_kwargs = function_kwargs self.function_arguments = inspect.getcallargs(self.func, *self.function_args, **self.function_kwargs) self.now_reference = datetime.datetime.now() self.cache_client = CacheClient.instantiate(self.cache_backend, cache_host) self._create_func_full_qualified_name() self._create_cache_key() self.stored_info = self.info() self.stored_value = self.stored_info[ 'value'] if self.stored_info else None self.stored_at = self.stored_info[ 'date added'] if self.stored_info else None if self.verbose: print '-' * 50 print 'KEY: {}'.format(self.cache_key)
def test_timeout_zero(self): with self.assertRaises(ImproperlyConfigured) as e: PySmartCacheSettings._get_timeout(0) self.assertEquals(str(e.exception), 'PySmartCache timeout settings must be positive')
def test_timeout_nan(self): with self.assertRaises(ImproperlyConfigured) as e: PySmartCacheSettings._get_timeout('NaN NaN NaN NaN Batman!') self.assertEquals(str(e.exception), 'PySmartCache timeout settings must be numeric')