Mercurial > p > roundup > code
view test/session_common.py @ 4652:dfbc0cfa9811
Add an interface to register clearCache callbacks in roundupdb.
Sometimes complicated computations may require an application cache.
This application can now register a callback to clear the application
cache, because roundup knows better when to clear it (usually when a
transaction ends, either with rollback or with commit). The interface
for this is currently considered experimental. The current interface
is registerClearCacheCallback(self, method, param) where method is
called with param as the only parameter.
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Fri, 17 Aug 2012 15:30:36 +0200 |
| parents | cc33dc9aa3f2 |
| children | 63c79c0992ae |
line wrap: on
line source
import os, shutil, unittest from db_test_base import config class SessionTest(unittest.TestCase): def setUp(self): # remove previous test, ignore errors if os.path.exists(config.DATABASE): shutil.rmtree(config.DATABASE) os.makedirs(config.DATABASE + '/files') self.db = self.module.Database(config, 'admin') self.sessions = self.sessions_module.Sessions(self.db) self.otks = self.sessions_module.OneTimeKeys(self.db) def tearDown(self): del self.otks del self.sessions if hasattr(self, 'db'): self.db.close() if os.path.exists(config.DATABASE): shutil.rmtree(config.DATABASE) def testList(self): self.sessions.list() self.sessions.set('random_key', text='hello, world!') self.sessions.list() def testGetAll(self): self.sessions.set('random_key', text='hello, world!') self.assertEqual(self.sessions.getall('random_key'), {'text': 'hello, world!'}) def testDestroy(self): self.sessions.set('random_key', text='hello, world!') self.assertEquals(self.sessions.getall('random_key'), {'text': 'hello, world!'}) self.sessions.destroy('random_key') self.assertRaises(KeyError, self.sessions.getall, 'random_key') def testSetSession(self): self.sessions.set('random_key', text='hello, world!') self.assertEqual(self.sessions.get('random_key', 'text'), 'hello, world!') def testUpdateSession(self): self.sessions.set('random_key', text='hello, world!') self.assertEqual(self.sessions.get('random_key', 'text'), 'hello, world!') self.sessions.set('random_key', text='nope') self.assertEqual(self.sessions.get('random_key', 'text'), 'nope') class DBMTest(SessionTest): import roundup.backends.sessions_dbm as sessions_module class RDBMSTest(SessionTest): import roundup.backends.sessions_rdbms as sessions_module
