Ejemplo n.º 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 == {}
Ejemplo n.º 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 == {}
Ejemplo n.º 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")
Ejemplo n.º 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 == {}
Ejemplo n.º 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
Ejemplo n.º 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()
Ejemplo n.º 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
Ejemplo n.º 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 == {}
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 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()
Ejemplo n.º 19
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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()