Mercurial > p > roundup > code
view test/session_common.py @ 5036:380d8d8b30a3
Replace existing run_tests.py script with a pytest script
The existing run_test.py script is quite old, a bit restrictive, and
doesn't always behave as documented. The pytest testing tool is mature,
well documented, and maintained.
The run_tests.py script is generating by installing py.test and running:
py.tests --genscript=run_tests.py
Note: to generate a script that is compatible with python2.6 the command
needs to be run using python2.6
| author | John Kristensen <john@jerrykan.com> |
|---|---|
| date | Thu, 20 Aug 2015 18:15:23 +1000 |
| parents | 63c79c0992ae |
| children | 62de601bdf6f |
line wrap: on
line source
import os, shutil, unittest from db_test_base import config class SessionTest(object): 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
