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 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""DBTab mount point (stored in ZODB). """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 import os
...@@ -24,25 +24,14 @@ from AccessControl.ZopeGuards import guarded_getattr ...@@ -24,25 +24,14 @@ from AccessControl.ZopeGuards import guarded_getattr
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from OFS.Folder import Folder from OFS.Folder import Folder
from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Mount import MountPoint from Mount import MountPoint
_www = os.path.join(os.path.dirname(__file__), 'www') _www = os.path.join(os.path.dirname(__file__), 'www')
configuration = None
def getConfiguration(): def getConfiguration():
from App.config import getConfiguration from App.config import getConfiguration
global configuration return getConfiguration().dbtab
if configuration is None:
configuration = getConfiguration().dbtab
return configuration
def setConfiguration(c):
global configuration
configuration = c
class SimpleTrailblazer: class SimpleTrailblazer:
"""Follows Zope paths. If a path is not found, creates a Folder. """Follows Zope paths. If a path is not found, creates a Folder.
......
...@@ -21,8 +21,8 @@ import Testing ...@@ -21,8 +21,8 @@ import Testing
import ZODB import ZODB
from OFS.Application import Application from OFS.Application import Application
from OFS.Folder import Folder from OFS.Folder import Folder
from Products.ZODBMountPoint.MountedObject \ import App.config
import setConfiguration, manage_addMounts, getMountPoint from Products.ZODBMountPoint.MountedObject import manage_addMounts, getMountPoint
from DBTab.DBTab import DBTab from DBTab.DBTab import DBTab
try: try:
...@@ -59,11 +59,18 @@ class TestDBConfig: ...@@ -59,11 +59,18 @@ class TestDBConfig:
def getSectionName(self): def getSectionName(self):
return self.name return self.name
original_config = None
class DBTabTests (unittest.TestCase): class DBTabTests (unittest.TestCase):
def setUp(self): 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(), databases = [TestDBConfig('test_main.fs', ['/']).getDB(),
TestDBConfig('test_mount1.fs', ['/mount1']).getDB(), TestDBConfig('test_mount1.fs', ['/mount1']).getDB(),
TestDBConfig('test_mount2.fs', ['/mount2']).getDB(), TestDBConfig('test_mount2.fs', ['/mount2']).getDB(),
...@@ -77,7 +84,9 @@ class DBTabTests (unittest.TestCase): ...@@ -77,7 +84,9 @@ class DBTabTests (unittest.TestCase):
for point in points: for point in points:
mount_points[point] = name mount_points[point] = name
conf = DBTab(mount_factories, mount_points) conf = DBTab(mount_factories, mount_points)
setConfiguration(conf) d = App.config.DefaultConfiguration()
d.dbtab = conf
App.config.setConfiguration(d)
self.conf = conf self.conf = conf
db = conf.getDatabase('/') db = conf.getDatabase('/')
self.db = db self.db = db
...@@ -90,8 +99,9 @@ class DBTabTests (unittest.TestCase): ...@@ -90,8 +99,9 @@ class DBTabTests (unittest.TestCase):
get_transaction().commit() # Get the mount points ready get_transaction().commit() # Get the mount points ready
def tearDown(self): def tearDown(self):
setConfiguration(None) App.config.setConfiguration(original_config)
get_transaction().abort() get_transaction().abort()
self.app._p_jar.close() self.app._p_jar.close()
del self.app del self.app
...@@ -100,7 +110,6 @@ class DBTabTests (unittest.TestCase): ...@@ -100,7 +110,6 @@ class DBTabTests (unittest.TestCase):
db.close() db.close()
del self.conf del self.conf
def testRead(self): def testRead(self):
self.assertEqual(self.app.mount1.id, 'mount1') self.assertEqual(self.app.mount1.id, 'mount1')
self.assertEqual(self.app.mount2.id, 'mount2') 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