From 280783b159aef19654cc1228be66194dc808d795 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Tue, 27 Jul 2010 14:29:16 +0000
Subject: [PATCH]  - provide utility class which can be used to check if
 subcontent of some object are reindexed upon parent reindexation, by checking
 list of to-be-indexed paths

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37289 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/tests/utils.py | 50 +++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/product/ERP5Type/tests/utils.py b/product/ERP5Type/tests/utils.py
index c0d4923473..be82944084 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()
-- 
2.30.9