Commit e2d87bee authored by Chris McDonough's avatar Chris McDonough

Dont maintain a configuration separate from that of the global config by using...

Dont maintain a configuration separate from that of the global config by using a module-scope global.  This causes problems when the global config changes (the
changes are not picked up here).  This is typically an issue when running unit tests.
parent 78cfa693
......@@ -13,7 +13,7 @@
##############################################################################
"""DBTab mount point (stored in ZODB).
$Id: MountedObject.py,v 1.1 2003/07/20 02:56:01 chrism Exp $
$Id: MountedObject.py,v 1.2 2003/12/20 16:58:57 chrism Exp $
"""
import os
......@@ -24,25 +24,14 @@ from AccessControl.ZopeGuards import guarded_getattr
from OFS.SimpleItem import SimpleItem
from OFS.Folder import Folder
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Mount import MountPoint
_www = os.path.join(os.path.dirname(__file__), 'www')
configuration = None
def getConfiguration():
from App.config import getConfiguration
global configuration
if configuration is None:
configuration = getConfiguration().dbtab
return configuration
def setConfiguration(c):
global configuration
configuration = c
return getConfiguration().dbtab
class SimpleTrailblazer:
"""Follows Zope paths. If a path is not found, creates a Folder.
......
......@@ -21,8 +21,8 @@ import Testing
import ZODB
from OFS.Application import Application
from OFS.Folder import Folder
from Products.ZODBMountPoint.MountedObject \
import setConfiguration, manage_addMounts, getMountPoint
import App.config
from Products.ZODBMountPoint.MountedObject import manage_addMounts, getMountPoint
from DBTab.DBTab import DBTab
try:
......@@ -59,11 +59,18 @@ class TestDBConfig:
def getSectionName(self):
return self.name
original_config = None
class DBTabTests (unittest.TestCase):
def setUp(self):
global original_config
if original_config is None:
# stow away original config so we can reset it
original_config = App.config.getConfiguration()
databases = [TestDBConfig('test_main.fs', ['/']).getDB(),
TestDBConfig('test_mount1.fs', ['/mount1']).getDB(),
TestDBConfig('test_mount2.fs', ['/mount2']).getDB(),
......@@ -77,7 +84,9 @@ class DBTabTests (unittest.TestCase):
for point in points:
mount_points[point] = name
conf = DBTab(mount_factories, mount_points)
setConfiguration(conf)
d = App.config.DefaultConfiguration()
d.dbtab = conf
App.config.setConfiguration(d)
self.conf = conf
db = conf.getDatabase('/')
self.db = db
......@@ -90,8 +99,9 @@ class DBTabTests (unittest.TestCase):
get_transaction().commit() # Get the mount points ready
def tearDown(self):
setConfiguration(None)
App.config.setConfiguration(original_config)
get_transaction().abort()
self.app._p_jar.close()
del self.app
......@@ -100,7 +110,6 @@ class DBTabTests (unittest.TestCase):
db.close()
del self.conf
def testRead(self):
self.assertEqual(self.app.mount1.id, 'mount1')
self.assertEqual(self.app.mount2.id, 'mount2')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment