From c148487bcdcc0b9a4fe286d602bb0a20ef85e75f Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Tue, 19 Feb 2008 08:56:39 +0000
Subject: [PATCH] Generate object_to_update dictionary automaticaly when
 upgrading, as it would be when upgrade is done via web interface.

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

diff --git a/product/ERP5Type/tests/ERP5TypeTestCase.py b/product/ERP5Type/tests/ERP5TypeTestCase.py
index 42f3ef0cf0..4b13357c8b 100644
--- a/product/ERP5Type/tests/ERP5TypeTestCase.py
+++ b/product/ERP5Type/tests/ERP5TypeTestCase.py
@@ -645,22 +645,33 @@ def setupERP5Site( business_template_list=(),
               removeLocalConstraint(id_)
 
           update_business_templates = os.environ.get('update_business_templates') is not None
+          BusinessTemplate_getModifiedObject = aq_base(getattr(portal, 'BusinessTemplate_getModifiedObject', None))
 
           # Disable reindexing before adding templates
           # VERY IMPORTANT: Add some business templates
           for url, title in business_template_list:
             start = time.time()
+            get_install_kw = False
             if title in [x.getTitle() for x in portal.portal_templates.getInstalledBusinessTemplateList()]:
               if update_business_templates:
                 if not quiet:
                   ZopeTestCase._print('Updating %s business template ... ' % title)
+                if BusinessTemplate_getModifiedObject is not None:
+                  get_install_kw = True
               else:
                 continue
             else:
               if not quiet:
                 ZopeTestCase._print('Adding %s business template ... ' % title)
             bt = portal.portal_templates.download(url)
-            bt.install(light_install=light_install)
+            if not quiet:
+              ZopeTestCase._print('(downloaded in %.3fs) ' % (time.time() - start))
+            install_kw = {}
+            if get_install_kw:
+              listbox_object_list = BusinessTemplate_getModifiedObject.__of__(bt)()
+              for listbox_line in listbox_object_list:
+                install_kw[listbox_line.object_id] = listbox_line.choice_item_list[0][1]
+            bt.install(light_install=light_install, object_to_update=install_kw)
             # Release locks
             get_transaction().commit()
             if not quiet:
-- 
2.30.9