switchcache

Utils for testing with/without cache


Keywords
memcached, test, testing, decorators
License
Other
Install
pip install switchcache==0.1.1

Documentation

switchcache

Test utils for testing with memcache

with_cache/no_cache decorators

from switchcache import init, with_cache, no_cache

class Configure:
    HOSTS = ['127.0.0.1:11211']
    CACHE = {
        'foo': 'bar',
        'fuga': 'hoge'
    }
init(Configure)

@with_cache
def test_with_cache():
    <Cache enabled in this function>
    
@no_cache
def test_no_cache():
    <Cache disabled in this function>

"with" clause

from switchcache import cache

def test():
    with cache:
       <Cache enabled inside "with">
    <Cache disabled outside "with">

twice/times decorators

from switchcache import twice, times

@twice
def test_twice(s):
    return s
>>> test_twice('foo')
['foo', 'foo']
    
@times(5)
def test_5_times(s):
    return s
>>> test_5_times('bar')
['bar', 'bar', 'bar', 'bar', 'bar']

Note

Make sure HOSTS point to a your testing environment. Your current caches on memcache will be flushed & overrided.