Commit 755db8f7 authored by Łukasz Nowak's avatar Łukasz Nowak

- remove not needed patch to BTreeFolder2

 - add fix method for BTree if its _folder_handler is set to string
 - add tests:
   - to check if it is possible to recover functionality of isBTree and isHBTree methods using _fixFolderHandler
   - that BTree after adding content is still BTree while using isBTree (same for HBTree)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26327 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fcecb66b
......@@ -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.
"""
......
......@@ -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__
......@@ -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))
......
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