Пример #1
0
def test_multi_keys():
    cache = Cache("newtests", data_dir="./cache", type="dbm")
    cache.clear()
    called = {}

    def create_func():
        called["here"] = True
        return "howdy"

    try:
        cache.get_value("key1")
    except KeyError:
        pass
    else:
        raise Exception("Failed to keyerror on nonexistent key")

    assert "howdy" == cache.get_value("key2", createfunc=create_func)
    assert called["here"] == True
    del called["here"]

    try:
        cache.get_value("key3")
    except KeyError:
        pass
    else:
        raise Exception("Failed to keyerror on nonexistent key")
    try:
        cache.get_value("key1")
    except KeyError:
        pass
    else:
        raise Exception("Failed to keyerror on nonexistent key")

    assert "howdy" == cache.get_value("key2", createfunc=create_func)
    assert called == {}
Пример #2
0
def test_multi_keys():
    cache = Cache("newtests", data_dir="./cache", type="dbm")
    cache.clear()
    called = {}

    def create_func():
        called["here"] = True
        return "howdy"

    try:
        cache.get_value("key1")
    except KeyError:
        pass
    else:
        raise Exception("Failed to keyerror on nonexistent key")

    assert "howdy" == cache.get_value("key2", createfunc=create_func)
    assert called["here"] == True
    del called["here"]

    try:
        cache.get_value("key3")
    except KeyError:
        pass
    else:
        raise Exception("Failed to keyerror on nonexistent key")
    try:
        cache.get_value("key1")
    except KeyError:
        pass
    else:
        raise Exception("Failed to keyerror on nonexistent key")

    assert "howdy" == cache.get_value("key2", createfunc=create_func)
    assert called == {}
Пример #3
0
def test_clear():
    cache = Cache('test', data_dir='./cache', url=db_url, type='ext:database')
    o = object()
    cache.set_value("test", o)
    assert cache.has_key("test")
    cache.clear()
    assert not cache.has_key("test")
Пример #4
0
def test_multi_keys():
    cache = Cache('newtests', data_dir='./cache', type='dbm')
    cache.clear()
    called = {}

    def create_func():
        called['here'] = True
        return 'howdy'

    try:
        cache.get_value('key1')
    except KeyError:
        pass
    else:
        raise Exception("Failed to keyerror on nonexistent key")

    assert 'howdy' == cache.get_value('key2', createfunc=create_func)
    assert called['here'] == True
    del called['here']

    try:
        cache.get_value('key3')
    except KeyError:
        pass
    else:
        raise Exception("Failed to keyerror on nonexistent key")
    try:
        cache.get_value('key1')
    except KeyError:
        pass
    else:
        raise Exception("Failed to keyerror on nonexistent key")

    assert 'howdy' == cache.get_value('key2', createfunc=create_func)
    assert called == {}
Пример #5
0
def test_clear():
    cache = Cache('test', data_dir='./cache', url=db_url, type='ext:database')
    o = object()
    cache.set_value("test", o)
    assert "test" in cache
    cache.clear()
    assert "test" not in cache
Пример #6
0
def test_dropping_keys():
    cache = Cache('test',
                  data_dir='./cache',
                  url=uri,
                  type='mongodb',
                  sparse_collection=True)
    cache.set_value('test', 20)
    cache.set_value('fred', 10)
    assert cache.has_key('test')
    assert 'test' in cache
    assert cache.has_key('fred')

    # Directly nuke the actual key, to simulate it being removed by mongodb
    cache.namespace.mongo.update({'_id': {
        'namespace': 'test',
        'key': 'test'
    }}, {'$unset': {
        'data': True
    }},
                                 safe=True)
    assert not cache.has_key('test')
    assert cache.has_key('fred')

    # Nuke the keys dict, it might die, who knows
    cache.namespace.mongo.remove(
        {
            '_id': 'test',
            'data.test': {
                '$exists': True
            }
        }, safe=True)
    assert cache.has_key('fred')

    # And we still need clear to work, even if it won't work well
    cache.clear()
Пример #7
0
def test_clear():
    cache = Cache('test', url=db_url, type=db_type, database=db_name)
    o = object()
    cache.set_value("test", o)
    assert "test" in cache
    cache.clear()
    assert "test" not in cache
