[ZODB-Dev] ZODB4 and DemoStorage

Marius Gedminas mgedmin@codeworks.lt
Tue, 8 Apr 2003 13:10:23 +0300


Hi folks,

I'm trying to build a functional testing framework based on DemoStorage.
The docstring in demo.py suggests this is an intended use case:

"""
- Functional tests can load up the backing storage with initial state, then
  easily get back to that initial state by zapping the front storages.
"""

Here's how I am trying to do it:

  from zodb.db import DB
  from zodb.storage.mapping import MappingStorage
  from zodb.storage.demo import DemoStorage

  base_storage = MappingStorage("Base")
     # maybe MemoryFullStorage would be a better choice?

  db = DB(base_storage)
  ... bootstrap the DB (create root folder and essential services) ...
  db.close()

  ... and for each functional test case do:

    demo_storage = DemoStorage("Demo", base_storage)
    db = DB(demo_storage)
    ... do things with db ...
    db.close()

I have some reservations about it.  Closing the DB also closes the
storage, and I am not sure you just pass the same storage to a new DB
instance as if nothing had happened.

Comments?

BTW there's a bug in DemoStorage: newObjectId() returns oids that are
already in use by self._back.  DemoStorage.__init__ should set self._oid
to the last oid used by self._back.  I haven't found a public interface
method to do that (calling self._back.newObjectId() won't work if
self._back is read-only), so I think IStorage needs a new method,
lastObjectId().

Marius Gedminas
-- 
Codeworks is available for Zope consulting -- http://www.codeworks.lt/