Mercurial > p > roundup > code
view test/test_memorydb.py @ 6808:375d40a9e730
Add tests to BasicDatabase and merge implementations
test/session_common.py:
add new tests:
* test set with bad __timestamps
* test get on missing item with no default
* test clear() method
* test new lifetime() method
everything below here was needed to get the tests to work across all
db's.
roundup/backends/sessions_dbm.py:
make set() validate __timestamp as float. If invalid and item is new,
set it to time.time(). If invalid and item exists keep original
timestamp.
add lifetime(key_lifetime) method. Given key_lifetime in seconds,
generate a __timestamp that will be deleted after that many seconds.
roundup/backends/sessions_rdbms.py:
make set() behave the same as session_dbm.
add lifetime method as above.
roundup/backends/sessions_sqlite.py:
import session_rdbms::BasicDatabase and override __init__.
rather than cloning all the code. Kept a few logging and sql methods.
roundup/test/memorydb.py:
make get() on a missing key return KeyError
make set() conform to dbm/rdbms implementations.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 25 Jul 2022 21:21:26 -0400 |
| parents | bdd28b244839 |
| children | 74cafb11351f |
line wrap: on
line source
import unittest, os, shutil, time from roundup import hyperdb from .db_test_base import DBTest, ROTest, SchemaTest, config, setupSchema from roundup.test import memorydb from roundup.anypy import strings class memorydbOpener: module = memorydb def nuke_database(self): # really kill it memorydb.db_nuke('') self.db = None db = None def open_database(self, user='admin'): if self.db: self.db.close() self.db = self.module.Database(config, user) return self.db def setUp(self): self.open_database() setupSchema(self.db, 1, self.module) def tearDown(self): if self.db is not None: self.db.close() self.db = None self.nuke_database() # nuke and re-create db for restore def nukeAndCreate(self): self.db.close() self.nuke_database() self.db = self.module.Database(config, 'admin') setupSchema(self.db, 0, self.module) class memorydbDBTest(memorydbOpener, DBTest, unittest.TestCase): pass class memorydbROTest(memorydbOpener, ROTest, unittest.TestCase): def setUp(self): self.db = self.module.Database(config) setupSchema(self.db, 0, self.module) class memorydbSchemaTest(memorydbOpener, SchemaTest, unittest.TestCase): pass from .session_common import SessionTest class memorydbSessionTest(memorydbOpener, SessionTest, unittest.TestCase): s2b = lambda x,y: strings.s2b(y) def setUp(self): self.db = self.module.Database(config, 'admin') setupSchema(self.db, 1, self.module) self.sessions = self.db.sessions # doesn't work for memory as it uses a mock for session db. def testUpdateTimestamp(self): pass # vim: set filetype=python ts=4 sw=4 et si
