Commit fbd88a68 authored by Jérome Perrin's avatar Jérome Perrin

BT5: fix bug in getInstalledBusinessTemplate with uninstalled bt

getInstalledBusinessTemplate was returning "replaced" versions of a business
template beeing uninstalled.
Also add some missing tests for getInstalledBusinessTemplate
parent 34ec455d
......@@ -114,9 +114,9 @@ class TemplateTool (BaseTool):
manage_overview = DTMLFile('explainTemplateTool', _dtmldir)
def getInstalledBusinessTemplate(self, title, strict=False, **kw):
"""
Return an installed version of business template of a certain title.
"""Returns an installed version of business template of a given title.
Returns None if business template is not installed or has been uninstalled.
It not "installed" business template is found, look at replaced ones.
This is mostly usefull if we are looking for the installed business
template in a transaction replacing an existing business template.
......@@ -132,7 +132,15 @@ class TemplateTool (BaseTool):
state = bt.getInstallationState()
if state == 'installed':
return bt
if state == 'replaced' and not strict:
if state == 'not_installed':
last_transition = bt.workflow_history \
['business_template_installation_workflow'][-1]
if last_transition['action'] == 'uninstall': # There is not uninstalled state !
t = last_transition['time']
if last_time < t:
last_bt = None
last_time = t
elif state == 'replaced' and not strict:
t = bt.workflow_history \
['business_template_installation_workflow'][-1]['time']
if last_time < t:
......
......@@ -5593,6 +5593,79 @@ class TestBusinessTemplate(BusinessTemplateMixin):
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_getInstalledBusinessTemplate_installed(self):
test_bt = self.portal.portal_templates.newContent(
portal_type='Business Template',
title='erp5_test_bt_%s' % self.id())
test_bt.install()
self.tic()
self.assertEqual(test_bt,
self.portal.portal_templates.getInstalledBusinessTemplate('erp5_test_bt_%s' % self.id()))
def test_getInstalledBusinessTemplate_erp5_core_installed(self):
erp5_core = self.portal.portal_templates.getInstalledBusinessTemplate('erp5_core')
self.assertNotEqual(None, erp5_core)
self.assertEqual('Business Template', erp5_core.getPortalType())
def test_getInstalledBusinessTemplate_not_installed(self):
self.assertEquals(None,
self.portal.portal_templates.getInstalledBusinessTemplate('not_installed'))
def test_getInstalledBusinessTemplate_provision(self):
test_bt = self.portal.portal_templates.newContent(
portal_type='Business Template',
title='test_bt',
provision_list=['erp5_test_bt_%s' % self.id()])
test_bt.install()
self.tic()
self.assertEqual(test_bt,
self.portal.portal_templates.getInstalledBusinessTemplate('erp5_test_bt_%s' % self.id()))
def test_getInstalledBusinessTemplate_replaced(self):
test_bt_v1 = self.portal.portal_templates.newContent(
portal_type='Business Template',
title='test_bt_%s' % self.id(),
version='1')
test_bt_v1.install()
self.tic()
test_bt_v2 = self.portal.portal_templates.newContent(
portal_type='Business Template',
title='test_bt_%s' % self.id(),
version='2')
test_bt_v2.install()
self.assertEqual('replaced', test_bt_v1.getInstallationState())
self.tic()
self.assertEqual(test_bt_v2,
self.portal.portal_templates.getInstalledBusinessTemplate('test_bt_%s' % self.id()))
def test_getInstalledBusinessTemplate_uninstalled(self):
test_bt = self.portal.portal_templates.newContent(
portal_type='Business Template',
title='test_bt_%s' % self.id())
test_bt.install()
test_bt.uninstall()
self.tic()
self.assertEqual(None,
self.portal.portal_templates.getInstalledBusinessTemplate('test_bt_%s' % self.id()))
def test_getInstalledBusinessTemplate_replaced_then_uninstalled(self):
test_bt_v1 = self.portal.portal_templates.newContent(
portal_type='Business Template',
title='test_bt_%s' % self.id(),
version='1')
test_bt_v1.install()
self.tic()
test_bt_v2 = self.portal.portal_templates.newContent(
portal_type='Business Template',
title='test_bt_%s' % self.id(),
version='2')
test_bt_v2.install()
self.assertEqual('replaced', test_bt_v1.getInstallationState())
self.tic()
test_bt_v2.uninstall()
self.assertEqual(None,
self.portal.portal_templates.getInstalledBusinessTemplate('test_bt_%s' % self.id()))
def test_checkDependencies(self):
from Products.ERP5.Document.BusinessTemplate import \
BusinessTemplateMissingDependency
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment