[Checkins] SVN: zc.selenium/branches/wosc-zope2/ accept TemporaryStorage as well as DemoStorage to mean we are running in test mode, so we can do our DB-push/pop.
Wolfgang Schnerring
wosc at wosc.de
Thu Feb 19 02:16:00 EST 2009
Log message for revision 96720:
accept TemporaryStorage as well as DemoStorage to mean we are running in test mode, so we can do our DB-push/pop.
Changed:
U zc.selenium/branches/wosc-zope2/src/zc/selenium/dbs.py
U zc.selenium/branches/wosc-zope2/zope2.cfg
-=-
Modified: zc.selenium/branches/wosc-zope2/src/zc/selenium/dbs.py
===================================================================
--- zc.selenium/branches/wosc-zope2/src/zc/selenium/dbs.py 2009-02-19 07:14:08 UTC (rev 96719)
+++ zc.selenium/branches/wosc-zope2/src/zc/selenium/dbs.py 2009-02-19 07:16:00 UTC (rev 96720)
@@ -15,37 +15,74 @@
$Id: dbs.py 12602 2006-07-06 06:29:48Z fred $
"""
-
from ZODB.DemoStorage import DemoStorage
from ZODB.DB import DB
+ALLOWED_STORAGES = [DemoStorage]
-class PushDBs(object):
+# zope2 compatibility
+try:
+ from tempstorage.TemporaryStorage import TemporaryStorage
+ ALLOWED_STORAGES.append(TemporaryStorage)
+except ImportError:
+ pass
+
+class DatabaseAware(object):
+ def get_db(self):
+ try:
+ import Zope2
+ DB = Zope2.DB
+ except ImportError:
+ DB = self.request.publication.db
+ return DB
+
+ def set_db(self, db):
+ try:
+ import Zope2
+ Zope2.DB = db
+ except ImportError:
+ self.request.publication.db = db
+ return DB
+
+ db = property(get_db, set_db)
+
+ def is_demo_db(self):
+ for db in self.db.databases.values():
+ if not self.is_demo_storage(db._storage):
+ return False
+ return True
+
+ def is_demo_storage(self, storage):
+ for class_ in ALLOWED_STORAGES:
+ if isinstance(storage, class_):
+ return True
+ return False
+
+
+class PushDBs(DatabaseAware):
+ """Push DB"""
+
def __call__(self):
- publication = self.request.publication
- if [1
- for d in publication.db.databases.values()
- if not isinstance(d._storage, DemoStorage)
- ]:
+ if not self.is_demo_db():
raise RuntimeError("Wrong mode")
databases = {}
- for name, db in publication.db.databases.items():
+ for name, db in self.db.databases.items():
DB(DemoStorage(base=db._storage),
databases=databases, database_name=name,
)
- newdb = databases[publication.db.database_name]
- newdb.pushed_base = publication.db # hacking extra attr onto db
- publication.db = newdb
+ newdb = databases[self.db.database_name]
+ newdb.pushed_base = self.db # hacking extra attr onto db
+ self.db = newdb
return 'Done'
-class PopDBs(object):
+class PopDBs(DatabaseAware):
+ """Pop DB"""
+
def __call__(self):
- publication = self.request.publication
- publication.db = publication.db.pushed_base
-
+ self.db = self.db.pushed_base
return 'Done'
Modified: zc.selenium/branches/wosc-zope2/zope2.cfg
===================================================================
--- zc.selenium/branches/wosc-zope2/zope2.cfg 2009-02-19 07:14:08 UTC (rev 96719)
+++ zc.selenium/branches/wosc-zope2/zope2.cfg 2009-02-19 07:16:00 UTC (rev 96720)
@@ -34,6 +34,7 @@
http-address = 39858
debug-mode = on
verbose-security = on
+demo-storage = on
eggs = zc.selenium
# XXX: copied from Five, since plone.recipe.zope2instance can't deal with files
# called 'tests.zcml', only configure, meta and overrides. :-(
More information about the Checkins
mailing list