[Erp5-report] r42316 rafael - in /erp5/trunk/products/ERP5: Tool/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Jan 13 21:24:33 CET 2011


Author: rafael
Date: Thu Jan 13 21:24:33 2011
New Revision: 42316

URL: http://svn.erp5.org?rev=42316&view=rev
Log:

On updateBusinessTemplateFromUrl, do not install the business template or run any script if the business template was already installed with the same revision or newer. The Exception is if reinstall parameter is True.

Modified:
    erp5/trunk/products/ERP5/Tool/TemplateTool.py
    erp5/trunk/products/ERP5/tests/testBusinessTemplate.py

Modified: erp5/trunk/products/ERP5/Tool/TemplateTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Tool/TemplateTool.py?rev=42316&r1=42315&r2=42316&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Tool/TemplateTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Tool/TemplateTool.py [utf8] Thu Jan 13 21:24:33 2011
@@ -1199,6 +1199,12 @@ class TemplateTool (BaseTool):
         install_kw = dict.fromkeys(imported_bt5.getItemsList(), 'install')
       else:
         install_kw = {}
+        previous_bt5 = self.getInstalledBusinessTemplate(bt_title)
+        if previous_bt5 is not None and \
+            (imported_bt5.getRevision() <= previous_bt5.getRevision()):
+          log("%s is already installed with same or newer revision." % bt_title)
+          return imported_bt5
+
       for listbox_line in listbox_object_list:
         item = listbox_line.object_id
         state = listbox_line.object_state

Modified: erp5/trunk/products/ERP5/tests/testBusinessTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testBusinessTemplate.py?rev=42316&r1=42315&r2=42316&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testBusinessTemplate.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testBusinessTemplate.py [utf8] Thu Jan 13 21:24:33 2011
@@ -5690,21 +5690,42 @@ class TestBusinessTemplate(ERP5TypeTestC
   def test_updateBusinessTemplateFromUrl_simple(self):
     """
      Test updateBusinessTemplateFromUrl method
+
+     By default if a new business template has revision >= previous one
+     the new bt5 is not installed, only imported.
     """
     template_tool = self.portal.portal_templates
     old_bt = template_tool.getInstalledBusinessTemplate('erp5_csv_style')
+    # change revision to an old revision
+    old_bt.setRevision(0.0001)
     url = 'https://svn.erp5.org/repos/public/erp5/trunk/bt5/erp5_csv_style'
     template_tool.updateBusinessTemplateFromUrl(url)
     new_bt = template_tool.getInstalledBusinessTemplate('erp5_csv_style')
-
     self.assertNotEquals(old_bt, new_bt)
     self.assertEquals('erp5_csv_style', new_bt.getTitle())
+
+    # Test Another time with definning an ID
     old_bt = new_bt
+    old_bt.setRevision(0.0002)
     template_tool.updateBusinessTemplateFromUrl(url, id="new_erp5_csv_style")
     new_bt = template_tool.getInstalledBusinessTemplate('erp5_csv_style')
     self.assertNotEquals(old_bt, new_bt)
     self.assertEquals('erp5_csv_style', new_bt.getTitle())
     self.assertEquals('new_erp5_csv_style', new_bt.getId())
+    
+    # Test if the new instance with same revision is not installed.
+    old_bt = new_bt
+    template_tool.updateBusinessTemplateFromUrl(url, id="not_installed_bt5")
+    new_bt = template_tool.getInstalledBusinessTemplate('erp5_csv_style')
+    self.assertEquals(old_bt, new_bt)
+    self.assertEquals('erp5_csv_style', new_bt.getTitle())
+    self.assertEquals('new_erp5_csv_style', new_bt.getId())
+    not_installed_bt5 = getattr(template_tool, "not_installed_bt5", None)
+    self.assertNotEquals(not_installed_bt5, None)
+    self.assertEquals('erp5_csv_style', not_installed_bt5.getTitle())
+    self.assertEquals(not_installed_bt5.getInstallationState(), 
+                      "not_installed")
+    self.assertEquals(not_installed_bt5.getRevision(), new_bt.getRevision())
 
   def test_updateBusinessTemplateFromUrl_keep_list(self):
     """



More information about the Erp5-report mailing list