Skip to content
Myr

Merge pull request #672 from alexk307/tests-memcached-bytecode-cache

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Adds tests for the memcached bytecode cache module

authored by David Lord · committed by GitHub · parents 711ad9d, a675c85 · Browse files · 1 file+61 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+61 added−1 removed

  • tests:+61 added−1 removed

1 file+61 added−1 removed

modified:tests/test_bytecode_cache.py+61 added-1 removed
6 unmodified lines
78 :copyright: (c) 2017 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10"""1112import pytest1314from jinja2 import Environment13from jinja2.bccache import FileSystemBytecodeCache15from jinja2.bccache import Bucket, FileSystemBytecodeCache, \16 MemcachedBytecodeCache17from jinja2.exceptions import TemplateNotFound181920@pytest.fixture
11 unmodified lines
32 def test_simple(self, env):33 tmpl = env.get_template('test.html')34 assert tmpl.render().strip() == 'BAR'35 pytest.raises(TemplateNotFound, env.get_template, 'missing.html')363738class MockMemcached(object):39 class Error(Exception):40 pass4142 key = None43 value = None44 timeout = None4546 def get(self, key):47 return self.value4849 def set(self, key, value, timeout=None):50 self.key = key51 self.value = value52 self.timeout = timeout5354 def get_side_effect(self, key):55 raise self.Error()5657 def set_side_effect(self, *args):58 raise self.Error()596061class TestMemcachedBytecodeCache(object):62 def test_dump_load(self):63 memcached = MockMemcached()64 m = MemcachedBytecodeCache(memcached)6566 b = Bucket(None, 'key', '')67 b.code = 'code'68 m.dump_bytecode(b)69 assert memcached.key == 'jinja2/bytecode/key'7071 b = Bucket(None, 'key', '')72 m.load_bytecode(b)73 assert b.code == 'code'7475 def test_exception(self):76 memcached = MockMemcached()77 memcached.get = memcached.get_side_effect78 memcached.set = memcached.set_side_effect79 m = MemcachedBytecodeCache(memcached)80 b = Bucket(None, 'key', '')81 b.code = 'code'8283 m.dump_bytecode(b)84 m.load_bytecode(b)8586 m.ignore_memcache_errors = False8788 with pytest.raises(MockMemcached.Error):89 m.dump_bytecode(b)9091 with pytest.raises(MockMemcached.Error):92 m.load_bytecode(b)