Пример #8
0
def test_multi_keys():
    cache = Cache('newtests', data_dir='./cache', type='dbm')
    cache.clear()
    called = {}
    def create_func():
        called['here'] = True
        return 'howdy'
    
    try:
        cache.get_value('key1')
    except KeyError:
        pass
    else:
        raise Exception("Failed to keyerror on nonexistent key")

    assert 'howdy' == cache.get_value('key2', createfunc=create_func)
    assert called['here'] == True
    del called['here']

    try:
        cache.get_value('key3')
    except KeyError:
        pass
    else:
        raise Exception("Failed to keyerror on nonexistent key")
    try:
        cache.get_value('key1')
    except KeyError:
        pass
    else:
        raise Exception("Failed to keyerror on nonexistent key")
    
    assert 'howdy' == cache.get_value('key2', createfunc=create_func)
    assert called == {}
Пример #9
0
def test_clear():
    cache = Cache('test', url=db_url, type=db_type, database=db_name)
    o = object()
    cache.set_value("test", o)
    assert cache.has_key("test")
    cache.clear()
    assert not cache.has_key("test")
Пример #10
0
def test_clear():
    cache = Cache("test", data_dir="./cache", url=db_url, type="ext:database")
    o = object()
    cache.set_value("test", o)
    assert cache.has_key("test")
    cache.clear()
    assert not cache.has_key("test")
Пример #11
0
 def test_clear(self):
     cache = Cache('test', **self.CACHE_ARGS)
     cache.set_value('test', 20)
     cache.set_value('fred', 10)
     assert cache.has_key('test')
     assert 'test' in cache
     assert cache.has_key('fred')
     cache.clear()
     assert not cache.has_key("test")
Пример #12
0
 def test_clear(self):
     cache = Cache("test", **self.CACHE_ARGS)
     cache.set_value("test", 20)
     cache.set_value("fred", 10)
     assert cache.has_key("test")
     assert "test" in cache
     assert cache.has_key("fred")
     cache.clear()
     assert not cache.has_key("test")
Пример #13
0
 def test_clear(self):
     cache = Cache('test', **self.CACHE_ARGS)
     cache.set_value('test', 20)
     cache.set_value('fred', 10)
     assert cache.has_key('test')
     assert 'test' in cache
     assert cache.has_key('fred')
     cache.clear()
     assert not cache.has_key("test")
Пример #14
0
class TestRedisJson(RedisTestOverrides, CommonMethodMixin, unittest.TestCase):
    def setUp(self):
        self.cache = Cache("testns", type="ext:redis", url="redis://localhost:6379", serializer="json")
        self.cache.clear()

    @nottest
    def test_store_obj(self):
        # We can't store objects with the json serializer so skip this test from
        # the CommonMethodMixin.
        pass
Пример #15
0
def test_clearing_cache():
    cache = Cache('test', data_dir='./cache', url=uri, type='mongodb_gridfs')
    cache.set_value('test', 20)
    cache.set_value('fred', 10)
    assert cache.has_key('test')
    assert 'test' in cache
    assert cache.has_key('fred')

    cache.clear()
    assert not cache.has_key('test')
Пример #16
0
class TestRedisJson(RedisTestOverrides, CommonMethodMixin, unittest.TestCase):
    def setUp(self):
        self.cache = Cache("testns", type="ext:redis", url="redis://localhost:6379", serializer="json")
        self.cache.clear()

    @nottest
    def test_store_obj(self):
        # We can't store objects with the json serializer so skip this test from
        # the CommonMethodMixin.
        pass
Пример #17
0
def test_clearing_cache():
    cache = Cache('test', data_dir='./cache', url=uri, type='mongodb_gridfs')
    cache.set_value('test', 20)
    cache.set_value('fred', 10)
    assert cache.has_key('test')
    assert 'test' in cache
    assert cache.has_key('fred')

    cache.clear()
    assert not cache.has_key('test')
Пример #18
0
class CassandraCqlJsonSetup(object):
    __keyspace = "test_ks"
    __table = "test_table"

    def setUp(self):
        self.cache = Cache(
            "testns",
            type="cassandra_cql",
            url="localhost:9042",
            keyspace=self.__keyspace,
            column_family=self.__table,
            serializer="json",
        )
        self.cache.clear()
