"Fossies" - the Fresh Open Source Software Archive

Member "roundup-2.0.0/test/session_common.py" (26 Aug 2019, 1764 Bytes) of package /linux/www/roundup-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "session_common.py": 1.6.1_vs_2.0.0.

    1 import os, shutil, unittest
    2 
    3 from .db_test_base import config
    4 
    5 
    6 class SessionTest(object):
    7     def setUp(self):
    8         # remove previous test, ignore errors
    9         if os.path.exists(config.DATABASE):
   10             shutil.rmtree(config.DATABASE)
   11         os.makedirs(config.DATABASE + '/files')
   12         self.db = self.module.Database(config, 'admin')
   13         self.sessions = self.db.getSessionManager()
   14         self.otks = self.db.getOTKManager()
   15 
   16     def tearDown(self):
   17         if hasattr(self, 'db'):
   18             self.db.close()
   19         if os.path.exists(config.DATABASE):
   20             shutil.rmtree(config.DATABASE)
   21 
   22     def testList(self):
   23         self.sessions.list()
   24         self.sessions.set('random_key', text='hello, world!')
   25         self.sessions.list()
   26 
   27     def testGetAll(self):
   28         self.sessions.set('random_key', text='hello, world!')
   29         self.assertEqual(self.sessions.getall('random_key'),
   30             {'text': 'hello, world!'})
   31 
   32     def testDestroy(self):
   33         self.sessions.set('random_key', text='hello, world!')
   34         self.assertEqual(self.sessions.getall('random_key'),
   35             {'text': 'hello, world!'})
   36         self.sessions.destroy('random_key')
   37         self.assertRaises(KeyError, self.sessions.getall, 'random_key')
   38 
   39     def testSetSession(self):
   40         self.sessions.set('random_key', text='hello, world!')
   41         self.assertEqual(self.sessions.get('random_key', 'text'),
   42             'hello, world!')
   43 
   44     def testUpdateSession(self):
   45         self.sessions.set('random_key', text='hello, world!')
   46         self.assertEqual(self.sessions.get('random_key', 'text'),
   47             'hello, world!')
   48         self.sessions.set('random_key', text='nope')
   49         self.assertEqual(self.sessions.get('random_key', 'text'), 'nope')
   50