##// END OF EJS Templates
docs: updated configuration for nginx and reverse proxy.
docs: updated configuration for nginx and reverse proxy.

File last commit:

r2932:9bfe4e0a default
r3341:6387bcda stable
Show More
test_caches.py
108 lines | 3.5 KiB | text/x-python | PythonLexer
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
release: update copyright year to 2018
r2487 # Copyright (C) 2016-2018 RhodeCode GmbH
project: added all source files and assets
r1 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import time
import pytest
caches: rewrite of auth/permission caches to dogpile.
r2845 from rhodecode.lib import rc_cache
project: added all source files and assets
r1
caches: new cache context managers....
r2932 @pytest.mark.usefixtures('app')
caches: rewrite of auth/permission caches to dogpile.
r2845 class TestCaches(object):
project: added all source files and assets
r1
caches: rewrite of auth/permission caches to dogpile.
r2845 def test_cache_decorator_init_not_configured(self):
with pytest.raises(EnvironmentError):
rc_cache.get_or_create_region('dontexist')
@pytest.mark.parametrize('region_name', [
'cache_perms', u'cache_perms',
project: added all source files and assets
r1 ])
caches: rewrite of auth/permission caches to dogpile.
r2845 def test_cache_decorator_init(self, region_name):
namespace = region_name
cache_region = rc_cache.get_or_create_region(
region_name, region_namespace=namespace)
assert cache_region
project: added all source files and assets
r1
@pytest.mark.parametrize('example_input', [
('',),
(u'/ac',),
(u'/ac', 1, 2, object()),
(u'/ęćc', 1, 2, object()),
('/Ä…ac',),
(u'/ac', ),
])
def test_cache_manager_create_key(self, example_input):
caches: rewrite of auth/permission caches to dogpile.
r2845 key = rc_cache.utils.compute_key_from_params(*example_input)
project: added all source files and assets
r1 assert key
caches: rewrite of auth/permission caches to dogpile.
r2845 @pytest.mark.parametrize('example_namespace', [
'namespace', None
])
@pytest.mark.parametrize('example_input', [
('',),
(u'/ac',),
(u'/ac', 1, 2, object()),
(u'/ęćc', 1, 2, object()),
('/Ä…ac',),
(u'/ac', ),
])
def test_cache_keygen(self, example_input, example_namespace):
def func_wrapped():
return 1
func = rc_cache.utils.key_generator(example_namespace, func_wrapped)
key = func(*example_input)
assert key
project: added all source files and assets
r1
caches: rewrite of auth/permission caches to dogpile.
r2845 def test_store_value_in_cache(self):
cache_region = rc_cache.get_or_create_region('cache_perms')
# make sure we empty the cache now
caches: use delete_multi for clearing out cache keys....
r2888 cache_region.delete_multi(cache_region.backend.list_keys())
caches: rewrite of auth/permission caches to dogpile.
r2845
assert cache_region.backend.list_keys() == []
caches: use new decorator that uses conditional caches skipping dogpile if cache is disabled.
r2892 @cache_region.conditional_cache_on_arguments(expiration_time=5)
caches: rewrite of auth/permission caches to dogpile.
r2845 def compute(key):
project: added all source files and assets
r1 return time.time()
caches: rewrite of auth/permission caches to dogpile.
r2845 for x in range(10):
compute(x)
assert len(set(cache_region.backend.list_keys())) == 10
project: added all source files and assets
r1
caches: rewrite of auth/permission caches to dogpile.
r2845 def test_store_and_get_value_from_region(self):
cache_region = rc_cache.get_or_create_region('cache_perms')
# make sure we empty the cache now
for key in cache_region.backend.list_keys():
cache_region.delete(key)
assert cache_region.backend.list_keys() == []
project: added all source files and assets
r1
caches: use new decorator that uses conditional caches skipping dogpile if cache is disabled.
r2892 @cache_region.conditional_cache_on_arguments(expiration_time=5)
caches: rewrite of auth/permission caches to dogpile.
r2845 def compute(key):
return time.time()
project: added all source files and assets
r1
caches: rewrite of auth/permission caches to dogpile.
r2845 result = set()
for x in range(10):
ret = compute('x')
result.add(ret)
project: added all source files and assets
r1
caches: rewrite of auth/permission caches to dogpile.
r2845 # once computed we have only one value (the same from cache)
# after executing it 10x
assert len(result) == 1