diff --git a/doc/CHANGES.txt b/doc/CHANGES.txt index a6fff0d3827e2555182de3b1efb081ae0b7ecfc8..1c0d472a54488fea5449c7f3dd1c185a3f30dbe1 100644 --- a/doc/CHANGES.txt +++ b/doc/CHANGES.txt @@ -27,6 +27,9 @@ Zope Changes Bugs fixed + - OFS ObjectManager: Fixed list_imports() to tolerate missing + import directories. + - Collector #1965: 'get_transaction' missing from builtins without sufficient deprecation notice (ZODB 3.6 properly removed it, but Zope needs to keep it for another release). diff --git a/lib/python/OFS/ObjectManager.py b/lib/python/OFS/ObjectManager.py index 2170b5ddce747b043f2a9362c13ca1b3098d6c5f..068b9eb208c12d2101d6382e6231a60a006aabee 100644 --- a/lib/python/OFS/ObjectManager.py +++ b/lib/python/OFS/ObjectManager.py @@ -619,6 +619,8 @@ class ObjectManager( paths.append(cfg.instancehome) for impath in paths: directory = os.path.join(impath, 'import') + if not os.path.isdir(directory): + continue listing += [f for f in os.listdir(directory) if f.endswith('.zexp') or f.endswith('.xml')] return listing diff --git a/lib/python/OFS/tests/testObjectManager.py b/lib/python/OFS/tests/testObjectManager.py index 0776ebd3c87692e8cf6818e0b19963cafa5614b8..3029628a808e93ced9da87ffad4b5755cb169a23 100644 --- a/lib/python/OFS/tests/testObjectManager.py +++ b/lib/python/OFS/tests/testObjectManager.py @@ -108,7 +108,6 @@ class ObjectManagerTests(PlacelessSetup, unittest.TestCase): self.assertEqual( si.__ac_local_roles__, None ) def test_setObject_set_owner_with_emergency_user( self ): - om = self._makeOne() newSecurityManager( None, emergency_user ) @@ -380,6 +379,16 @@ class ObjectManagerTests(PlacelessSetup, unittest.TestCase): self.assertRaises(BadRequest, om._setObject, 'REQUEST', si) self.assertRaises(BadRequest, om._setObject, '/', si) + def test_list_imports(self): + om = self._makeOne() + # This must work whether we've done "make instance" or not. + # So list_imports() may return an empty list, or whatever's + # in skel/import. Tolerate both cases. + self.failUnless(isinstance(om.list_imports(), list)) + for filename in om.list_imports(): + self.failUnless(filename.endswith('.zexp') or + filename.endswith('.xml')) + def test_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite( ObjectManagerTests ) )