caches: make sure __repr__ of invalidaiton context always return strings.

- this is a part of python specs, otherwise we potentially can cause
UnicodeDecodeErrors
This commit is contained in:
Marcin Kuzminski 2016-06-28 16:58:55 +02:00
parent c37c75f1a8
commit 68bbf9bd37
2 changed files with 11 additions and 3 deletions

View file

@ -167,7 +167,7 @@ class FreshRegionCache(ActiveRegionCache):
class InvalidationContext(object):
def __repr__(self):
return '<InvalidationContext:{}[{}]>'.format(
self.repo_name, self.cache_type)
safe_str(self.repo_name), safe_str(self.cache_type))
def __init__(self, compute_func, repo_name, cache_type,
raise_exception=False):

View file

@ -432,7 +432,13 @@ def test_get_repo_by_id(test, expected):
assert _test == expected
def test_invalidation_context(pylonsapp):
@pytest.mark.parametrize("test_repo_name, repo_type", [
("test_repo_1", None),
("repo_group/foobar", None),
("test_non_asci_ąćę", None),
(u"test_non_asci_unicode_ąćę", None),
])
def test_invalidation_context(pylonsapp, test_repo_name, repo_type):
from beaker.cache import cache_region
from rhodecode.lib import caches
from rhodecode.model.db import CacheKey
@ -442,7 +448,7 @@ def test_invalidation_context(pylonsapp):
return 'result'
invalidator_context = CacheKey.repo_context_cache(
_dummy_func, 'test_repo_1', 'repo')
_dummy_func, test_repo_name, 'repo')
with invalidator_context as context:
invalidated = context.invalidate()
@ -452,6 +458,8 @@ def test_invalidation_context(pylonsapp):
assert 'result' == result
assert isinstance(context, caches.FreshRegionCache)
assert 'InvalidationContext' in repr(invalidator_context)
with invalidator_context as context:
context.invalidate()
result = context.compute()