Commit 3a9bece1 authored by Rafael Monnerat's avatar Rafael Monnerat

Introduce API to resolve Dependencies for a List of Business Templates

The API resolveBusinessTemplateListDependency is able to return a list
of BT5 with URL and include all dependencies.
parent 2b25063a
......@@ -1233,6 +1233,52 @@ class TemplateTool (BaseTool):
return self.installBusinessTemplateListFromRepository(template_list,
only_newer, update_catalog, activate=False)
security.declareProtected(Permissions.ManagePortal,
'resolveBusinessTemplateListDependency')
def resolveBusinessTemplateListDependency(self, template_title_list,
newest_only=True):
available_bt5_list = self.getRepositoryBusinessTemplateList(
newest_only=newest_only)
installed_bt5_title_list = self.getInstalledBusinessTemplateTitleList()
bt5_set = set([])
for available_bt5 in available_bt5_list:
if available_bt5.title in template_title_list:
document = self.getInstalledBusinessTemplate(available_bt5.title)
if not newest_only or document is None or (document is not None and \
(int(document.getRevision()) < int(available_bt5.getRevision()))):
bt5 = self.decodeRepositoryBusinessTemplateUid(available_bt5.uid)
bt5_set.add(bt5)
for dep_repository, dep_id in self.getDependencyList(bt5):
if dep_repository != 'meta':
bt5_set.add((dep_repository, dep_id))
else:
provider_list = self.getProviderList(dep_id)
provider_installed = False
for provider in provider_list:
if provider in [i[1].replace(".bt5", "") for i in bt5_set] or \
provider in installed_bt5_title_list or \
provider in template_title_list:
provider_installed = True
break
if not provider_installed:
if len(provider_list) == 1:
for candidate in available_bt5_list:
if candidate.title == provider_list[0]:
bt5_set.add(\
self.decodeRepositoryBusinessTemplateUid(
candidate.uid))
break
else:
raise BusinessTemplateMissingDependency,\
"Unable to resolve dependencies for %s, options are %s" \
% (dep_id, provider_list)
return self.sortBusinessTemplateList(list(bt5_set))
security.declareProtected(Permissions.ManagePortal,
'installBusinessTemplateListFromRepository')
def installBusinessTemplateListFromRepository(self, template_list,
......
......@@ -354,6 +354,68 @@ class TestTemplateTool(ERP5TypeTestCase):
self.assertEquals(getBusinessTemplateUrl(url_list[2:], not_exist_bt5), None)
self.assertEquals(getBusinessTemplateUrl(url_list[3:], not_exist_bt5), None)
self.assertEquals(getBusinessTemplateUrl(url_list[4:], not_exist_bt5), None)
def test_resolveBusinessTemplateListDependency(self):
""" Test API able to return a complete list of bt5s to setup a sub set of
business templates.
"""
repository = "http://www.erp5.org/dists/snapshot/bt5/"
template_tool = self.portal.portal_templates
bt5_id_list = ['erp5_accounting']
bt5_list = template_tool.resolveBusinessTemplateListDependency(bt5_id_list)
self.assertEquals([(repository, 'erp5_simulation.bt5'),
(repository, 'erp5_accounting.bt5')], bt5_list)
bt5_id_list = ['erp5_csv_style']
bt5_list = template_tool.resolveBusinessTemplateListDependency(bt5_id_list)
self.assertEquals([], bt5_list)
bt5_list = template_tool.resolveBusinessTemplateListDependency(
bt5_id_list, False)
self.assertEquals([(repository, 'erp5_csv_style.bt5')], bt5_list)
bt5_id_list = ['erp5_base']
bt5_list = template_tool.resolveBusinessTemplateListDependency(
bt5_id_list, True)
self.assertEquals([], bt5_list)
bt5_id_list = ['erp5_configurator_ung']
bt5_list = template_tool.resolveBusinessTemplateListDependency(bt5_id_list)
self.assertEquals([(repository, 'erp5_workflow.bt5'),
(repository, 'erp5_configurator.bt5'),
(repository, 'erp5_configurator_ung.bt5')], bt5_list)
bt5_id_list = ['erp5_configurator_ung', 'erp5_accounting', 'erp5_invoicing',
'erp5_crm']
bt5_list = template_tool.resolveBusinessTemplateListDependency(bt5_id_list)
self.assertEquals([(repository, 'erp5_ingestion_mysql_innodb_catalog.bt5'),
(repository, 'erp5_workflow.bt5'),
(repository, 'erp5_simulation.bt5'),
(repository, 'erp5_pdm.bt5'),
(repository, 'erp5_ingestion.bt5'),
(repository, 'erp5_configurator.bt5'),
(repository, 'erp5_trade.bt5'),
(repository, 'erp5_accounting.bt5'),
(repository, 'erp5_crm.bt5'),
(repository, 'erp5_configurator_ung.bt5'),
(repository, 'erp5_invoicing.bt5')], bt5_list)
bt5_id_list = ['erp5_base']
self.assertRaises(BusinessTemplateMissingDependency,
template_tool.resolveBusinessTemplateListDependency,
bt5_id_list, False)
bt5_id_list = ['erp5_dms', 'erp5_full_text_myisam_catalog', 'erp5_base']
bt5_list = template_tool.resolveBusinessTemplateListDependency(bt5_id_list,
False)
self.assertEquals([(repository, 'erp5_core_proxy_field_legacy.bt5'),
(repository, 'erp5_full_text_myisam_catalog.bt5'),
(repository, 'erp5_ingestion_mysql_innodb_catalog.bt5'),
(repository, 'erp5_base.bt5'),
(repository, 'erp5_jquery.bt5'),
(repository, 'erp5_ingestion.bt5'),
(repository, 'erp5_web.bt5'),
(repository, 'erp5_dms.bt5')], bt5_list)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestTemplateTool))
......
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