def test_cache_persistence(self): """ Checks that cache persistence behaviour is maintained. i.e. New engines use same cache as type is 'engine'. """ # create engine with identical attributes to default engine engine = create_engine(self.engine.name, self.engine.cache_type) # create new cache for engine c = cache.QueryCache(engine) # store instance query/response c.store(self.query, self.response) # create 2nd engine with identical attributes to default engine engine2 = create_engine(self.engine.name, self.engine.cache_type) # create new cache for engine c2 = cache.QueryCache(engine2) # check that new cache has query/response available assert_equal(c2.get(self.query), self.response)
def test_cache_keys_deleted(self): """ Checks that the cache keys are deleted when engine de-referenced/destroyed. """ # create engine with identical attributes to default engine engine = create_engine(self.engine.name, self.engine.cache_type) # create new cache for engine c = cache.QueryCache(engine) # store instance query/response c.store(self.query, self.response) # save key name key = c._make_key(self.query) # delete/de-reference cache del c # create new instance cache c = cache.QueryCache(engine) # check that saved key is no longer present assert_equal(c.connection.exists(key), False)
def setup(self): """ Creates engine, cache and a query/response pair as instance attributes. """ # mock engine self.engine = create_engine("TestEngine", "engine") # create cache and flush db self.c = cache.QueryCache(self.engine) self.c.connection.flushdb() # create default query/response test pair for pair in gen_query(response=True): self.query, self.response = pair
def setup(self): """ Creates engine, cache and a query/response pair as instance attributes. Notes: Overridden method. """ self.engine = create_engine("TestEngine", "instance") self.c = cache.QueryCache(self.engine) self.c.connection.flushdb() for pair in gen_query(response=True): self.query, self.response = pair