def test_invalidate_function_with_args(self): def my_func(name): # pragma: nocover return "Hello %s" % name my_func._region = 'short_term' my_func._namespace = 'retools:a_key decarg' mock_redis = Mock(spec=redis.client.Redis) mock_redis.smembers.return_value = set(['1']) invalidate_function = self._makeOne() with patch('retools.global_connection._redis', mock_redis): CR = self._makeCR() CR.add_region('short_term', expires=600) invalidate_function(my_func, 'fred') calls = mock_redis.method_calls eq_(calls[0][1][0], 'retools:short_term:retools:a_key decarg:fred') eq_(calls[0][0], 'hset') eq_(len(calls), 1) # And a unicode key mock_redis.reset_mock() invalidate_function(my_func, u"\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac") calls = mock_redis.method_calls eq_(calls[0][1][0], u'retools:short_term:retools:a_key' \ u' decarg:\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac') eq_(calls[0][0], 'hset') eq_(len(calls), 1)
def test_invalidate_function_with_args(self): def my_func(name): # pragma: nocover return "Hello %s" % name my_func._region = 'short_term' my_func._namespace = 'retools:a_key decarg' mock_redis = Mock(spec=redis.client.Redis) mock_redis.smembers.return_value = {'1'} invalidate_function = self._makeOne() with patch('retools.global_connection._redis', mock_redis): CR = self._makeCR() CR.add_region('short_term', expires=600) invalidate_function(my_func, 'fred') calls = mock_redis.method_calls eq_(calls[0][1][0], 'retools:short_term:retools:a_key decarg:fred') eq_(calls[0][0], 'hset') eq_(len(calls), 1) # And a unicode key mock_redis.reset_mock() invalidate_function( my_func, "\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac") calls = mock_redis.method_calls eq_(calls[0][1][0], 'retools:short_term:retools:a_key' \ ' decarg:\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac') eq_(calls[0][0], 'hset') eq_(len(calls), 1)
def test_invalidate_function_without_args(self): def my_func(): return "Hello" my_func._region = 'short_term' my_func._namespace = 'retools:a_key' mock_redis = Mock(spec=redis.client.Redis) mock_redis.smembers.return_value = set(['1']) mock_pipeline = Mock(spec=redis.client.Pipeline) mock_redis.pipeline.return_value = mock_pipeline invalidate_function = self._makeOne() with patch('retools.global_connection._redis', mock_redis): CR = self._makeCR() CR.add_region('short_term', expires=600) invalidate_function(my_func) calls = mock_redis.method_calls eq_(calls[0][1], ('retools:short_term:retools:a_key:keys',)) eq_(len(calls), 2)
def test_invalidate_function_without_args(self): def my_func(): # pragma: nocover return "Hello" my_func._region = 'short_term' my_func._namespace = 'retools:a_key' mock_redis = Mock(spec=redis.client.Redis) mock_redis.smembers.return_value = {'1'} mock_pipeline = Mock(spec=redis.client.Pipeline) mock_redis.pipeline.return_value = mock_pipeline invalidate_function = self._makeOne() with patch('retools.global_connection._redis', mock_redis): CR = self._makeCR() CR.add_region('short_term', expires=600) invalidate_function(my_func) calls = mock_redis.method_calls eq_(calls[0][1], ('retools:short_term:retools:a_key:keys', )) eq_(len(calls), 2)