Adds tests for the memcached bytecode cache module
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Alex Kahan · committed by David Lord · parent 711ad9d · Browse files · 1 file·+64 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+64 added−1 removed
- tests:+64 added−1 removed
Provenance
- Commit
6e74191- Tree
17ddd46- Author
Alex Kahan <alexk307@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
711ad9d
1 file changed+64 added−1 removed
modified:tests/test_bytecode_cache.py+64 added-1 removed
8 unmodified lines9 :license: BSD, see LICENSE for more details.10 """11 import pytest12 from jinja2 import Environment13-from jinja2.bccache import FileSystemBytecodeCache13+from jinja2.bccache import FileSystemBytecodeCache, MemcachedBytecodeCache,\14+ Bucket15 from jinja2.exceptions import TemplateNotFound16 17 18 @pytest.fixture11 unmodified lines30 def test_simple(self, env):31 tmpl = env.get_template('test.html')32 assert tmpl.render().strip() == 'BAR'33 pytest.raises(TemplateNotFound, env.get_template, 'missing.html')34+35+36+class MockMemcached(object):37+38+ def get(self, key):39+ return "value"40+41+ def set(self, *args):42+ pass43+44+ def get_side_effect(self, key):45+ raise Exception()46+47+ def set_side_effect(self, *args):48+ raise Exception()49+50+51+class TestMemcachedBytecodeCache(object):52+53+ def test_load_bytecode(self):54+55+ # Python 2.X does not have explicit bytes type and Python 3.X's56+ # str type does not support Buffer interface57+ try:58+ key = bytes("key", "utf-8") # PY 3.X59+ except:60+ key = "key" # PY 2.X61+62+ m = MemcachedBytecodeCache(MockMemcached())63+ b = Bucket("", key, "")64+ m.load_bytecode(b)65+66+ def test_load_bytecode_exception(self):67+ memcached = MockMemcached()68+ memcached.get = memcached.get_side_effect69+ m = MemcachedBytecodeCache(memcached)70+ b = Bucket("", "key", "")71+ m.load_bytecode(b)72+73+ def test_load_bytecode_exception_raise(self):74+ memcached = MockMemcached()75+ memcached.get = memcached.get_side_effect76+ m = MemcachedBytecodeCache(memcached, ignore_memcache_errors=False)77+ b = Bucket("", "key", "")78+ with pytest.raises(Exception):79+ m.load_bytecode(b)80+81+ def test_dump_bytecode(self):82+ memcached = MockMemcached()83+ m = MemcachedBytecodeCache(memcached, timeout=10)84+ b = Bucket("", "key", "")85+ b.code = "code"86+ m.dump_bytecode(b)87+88+ def test_dump_bytecode_exception_raise(self):89+ memcached = MockMemcached()90+ memcached.set = memcached.set_side_effect91+ m = MemcachedBytecodeCache(memcached, ignore_memcache_errors=False)92+ b = Bucket("", "key", "")93+ b.code = "code"94+ with pytest.raises(Exception):95+ m.dump_bytecode(b)