1 import os, shutil, unittest
3 from db_test_base import config
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)
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)
23 def testList(self):
24 self.sessions.list()
25 self.sessions.set('random_key', text='hello, world!')
26 self.sessions.list()
28 def testGetAll(self):
29 self.sessions.set('random_key', text='hello, world!')
30 self.assertEqual(self.sessions.getall('random_key'),
31 {'text': 'hello, world!'})
33 def testDestroy(self):
34 self.sessions.set('random_key', text='hello, world!')
35 self.assertEquals(self.sessions.getall('random_key'),
36 {'text': 'hello, world!'})
37 self.sessions.destroy('random_key')
38 self.assertRaises(KeyError, self.sessions.getall, 'random_key')
40 def testSetSession(self):
41 self.sessions.set('random_key', text='hello, world!')
42 self.assertEqual(self.sessions.get('random_key', 'text'),
43 'hello, world!')
45 def testUpdateSession(self):
46 self.sessions.set('random_key', text='hello, world!')
47 self.assertEqual(self.sessions.get('random_key', 'text'),
48 'hello, world!')
49 self.sessions.set('random_key', text='nope')
50 self.assertEqual(self.sessions.get('random_key', 'text'), 'nope')
52 class DBMTest(SessionTest):
53 import roundup.backends.sessions_dbm as sessions_module
55 class RDBMSTest(SessionTest):
56 import roundup.backends.sessions_rdbms as sessions_module