From 3c9ca89cb2e65676758a85bce57d88db88a8eb5c Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Fri, 28 Dec 2007 12:35:46 +0000
Subject: [PATCH] Check that renaming objects preserve their uid. Check that
 renaming an object with a subobject updates subobject path.

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

diff --git a/product/ERP5Type/tests/testERP5Type.py b/product/ERP5Type/tests/testERP5Type.py
index bcc6afad09..6023881fd2 100644
--- a/product/ERP5Type/tests/testERP5Type.py
+++ b/product/ERP5Type/tests/testERP5Type.py
@@ -1838,6 +1838,49 @@ class TestPropertySheet:
       self.assertRaises(ValueError, getattr, not_ok, 'attr')
       self.assertFalse(hasattr(not_ok, 'attr'))
 
+    def test_renameObjectsPreservesUid(self, quiet=quiet, run=run_all_test):
+      """Test that object renaming preserves original uid.
+         This features allows to avoid reindexing all related objects, as it
+         can be extremely costly.
+      """
+      if not run: return
+      folder = self.getOrganisationModule()
+      initial_id = 'foo'
+      final_id = 'bar'
+      folder.newContent(portal_type='Organisation', id=initial_id)
+      get_transaction().commit()
+      self.tic()
+      folder = self.getOrganisationModule()
+      document = folder[initial_id]
+      initial_uid = document.uid
+      folder.manage_renameObjects([initial_id], [final_id])
+      get_transaction().commit()
+      self.tic()
+      folder = self.getOrganisationModule()
+      document = folder[final_id]
+      self.assertEqual(initial_uid, document.uid)
+
+    def test_renameObjectsReindexSubobjects(self, quiet=quiet, run=run_all_test):
+      """Test that renaming an object with subobjects causes them to be
+         reindexed (their path must be updated).
+      """
+      if not run: return
+      folder = self.getOrganisationModule()
+      initial_id = 'foo'
+      final_id = 'bar'
+      subdocument_id = 'sub'
+      object = folder.newContent(portal_type='Organisation', id=initial_id)
+      object.newContent(id=subdocument_id)
+      get_transaction().commit()
+      self.tic()
+      folder = self.getOrganisationModule()
+      folder.manage_renameObjects([initial_id], [final_id])
+      get_transaction().commit()
+      self.tic()
+      folder = self.getOrganisationModule()
+      subdocument = folder[final_id][subdocument_id]
+      subdocument_catalogged_path = self.getPortalObject().portal_catalog.getSQLCatalog()[subdocument.uid].path
+      self.assertEqual(subdocument.getPath(), subdocument_catalogged_path)
 
 def test_suite():
   suite = unittest.TestSuite()
-- 
2.30.9