Commit 7c156abf authored by Jérome Perrin's avatar Jérome Perrin

XMLMatrix.py:

 * call _delObject before changing the id of the object we are deleting in
 setCellRange (similar to r26610)

tests/testXMLMatrix.py:
 * creates cells in the test before testing setCellRange, to make sure that it
 works with existing cells.
 * use LogInterceptor to make sure there are no error logged. This shows that
 we get duplicate uids if we don't have portal_activities, but i'm not sure
 this is a real problem, is ERP5 supposed to work without portal_activities ?



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27576 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e780a00a
...@@ -231,10 +231,9 @@ class XMLMatrix(Folder): ...@@ -231,10 +231,9 @@ class XMLMatrix(Folder):
for object_id in object_id_list: for object_id in object_id_list:
new_name = 'temp_' + object_id new_name = 'temp_' + object_id
obj = self._getOb(object_id) obj = self._getOb(object_id)
obj.isIndexable = 0 # Disable reindexing while moving cells self._delObject(object_id)
obj.id = new_name obj.id = new_name
self._setObject(new_name, aq_base(obj)) self._setObject(new_name, aq_base(obj))
self._delObject(object_id)
# Rename all cells to their final name. # Rename all cells to their final name.
for object_id in object_id_list: for object_id in object_id_list:
...@@ -270,13 +269,13 @@ class XMLMatrix(Folder): ...@@ -270,13 +269,13 @@ class XMLMatrix(Folder):
if not to_delete and not (None in object_place): if not to_delete and not (None in object_place):
o = self._getOb('temp_' + object_id) o = self._getOb('temp_' + object_id)
self._delObject('temp_' + object_id) # In all cases, we have
# to remove the temp object
new_name = base_id + '_' + join(object_place,'_') new_name = base_id + '_' + join(object_place,'_')
o.id = new_name o.id = new_name
new_object_id_list.extend(new_name) new_object_id_list.extend(new_name)
self._setObject(new_name, aq_base(o)) self._setObject(new_name, aq_base(o))
self._delObject('temp_' + object_id) # In all cases, we have
# to remove the temp object
o.isIndexable = 1 # reindexing is possible again
if new_name != object_id: if new_name != object_id:
# Theses two lines are very important, if the object is renamed # Theses two lines are very important, if the object is renamed
# then we must uncatalog the previous one # then we must uncatalog the previous one
......
...@@ -31,8 +31,10 @@ import unittest ...@@ -31,8 +31,10 @@ import unittest
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.CMFCore.tests.base.testcase import LogInterceptor
from Products.ERP5Type.Utils import cartesianProduct from Products.ERP5Type.Utils import cartesianProduct
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from zLOG import PROBLEM
try: try:
from transaction import get as get_transaction from transaction import get as get_transaction
...@@ -40,7 +42,7 @@ except ImportError: ...@@ -40,7 +42,7 @@ except ImportError:
pass pass
class TestXMLMatrix(ERP5TypeTestCase): class TestXMLMatrix(ERP5TypeTestCase, LogInterceptor):
""" """
Tests the Cell API Tests the Cell API
""" """
...@@ -70,6 +72,11 @@ class TestXMLMatrix(ERP5TypeTestCase): ...@@ -70,6 +72,11 @@ class TestXMLMatrix(ERP5TypeTestCase):
module = portal.purchase_order_module module = portal.purchase_order_module
if '1' not in module.objectIds(): if '1' not in module.objectIds():
order = module.newContent(id='1', portal_type='Purchase Order') order = module.newContent(id='1', portal_type='Purchase Order')
self._catch_log_errors(ignored_level=PROBLEM)
def beforeTearDown(self):
self._ignore_log_errors()
def test_01_RenameCellRange(self, quiet=quiet): def test_01_RenameCellRange(self, quiet=quiet):
""" """
...@@ -260,6 +267,59 @@ class TestXMLMatrix(ERP5TypeTestCase): ...@@ -260,6 +267,59 @@ class TestXMLMatrix(ERP5TypeTestCase):
cell_path = url + '/' + id cell_path = url + '/' + id
self.assertEquals(catalog.hasPath(cell_path),False) self.assertEquals(catalog.hasPath(cell_path),False)
# create some cells
cell1 = matrix.newCell(*['0', 'a'], **kwd)
cell1_path = cell1.getPath()
cell2 = matrix.newCell(*['1', 'a'], **kwd)
cell2_path = cell2.getPath()
get_transaction().commit()
# if we keep the same range, nothing happens
matrix.setCellRange(*cell_range, **kwd)
get_transaction().commit()
self.assertEqual(matrix.getCellRange(**kwd), cell_range)
self.assertEqual(len(matrix.getCellValueList(**kwd)), 2)
self.tic()
self.assertTrue(catalog.hasPath(matrix.getPath()))
self.assertTrue(catalog.hasPath(cell1_path))
self.assertTrue(catalog.hasPath(cell2_path))
# now set other ranges
cell_range = [['0', '2'], ['a', ], ['Z']]
matrix.setCellRange(*cell_range, **kwd)
get_transaction().commit()
self.assertEqual(matrix.getCellRange(**kwd), cell_range)
self.tic()
# in this case, cells has been removed
self.assertEqual(matrix.getCellValueList(**kwd), [])
self.assertTrue(catalog.hasPath(matrix.getPath()))
self.assertFalse(catalog.hasPath(cell1_path))
self.assertFalse(catalog.hasPath(cell2_path))
# create cells in this new range
cell1 = matrix.newCell(*['0', 'a', 'Z'], **kwd)
cell1_path = cell1.getPath()
cell2 = matrix.newCell(*['2', 'a', 'Z'], **kwd)
cell2_path = cell2.getPath()
get_transaction().commit()
cell_range = [['1', '2'], ['a', ], ['X']]
matrix.setCellRange(*cell_range, **kwd)
get_transaction().commit()
self.assertEqual(matrix.getCellRange(**kwd), cell_range)
self.tic()
# in this case, cells has been removed
self.assertEqual(matrix.getCellValueList(**kwd), [])
self.assertTrue(catalog.hasPath(matrix.getPath()))
self.assertFalse(catalog.hasPath(cell1_path))
self.assertFalse(catalog.hasPath(cell2_path))
def test_02_SetCellRangeAndCatalogWithActivities(self, quiet=quiet): def test_02_SetCellRangeAndCatalogWithActivities(self, quiet=quiet):
""" """
Tests if set Cell range do well catalog and uncatalog, using activities Tests if set Cell range do well catalog and uncatalog, using activities
......
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