[Erp5-report] r35694 rafael - in /erp5/trunk/products/ERP5: Tool/ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri May 28 02:59:13 CEST 2010
Author: rafael
Date: Fri May 28 02:59:11 2010
New Revision: 35694
URL: http://svn.erp5.org?rev=35694&view=rev
Log:
Added updateBusinessTemplateFromUrl, this method allows you:
- Define after script list, before script list to be executed before/after bt5 installation.
- Define a list of keep_original, to avoid remove/add unwanted objects when install a business template.
This is usefull to automate user actions during a upgrade, It is not recommentd use it to hack and provide behaviours that should be part of default business template installations. after/before script should be used only by projects that requires specific procedures.
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=35694&r1=35693&r2=35694&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Tool/TemplateTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Tool/TemplateTool.py [utf8] Fri May 28 02:59:11 2010
@@ -40,6 +40,7 @@
from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions, tarfile
from Products.ERP5.Document.BusinessTemplate import BusinessTemplateMissingDependency
+from Acquisition import aq_base
from tempfile import mkstemp, mkdtemp
from Products.ERP5 import _dtmldir
from cStringIO import StringIO
@@ -135,14 +136,27 @@
DeprecationWarning('getInstalledBusinessTemplatesList is deprecated; Use getInstalledBusinessTemplateList instead.', DeprecationWarning)
return self.getInstalledBusinessTemplateList()
- def getInstalledBusinessTemplateList(self):
+ def _getInstalledBusinessTemplateList(self, only_title=0):
"""Get the list of installed business templates.
"""
installed_bts = []
for bt in self.contentValues(portal_type='Business Template'):
if bt.getInstallationState() == 'installed':
- installed_bts.append(bt)
+ bt5 = bt
+ if only_title:
+ bt5 = bt.getTitle()
+ installed_bts.append(bt5)
return installed_bts
+
+ def getInstalledBusinessTemplateList(self):
+ """Get the list of installed business templates.
+ """
+ return self._getInstalledBusinessTemplateList(only_title=0)
+
+ def getInstalledBusinessTemplateTitleList(self):
+ """Get the list of installed business templates.
+ """
+ return self._getInstalledBusinessTemplateList(only_title=1)
def getInstalledBusinessTemplateRevision(self, title, **kw):
"""
@@ -1053,6 +1067,42 @@
return opreation_log
security.declareProtected(Permissions.ManagePortal,
+ 'updateBusinessTemplateFromUrl')
+ def updateBusinessTemplateFromUrl(self, download_url, id=None,
+ keep_original_list=[],
+ before_triggered_bt5_id_list=[],
+ after_triggered_bt5_id_list=[],
+ update_catalog=0):
+ """
+ This method download and install a bt5, from a URL.
+ """
+ imported_bt5 = self.download(url = download_url, id = id)
+ BusinessTemplate_getModifiedObject = \
+ aq_base(getattr(self, 'BusinessTemplate_getModifiedObject'))
+
+ install_kw = {}
+ listbox_object_list = BusinessTemplate_getModifiedObject.__of__(imported_bt5)()
+ for listbox_line in listbox_object_list:
+ # if a bt5 item is removed we may still want to keep it
+ if (listbox_line.object_state in ('Removed', 'Removed but used', 'Modified', 'New') and
+ listbox_line.object_id in keep_original_list):
+ install_kw[listbox_line.object_id] = 'nothing' #Keep original
+ else:
+ install_kw[listbox_line.object_id] = listbox_line.choice_item_list[0][1]
+
+ # Run before script list
+ for before_triggered_bt5_id in before_triggered_bt5_id_list:
+ getattr(imported_bt5, before_triggered_bt5_id)()
+
+ imported_bt5.install(object_to_update=install_kw,
+ update_catalog=update_catalog)
+
+ # Run After script list
+ for after_triggered_bt5_id in after_triggered_bt5_id_list:
+ getattr(imported_bt5, after_triggered_bt5_id)()
+ LOG('ERP5', INFO, "Updated %s from %s" %(imported_bt5.getTitle(), download_url))
+
+ security.declareProtected(Permissions.ManagePortal,
'getBusinessTemplateUrl')
def getBusinessTemplateUrl(self, base_url_list, bt5_title):
"""
Modified: erp5/trunk/products/ERP5/tests/testBusinessTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testBusinessTemplate.py?rev=35694&r1=35693&r2=35694&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testBusinessTemplate.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testBusinessTemplate.py [utf8] Fri May 28 02:59:11 2010
@@ -5275,6 +5275,33 @@
self.assertNotEquals(None, self.getPortal()\
.portal_templates.getInstalledBusinessTemplate('erp5_core'))
+ def test_getInstalledBusinessTemplateList(self):
+ templates_tool = self.getPortal().portal_templates
+ bt5_list = templates_tool.getInstalledBusinessTemplateList()
+ another_bt_list = [ i for i in templates_tool.contentValues() \
+ if i.getInstallationState() == 'installed']
+ self.assertEquals(len(bt5_list), len(another_bt_list))
+ for bt in bt5_list:
+ self.failUnless(bt in another_bt_list)
+
+ self.assertEquals(bt5_list,
+ templates_tool._getInstalledBusinessTemplateList())
+
+ def test_getInstalledBusinessTemplateTitleList(self):
+ templates_tool = self.getPortal().portal_templates
+ bt5_list = templates_tool.getInstalledBusinessTemplateTitleList()
+ another_bt_list = [ i.getTitle() for i in templates_tool.contentValues() \
+ if i.getInstallationState() == 'installed']
+ bt5_list.sort()
+ another_bt_list.sort()
+ self.assertEquals(bt5_list, another_bt_list)
+ for bt in bt5_list:
+ self.failUnless(bt in another_bt_list)
+
+ new_list = templates_tool._getInstalledBusinessTemplateList(only_title=1)
+ new_list.sort()
+ self.assertEquals(bt5_list, new_list)
+
def test_CompareVersions(self):
"""Tests compare version on template tool. """
compareVersions = self.getPortal().portal_templates.compareVersions
@@ -5330,6 +5357,81 @@
self.assertEquals(test_web.getPortalType(), 'Business Template')
self.assertEquals(test_web.getTitle(), 'test_web')
self.assertTrue(test_web.getRevision())
+
+ def test_updateBusinessTemplateFromUrl_simple(self):
+ """
+ Test updateBusinessTemplateFromUrl method
+ """
+ template_tool = self.portal.portal_templates
+ old_bt = template_tool.getInstalledBusinessTemplate('erp5_csv_style')
+ 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())
+ old_bt = new_bt
+ 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())
+
+ def test_updateBusinessTemplateFromUrl_keep_list(self):
+ """
+ Test updateBusinessTemplateFromUrl method
+ """
+ template_tool = self.portal.portal_templates
+ url = 'https://svn.erp5.org/repos/public/erp5/trunk/bt5/test_core'
+ # don't install test_file
+ keep_original_list = ( 'portal_skins/erp5_test/test_file', )
+ template_tool.updateBusinessTemplateFromUrl(url,
+ keep_original_list=keep_original_list)
+ bt = template_tool.getInstalledBusinessTemplate('test_core')
+ self.assertNotEquals(None, bt)
+ erp5_test = getattr(self.portal.portal_skins, 'erp5_test', None)
+ self.assertNotEquals(None, erp5_test)
+ test_file = getattr(erp5_test, 'test_file', None)
+ self.assertEquals(None, test_file)
+
+ def test_updateBusinessTemplateFromUrl_after_before_script(self):
+ """
+ Test updateBusinessTemplateFromUrl method
+ """
+ from Products.ERP5Type.tests.utils import createZODBPythonScript
+ portal = self.getPortal()
+
+ createZODBPythonScript(portal.portal_skins.custom,
+ 'BT_dummyA',
+ 'scripts_params=None',
+ '# Script body\n'
+ 'return context.setDescription("MODIFIED")')
+
+ createZODBPythonScript(portal.portal_skins.custom,
+ 'BT_dummyB',
+ 'scripts_params=None',
+ '# Script body\n'
+ 'return context.setChangeLog("MODIFIED")')
+
+ createZODBPythonScript(portal.portal_skins.custom,
+ 'BT_dummyC',
+ 'scripts_params=None',
+ '# Script body\n'
+ 'return context.getPortalObject().setTitle("MODIFIED")')
+
+ template_tool = self.portal.portal_templates
+ url = 'https://svn.erp5.org/repos/public/erp5/trunk/bt5/test_html_style'
+ # don't install test_file
+ before_triggered_bt5_id_list = ['BT_dummyA', 'BT_dummyB']
+ after_triggered_bt5_id_list = ['BT_dummyC']
+ template_tool.updateBusinessTemplateFromUrl(url,
+ before_triggered_bt5_id_list=before_triggered_bt5_id_list,
+ after_triggered_bt5_id_list=after_triggered_bt5_id_list)
+ bt = template_tool.getInstalledBusinessTemplate('test_html_style')
+ self.assertNotEquals(None, bt)
+ self.assertEquals(bt.getDescription(), 'MODIFIED')
+ self.assertEquals(bt.getChangeLog(), 'MODIFIED')
+ self.assertEquals(portal.getTitle(), 'MODIFIED')
def stepCreateCustomWorkflow(self, sequence=None, sequence_list=None, **kw):
"""
More information about the Erp5-report
mailing list