def test_setEntry(self): s = Storage(cleanupInterval=300, maxAge=300) object = 'object' key = ('view', (), ('answer', 42)) key2 = ('view2', (), ('answer', 42)) value = 'yes' t1 = time() s.setEntry(object, key, value) t2 = time() timestamp = s._data[object][key][1] self.failUnless(t1 <= timestamp <= t2, 'wrong timestamp') self.assertEqual(s._data, {object: {key: [value, timestamp, 0]}}, 'stored data incorrectly') s._data[object][key][1] = time() - 400 s.lastCleanup = time() - 400 s.setEntry(object, key2, value) timestamp = s._data[object][key2][1] self.assertEqual(s._data, {object: {key2: [value, timestamp, 0]}}, 'cleanup not called')
def test_getEntry_do_cleanup(self): s = Storage(cleanupInterval=300, maxAge=300) object = 'object' key = ('view', (), ('answer', 42)) value = 'yes' s.setEntry(object, key, value) s._data[object][key][1] = time() - 400 s.lastCleanup = time() - 400 self.assertRaises(KeyError, s.getEntry, object, key)