diff --git a/product/ERP5Type/tests/utils.py b/product/ERP5Type/tests/utils.py index c0d49234735c2b476c26fc7fd303f3f5d3ac6573..be82944084c3b27223d39e29a68eb88a2312345e 100644 --- a/product/ERP5Type/tests/utils.py +++ b/product/ERP5Type/tests/utils.py @@ -40,6 +40,8 @@ import Products.ERP5Type from Products.MailHost.MailHost import MailHost from email import message_from_string import backportUnittest +from Products.ERP5Type.Globals import PersistentMapping +from Products.ZSQLCatalog.SQLCatalog import Catalog class FileUpload(file): """Act as an uploaded file. @@ -542,3 +544,51 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list): cell.setMembershipCriterionCategoryList(membership_criterion_category_list) cell.edit(predicate_category_list=category_list, variation_category_list=category_list) + +def catalogObjectListWrapper(self, object_list, method_id_list=None, + disable_cache=0, check_uid=1, idxs=None): + """Wrapper to mark inside of portal object list of catalogged objects""" + import transaction + portal = self.getPortalObject() + for q in object_list: + portal.catalogged_object_path_dict[q.getPath()] = 1 + transaction.commit() + +class SubcontentReindexingWrapper(object): + def wrap_catalogObjectList(self): + self.original_catalogObjectList = Catalog.catalogObjectList + Catalog.catalogObjectList = catalogObjectListWrapper + + def unwrap_catalogObjectList(self): + Catalog.catalogObjectList = self.original_catalogObjectList + + def _testSubContentReindexing(self, parent_document, children_document_list): + """Helper method which shall be called *before* tic or commit""" + # cleanup existing reindexing + transaction.commit() + self.tic() + parent_document.reindexObject() + self.portal.catalogged_object_path_dict = PersistentMapping() + transaction.commit() + expected_path_list = [q.getPath() for q in children_document_list + + [parent_document]] + try: + # wrap call to catalogObjectList + self.wrap_catalogObjectList() + self.stepTic() + self.assertSameSet( + self.portal.catalogged_object_path_dict.keys(), + expected_path_list + ) + # do real assertions + self.portal.catalogged_object_path_dict = PersistentMapping() + transaction.commit() + parent_document.reindexObject() + self.stepTic() + self.assertSameSet( + self.portal.catalogged_object_path_dict.keys(), + expected_path_list + ) + finally: + # unwrap catalogObjectList + self.unwrap_catalogObjectList()