class CassandraCqlJsonSetup(object):
    __keyspace = "test_ks"
    __table = "test_table"

    def setUp(self):
        self.cache = Cache(
            "testns",
            type="cassandra_cql",
            url="localhost:9042",
            keyspace=self.__keyspace,
            column_family=self.__table,
            serializer="json",
        )
        self.cache.clear()
Пример #20
0
def test_dropping_keys():
    cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached')
    cache.set_value('test', 20)
    cache.set_value('fred', 10)
    assert 'test' in cache
    assert 'fred' in cache

    # Directly nuke the actual key, to simulate it being removed by memcached
    cache.namespace.mc.delete('test_test')
    assert 'test' not in cache
    assert 'fred' in cache

    # Nuke the keys dict, it might die, who knows
    cache.namespace.mc.delete('test:keys')
    assert 'fred' in cache

    # And we still need clear to work, even if it won't work well
    cache.clear()
Пример #21
0
def test_dropping_keys():
    cache = Cache("test", data_dir="./cache", url=mc_url, type="ext:memcached")
    cache.set_value("test", 20)
    cache.set_value("fred", 10)
    assert cache.has_key("test")
    assert "test" in cache
    assert cache.has_key("fred")

    # Directly nuke the actual key, to simulate it being removed by memcached
    cache.namespace.mc.delete("test_test")
    assert not cache.has_key("test")
    assert cache.has_key("fred")

    # Nuke the keys dict, it might die, who knows
    cache.namespace.mc.delete("test:keys")
    assert cache.has_key("fred")

    # And we still need clear to work, even if it won't work well
    cache.clear()
Пример #22
0
def test_dropping_keys():
    cache = Cache('test', data_dir='./cache', url=uri, type='mongodb')
    cache.set_value('test', 20)
    cache.set_value('fred', 10)
    assert cache.has_key('test')
    assert 'test' in cache
    assert cache.has_key('fred')

    # Directly nuke the actual key, to simulate it being removed by mongodb
    cache.namespace.mongo.update({'_id': 'test'}, {'$unset': {'data.test': True}}, safe=True)
    assert not cache.has_key('test')
    assert cache.has_key('fred')

    # Nuke the keys dict, it might die, who knows
    cache.namespace.mongo.remove({'_id': 'test', 'data.test': {'$exists': True}}, safe=True)
    assert cache.has_key('fred')

    # And we still need clear to work, even if it won't work well
    cache.clear()
Пример #23
0
def test_dropping_keys():
    cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached')
    cache.set_value('test', 20)
    cache.set_value('fred', 10)
    assert cache.has_key('test')
    assert 'test' in cache
    assert cache.has_key('fred')

    # Directly nuke the actual key, to simulate it being removed by memcached
    cache.namespace.mc.delete('test_test')
    assert not cache.has_key('test')
    assert cache.has_key('fred')

    # Nuke the keys dict, it might die, who knows
    cache.namespace.mc.delete('test:keys')
    assert cache.has_key('fred')

    # And we still need clear to work, even if it won't work well
    cache.clear()
Пример #24
0
def test_dropping_keys():
    cache = Cache("test", data_dir="./cache", url=mc_url, type="ext:memcached")
    cache.set_value("test", 20)
    cache.set_value("fred", 10)
    assert cache.has_key("test")
    assert "test" in cache
    assert cache.has_key("fred")

    # Directly nuke the actual key, to simulate it being removed by memcached
    cache.namespace.mc.delete("test_test")
    assert not cache.has_key("test")
    assert cache.has_key("fred")

    # Nuke the keys dict, it might die, who knows
    cache.namespace.mc.delete("test:keys")
    assert cache.has_key("fred")

    # And we still need clear to work, even if it won't work well
    cache.clear()
Пример #25
0
class TestRedisPickle(RedisTestOverrides, CommonMethodMixin, unittest.TestCase):
    def setUp(self):
        self.cache = Cache("testns", type="ext:redis", url="redis://localhost:6379", serializer="pickle")
        self.cache.clear()
Пример #26
0
class TestRedisPickle(RedisTestOverrides, CommonMethodMixin, unittest.TestCase):
    def setUp(self):
        self.cache = Cache("testns", type="ext:redis", url="redis://localhost:6379", serializer="pickle")
        self.cache.clear()