Mercurial > p > roundup > code
comparison roundup/test/memorydb.py @ 6365:7f00fc5958ca
Make memorydb persistent across re-open
This allows memorydb to be used for more tests, in particular re-opening
with another user for checking permissions.
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Wed, 31 Mar 2021 12:49:28 +0200 |
| parents | 58817c3bf471 |
| children | 087cae2fbcea |
comparison
equal
deleted
inserted
replaced
| 6364:e8361bce72de | 6365:7f00fc5958ca |
|---|---|
| 36 config.MAIL_DOMAIN = "your.tracker.email.domain.example" | 36 config.MAIL_DOMAIN = "your.tracker.email.domain.example" |
| 37 config.TRACKER_WEB = "http://tracker.example/cgi-bin/roundup.cgi/bugs/" | 37 config.TRACKER_WEB = "http://tracker.example/cgi-bin/roundup.cgi/bugs/" |
| 38 return config | 38 return config |
| 39 | 39 |
| 40 def create(journaltag, create=True, debug=False, prefix=default_prefix): | 40 def create(journaltag, create=True, debug=False, prefix=default_prefix): |
| 41 # "Nuke" in-memory db | |
| 42 db_nuke('') | |
| 43 | |
| 41 db = Database(new_config(debug), journaltag) | 44 db = Database(new_config(debug), journaltag) |
| 42 | 45 |
| 43 # load standard schema | 46 # load standard schema |
| 44 if not prefix.startswith('/'): | 47 if not prefix.startswith('/'): |
| 45 prefix = os.path.join (os.path.dirname(__file__), prefix) | 48 prefix = os.path.join (os.path.dirname(__file__), prefix) |
| 212 - perhaps detect write collisions (related to above)? | 215 - perhaps detect write collisions (related to above)? |
| 213 """ | 216 """ |
| 214 | 217 |
| 215 dbtype = "memorydb" | 218 dbtype = "memorydb" |
| 216 | 219 |
| 220 # Make it a little more persistent across re-open | |
| 221 memdb = {} | |
| 222 | |
| 217 def __init__(self, config, journaltag=None): | 223 def __init__(self, config, journaltag=None): |
| 218 self.config, self.journaltag = config, journaltag | 224 self.config, self.journaltag = config, journaltag |
| 219 self.classes = {} | 225 self.classes = {} |
| 220 self.items = {} | |
| 221 self.ids = {} | |
| 222 self.journals = {} | |
| 223 self.files = {} | 226 self.files = {} |
| 224 self.tx_files = {} | 227 self.tx_files = {} |
| 225 self.security = security.Security(self) | 228 self.security = security.Security(self) |
| 226 self.stats = {'cache_hits': 0, 'cache_misses': 0, 'get_items': 0, | 229 self.stats = {'cache_hits': 0, 'cache_misses': 0, 'get_items': 0, |
| 227 'filtering': 0} | 230 'filtering': 0} |
| 234 self.dirtynodes = {} # keep track of the dirty nodes by class | 237 self.dirtynodes = {} # keep track of the dirty nodes by class |
| 235 self.newnodes = {} # keep track of the new nodes by class | 238 self.newnodes = {} # keep track of the new nodes by class |
| 236 self.destroyednodes = {}# keep track of the destroyed nodes by class | 239 self.destroyednodes = {}# keep track of the destroyed nodes by class |
| 237 self.transactions = [] | 240 self.transactions = [] |
| 238 self.tx_Source = None | 241 self.tx_Source = None |
| 242 # persistence across re-open | |
| 243 self.items = self.__class__.memdb.get('items', {}) | |
| 244 self.ids = self.__class__.memdb.get('ids', {}) | |
| 245 self.journals = self.__class__.memdb.get('journals', {}) | |
| 239 | 246 |
| 240 def filename(self, classname, nodeid, property=None, create=0): | 247 def filename(self, classname, nodeid, property=None, create=0): |
| 241 shutil.copyfile(__file__, __file__+'.dummy') | 248 shutil.copyfile(__file__, __file__+'.dummy') |
| 242 return __file__+'.dummy' | 249 return __file__+'.dummy' |
| 243 | 250 |
| 288 self.clearCache() | 295 self.clearCache() |
| 289 self.tx_files = {} | 296 self.tx_files = {} |
| 290 # kill the schema too | 297 # kill the schema too |
| 291 self.classes = {} | 298 self.classes = {} |
| 292 # just keep the .items | 299 # just keep the .items |
| 300 # persistence across re-open | |
| 301 self.__class__.memdb['items'] = self.items | |
| 302 self.__class__.memdb['ids'] = self.ids | |
| 303 self.__class__.memdb['journals'] = self.journals | |
| 293 | 304 |
| 294 # | 305 # |
| 295 # Classes | 306 # Classes |
| 296 # | 307 # |
| 297 def __getattr__(self, classname): | 308 def __getattr__(self, classname): |
| 470 properties['nosy'] = hyperdb.Multilink("user", do_journal="no") | 481 properties['nosy'] = hyperdb.Multilink("user", do_journal="no") |
| 471 if 'superseder' not in properties: | 482 if 'superseder' not in properties: |
| 472 properties['superseder'] = hyperdb.Multilink(classname) | 483 properties['superseder'] = hyperdb.Multilink(classname) |
| 473 Class.__init__(self, db, classname, **properties) | 484 Class.__init__(self, db, classname, **properties) |
| 474 | 485 |
| 486 # Methods to check for existence and nuke the db | |
| 487 # We don't support multiple named databases | |
| 488 | |
| 489 def db_exists(name): | |
| 490 return bool(Database.memdb) | |
| 491 | |
| 492 def db_nuke(name): | |
| 493 Database.memdb = {} | |
| 494 | |
| 475 # vim: set et sts=4 sw=4 : | 495 # vim: set et sts=4 sw=4 : |
