Premiere version : mise en route du suivi.
[auf_roundup.git] / test / session_common.py
1 import os, shutil, unittest
2
3 from db_test_base import config
4
5 class SessionTest(unittest.TestCase):
6 def setUp(self):
7 # remove previous test, ignore errors
8 if os.path.exists(config.DATABASE):
9 shutil.rmtree(config.DATABASE)
10 os.makedirs(config.DATABASE + '/files')
11 self.db = self.module.Database(config, 'admin')
12 self.sessions = self.sessions_module.Sessions(self.db)
13 self.otks = self.sessions_module.OneTimeKeys(self.db)
14
15 def tearDown(self):
16 del self.otks
17 del self.sessions
18 if hasattr(self, 'db'):
19 self.db.close()
20 if os.path.exists(config.DATABASE):
21 shutil.rmtree(config.DATABASE)
22
23 def testSetSession(self):
24 self.sessions.set('random_key', text='hello, world!')
25 self.assertEqual(self.sessions.get('random_key', 'text'),
26 'hello, world!')
27
28 def testUpdateSession(self):
29 self.sessions.set('random_key', text='hello, world!')
30 self.assertEqual(self.sessions.get('random_key', 'text'),
31 'hello, world!')
32 self.sessions.set('random_key', text='nope')
33 self.assertEqual(self.sessions.get('random_key', 'text'), 'nope')
34
35 class DBMTest(SessionTest):
36 import roundup.backends.sessions_dbm as sessions_module
37
38 class RDBMSTest(SessionTest):
39 import roundup.backends.sessions_rdbms as sessions_module
40