diff --git a/product/ERP5Type/Core/Folder.py b/product/ERP5Type/Core/Folder.py index f3644af51a881caaa6bcd790fac49db10b809dd3..a6a2b029611f9662bfd1a6f37541a24753432f22 100644 --- a/product/ERP5Type/Core/Folder.py +++ b/product/ERP5Type/Core/Folder.py @@ -581,6 +581,21 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn, else: return CMFBTreeFolder._fixCount(self) + def _fixFolderHandler(self): + """Fixes _folder_handler if it is a string + + Bug affecting BTree folders in ERP5Type/patches/Folder.py introduced + string value for _folder_handler, which mades methods isBTree and isHBTree + fail. + + Returns True in case of founded and fixed error, in case + of no error returns False. + """ + if isinstance(self._folder_handler,str): + delattr(self, '_folder_handler') + return True + return False + def manage_cleanup(self): """Calls self._cleanup() and reports the result as text. """ diff --git a/product/ERP5Type/patches/BTreeFolder2.py b/product/ERP5Type/patches/BTreeFolder2.py index 528f8f11bbf29e230407b6d284ad5b8c03e10956..38ccba6946c06f9fdf8df335b3acbf9d822e06ce 100644 --- a/product/ERP5Type/patches/BTreeFolder2.py +++ b/product/ERP5Type/patches/BTreeFolder2.py @@ -97,10 +97,3 @@ def _cleanup(self): BTreeFolder2Base._cleanup = _cleanup -def __init__(self, id=None): - self._folder_handler = 'CMFBTreeFolderHandler' - if id is not None: - self.id = id - self._initBTrees() - -BTreeFolder2Base.__init__ = __init__ diff --git a/product/ERP5Type/tests/testFolderMigration.py b/product/ERP5Type/tests/testFolderMigration.py index bdb0f4e8f84b4109df20525ba3af569c7c1e7fab..78fdef59ad7c6bb3a57004b34db0e9fae18d1869 100644 --- a/product/ERP5Type/tests/testFolderMigration.py +++ b/product/ERP5Type/tests/testFolderMigration.py @@ -146,6 +146,19 @@ class TestFolderMigration(ERP5TypeTestCase, LogInterceptor): self.assertEqual(self.folder.isHBTree(), False) + def test_03a_filledFolderIsBtree(self, quiet=0, run=1): + """ + Test the folder is a BTree + """ + if not run : return + if not quiet: + message = 'Test FilledFolderIsBtree' + LOG('Testing... ', 0, message) + self.folder.newContent() + self.assertRaises(NotImplementedError, self.folder.getTreeIdList) + self.assertEqual(self.folder.isBTree(), True) + self.assertEqual(self.folder.isHBTree(), False) + def test_04_migrateEmptyFolder(self, quiet=0, run=1): """ migrate empty folder from btree to hbtree @@ -173,6 +186,10 @@ class TestFolderMigration(ERP5TypeTestCase, LogInterceptor): date = DateTime().Date() date = date.replace("/", "") self.failUnless(date in obj1.getId()) + # check we still have a hbtree + self.assertEqual(self.folder.isBTree(), False) + self.assertEqual(self.folder.isHBTree(), True) + self.assertEqual(len(self.folder.objectIds()), 1) def test_05_migrateFolderWithoutIdChange(self, quiet=0, run=1): """ @@ -493,6 +510,65 @@ class TestFolderMigration(ERP5TypeTestCase, LogInterceptor): self.assertEqual(len(self.folder.objectValues(base_id=id_prefix)), 3) + def test_13_wrongFolderHandlerFix(self, quiet=0, run=1): + if not run : return + if not quiet: + message = 'Test migrateFolder' + LOG('Testing... ', 0, message) + + self.assertEqual(self.folder.isBTree(), True) + self.assertEqual(self.folder.isHBTree(), False) + + setattr(self.folder,'_folder_handler','VeryWrongHandler') + get_transaction().commit() + self.tic() + + self.assertEqual(self.folder.isBTree(), False) + self.assertEqual(self.folder.isHBTree(), False) + + self.assertEquals(self.folder._fixFolderHandler(), True) + get_transaction().commit() + + self.assertEqual(self.folder.isBTree(), True) + self.assertEqual(self.folder.isHBTree(), False) + + self.folder.migrateToHBTree() + get_transaction().commit() + self.tic() + + self.assertEqual(self.folder.isBTree(), False) + self.assertEqual(self.folder.isHBTree(), True) + + def test_14_wrongFolderHandlerMigrate(self, quiet=0, run=1): + if not run : return + if not quiet: + message = 'Test migrateFolder' + LOG('Testing... ', 0, message) + + self.assertEqual(self.folder.isBTree(), True) + self.assertEqual(self.folder.isHBTree(), False) + + setattr(self.folder,'_folder_handler','VeryWrongHandler') + get_transaction().commit() + self.tic() + + self.assertEqual(self.folder.isBTree(), False) + self.assertEqual(self.folder.isHBTree(), False) + + self.folder.migrateToHBTree() + get_transaction().commit() + self.tic() + + self.assertEqual(self.folder.isBTree(), False) + self.assertEqual(self.folder.isHBTree(), True) + + self.folder.newContent() + get_transaction().commit() + self.tic() + + self.assertEqual(self.folder.isBTree(), False) + self.assertEqual(self.folder.isHBTree(), True) + def test_suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestFolderMigration))