Commit 0deb7d45 authored by Ayush Tiwari's avatar Ayush Tiwari

bt5_config: Update tests with different use cases

parent 0577e30b
...@@ -82,56 +82,9 @@ class TestBusinessPackage(ERP5TypeTestCase): ...@@ -82,56 +82,9 @@ class TestBusinessPackage(ERP5TypeTestCase):
except AttributeError: except AttributeError:
pass pass
def _createBusinessPackage(self, bp_id=None, title=None): def _createBusinessManager(self, sequence=None, bm_id=None, title=None):
if not bp_id:
bp_id = 'package_%s'%str(time.time())
if not title:
title = bp_id
package = self.portal.portal_templates.newContent(id=bp_id, portal_type='Business Package')
package.edit(title = bp_id,
version='1.0',
description='package for live test')
return package
def _buildAndExportBusinessPackage(self, package):
"""
Builds and exports Business Package to a given export directory
Returns the path of export
"""
package.build()
cfg = getConfiguration()
bp_title = pathname2url(package.getTitle())
package_path = os.path.join(cfg.instancehome, 'tests', '%s' % (bp_title,))
# Export package at the package_path
package.export(path=package_path, local=True)
return package_path
def _importBusinessPackage(self, package, package_path):
"""
Imports the package from the path where it had been exported.
"""
self.portal.portal_templates.manage_delObjects(package.getId())
import_package = self.portal.portal_templates.download(
url='file:'+package_path,
id=package.id+'1',
)
return import_package
def _installBusinessPackage(self, package):
"""
Install the package from its built version.
Expected to install the PathTemplateObject items
"""
package.install()
def _createBusinessManager(self, bm_id=None, title=None):
if not bm_id: if not bm_id:
bm_id = 'manager_%s'%str(time.time()) bm_id = 'manager_%s' % str(time.time())
if not title: if not title:
title = bm_id title = bm_id
manager = self.portal.portal_templates.newContent( manager = self.portal.portal_templates.newContent(
...@@ -169,94 +122,165 @@ class TestBusinessPackage(ERP5TypeTestCase): ...@@ -169,94 +122,165 @@ class TestBusinessPackage(ERP5TypeTestCase):
return import_manager return import_manager
def _installationOfBusinessManagerViaTemplateTool(self): def _copyBusinessManager(self, manager_id_list):
""" """
We try installing one or multiple Business Manager all via portal_templates, Copy the manger objects and returns the newly copied manager objects
keeping in mind that any operation done on BM should result in a BM which
can be easlily mapped with OFS.
""" """
manager = self._createBusinessManager()
portal_templates = self.portal.portal_templates portal_templates = self.portal.portal_templates
test_catalog_1 = self.portal.portal_catalog.newContent( copy_data = portal_templates.manage_copyObjects(ids=manager_id_list)
portal_type = 'Catalog', result_list = portal_templates.manage_pasteObjects(copy_data)
title = 'Test Catalog 1 for Multiple BP5 Installation',
)
path_catalog_1 = test_catalog_1.getRelativeUrl() new_id_list = []
path_item_catalog_1 = '%s | %s | %s'%(path_catalog_1, 1, 1) for res in result_list:
path_item_list = [path_item_catalog_1] new_id_list.append(res['new_id'])
manager._setTemplatePathList(path_item_list) manager_list = []
built_manager = manager.build() for new_id in new_id_list:
manager_list.append(portal_templates._getOb(new_id))
bm_list = [] return tuple(manager_list)
bm_list.append(built_manager)
self.portal.portal_catalog.manage_delObjects( \ def _addFolderInERP5(self):
[test_catalog_1.getId(),]) """
"""
test_folder = self.portal.newContent(id='test_folder',
portal_type='Folder',
title='couscous',
)
return test_folder
# Test that the catalogs don't exist on site anymore def test_useCase_IX(self):
self.assertRaises(KeyError, lambda: self.portal.restrictedTraverse(path_catalog_1)) """
Case IX:
"""
portal_templates = self.portal.portal_templates
managerA = self._createBusinessManager()
test_folder = self._addFolderInERP5()
portal_templates.installMultipleBusinessManager(bm_list) # Add catalog to the path list for Business Manager and build the object
folder_path = test_folder.getRelativeUrl()
# Add title as the property we want to use in path_item
path_item_folder = '%s | %s | %s' % (folder_path, 1, 1)
path_item_list = [path_item_folder]
catalog_1 = self.portal.restrictedTraverse(path_catalog_1) # Set catalog path item as path_item in managerA
self.assertEquals(catalog_1.getTitle(), \ managerA._setTemplatePathList(path_item_list)
'Test Catalog 1 for Multiple BP5 Installation')
def reduceBusinessManagerWithTwoConflictingPath(self): # Copy the Business Manager object
managerA_new, = self._copyBusinessManager([managerA.id,])
managerA_new.build()
managerA_new.setStatus('uninstalled')
# Delete the object from ZODB so as we can install the object there
self.portal.manage_delObjects([test_folder.getId(),])
# Install the Business Manager
portal_templates.installMultipleBusinessManager([managerA_new,])
installed_test_folder = self.portal.restrictedTraverse(folder_path)
self.assertEquals(installed_test_folder.getTitle(),
'couscous')
# Delete the object again from ZODB
self.portal.manage_delObjects([test_folder.getId(),])
# Set empty path item as path_item in managerA
managerA._setTemplatePathList([])
# Copy the Business Manager object
managerA_new, = self._copyBusinessManager([managerA.id,])
managerA_new.build()
managerA_new.setStatus('uninstalled')
portal_templates.installMultipleBusinessManager([managerA_new,])
# Test that the catalogs don't exist on site anymore
self.assertRaises(KeyError, lambda: self.portal.restrictedTraverse(folder_path))
def test_useCase_X(self):
""" """
Test the final Business Manager for Business Manager which have same path A A A : A
at different layer
""" """
portal_templates = self.portal.portal_templates portal_templates = self.portal.portal_templates
manager_1 = self._createBusinessManager() managerA = self._createBusinessManager()
manager_2 = self._createBusinessManager() test_folder = self._addFolderInERP5()
test_catalog_1 = self.portal.portal_catalog.newContent( # Add catalog to the path list for Business Manager and build the object
portal_type = 'Catalog', folder_path = test_folder.getRelativeUrl()
title = 'Test Catalog 1 for Multiple BP5 Installation', # Add title as the property we want to use in path_item
) path_item_folder = '%s | %s | %s' % (folder_path, 1, 1)
path_item_list = [path_item_folder]
path_catalog_1 = test_catalog_1.getRelativeUrl() # Set catalog path item as path_item in managerA
path_item_catalog_1 = '%s | %s | %s'%(path_catalog_1, 1, 1) managerA._setTemplatePathList(path_item_list)
path_item_list_1 = [path_item_catalog_1]
manager_1._setTemplatePathList(path_item_list_1) # Copy the Business Manager object
built_manager_1 = manager_1.build() managerA_new, = self._copyBusinessManager([managerA.id,])
managerA_new.build()
managerA_new.setStatus('uninstalled')
test_catalog_1.edit( # Delete the object from ZODB so as we can install the object there
title = 'Test Catalog 2 for Multiple BP5 Installation', self.portal.manage_delObjects([test_folder.getId(),])
) # Install the Business Manager
portal_templates.installMultipleBusinessManager([managerA_new,])
path_item_catalog_2 = '%s | %s | %s'%(path_catalog_1, 1, 2) installed_test_folder = self.portal.restrictedTraverse(folder_path)
path_item_list_2 = [path_item_catalog_2] self.assertEquals(installed_test_folder.getTitle(),
'couscous')
manager_2._setTemplatePathList(path_item_list_2) # Copy the Business Manager object, updated version of managerA
built_manager_2 = manager_2.build() managerA_new, = self._copyBusinessManager([managerA.id,])
managerA_new.build()
managerA_new.setStatus('uninstalled')
self.portal.portal_catalog.manage_delObjects( \ # Install the updated Business Manager
[test_catalog_1.getId(),]) portal_templates.installMultipleBusinessManager([managerA_new,])
# Test that the catalogs don't exist on site anymore # Expect the Business Manager to be there
self.assertRaises(KeyError, lambda: self.portal.restrictedTraverse(path_catalog_1)) installed_test_folder = self.portal.restrictedTraverse(folder_path)
self.assertEquals(installed_test_folder.getTitle(),
'couscous')
bm_list = [] def test_useCase_XIII(self):
bm_list.append(built_manager_1) """
bm_list.append(built_manager_2) A C A : C
"""
portal_templates = self.portal.portal_templates
managerA = self._createBusinessManager()
test_folder = self._addFolderInERP5()
portal_templates.installMultipleBusinessManager(bm_list) # Add catalog to the path list for Business Manager and build the object
folder_path = test_folder.getRelativeUrl()
# Add title as the property we want to use in path_item
path_item_folder = '%s | %s | %s' % (folder_path, 1, 1)
path_item_list = [path_item_folder]
catalog_1 = self.portal.restrictedTraverse(path_catalog_1) # Set catalog path item as path_item in managerA
self.assertEquals(catalog_1.getTitle(), \ managerA._setTemplatePathList(path_item_list)
'Test Catalog 2 for Multiple BP5 Installation')
# Copy the Business Manager object
managerA_new, = self._copyBusinessManager([managerA.id,])
managerA_new.build()
managerA_new.setStatus('uninstalled')
# Delete the object from ZODB so as we can install the object there
self.portal.manage_delObjects([test_folder.getId(),])
# Install the Business Manager
portal_templates.installMultipleBusinessManager([managerA_new,])
installed_test_folder = self.portal.restrictedTraverse(folder_path)
self.assertEquals(installed_test_folder.getTitle(),
'couscous')
# Copy the Business Manager object, updated version of managerA
managerA_new, = self._copyBusinessManager([managerA.id,])
managerA_new.build()
managerA_new.setStatus('uninstalled')
def test_globalInstallationOfBusinessTemplate(self): def test_globalInstallationOfBusinessTemplate(self):
""" """
NOTE: NOTE:
Keep in mind that the installation is done on build Business Manager Keep in mind that the installation is done on copy of built Business Manager
objects only, we are not yet exporting a Business Manager object objects only, we are not yet exporting a Business Manager object
USE CASE: USE CASE:
...@@ -272,17 +296,11 @@ class TestBusinessPackage(ERP5TypeTestCase): ...@@ -272,17 +296,11 @@ class TestBusinessPackage(ERP5TypeTestCase):
EXPECTED RESULT: EXPECTED RESULT:
Content of C': Something different than C, to be able to check Content of C': Something different than C, to be able to check
where C' is path C provided by A where C' is path C provided by A
""" """
portal_templates = self.portal.portal_templates portal_templates = self.portal.portal_templates
managerA = self._createBusinessManager() managerA = self._createBusinessManager()
managerB = self._createBusinessManager() managerB = self._createBusinessManager()
test_folder = self._addFolderInERP5()
test_folder = self.portal.newContent(
id='test_folder',
portal_type='Folder',
title='couscous',
)
# Add catalog to the path list for Business Manager and build the object # Add catalog to the path list for Business Manager and build the object
folder_path = test_folder.getRelativeUrl() folder_path = test_folder.getRelativeUrl()
...@@ -292,16 +310,10 @@ class TestBusinessPackage(ERP5TypeTestCase): ...@@ -292,16 +310,10 @@ class TestBusinessPackage(ERP5TypeTestCase):
# Set catalog path item as path_item in managerB # Set catalog path item as path_item in managerB
managerB._setTemplatePathList(path_item_list) managerB._setTemplatePathList(path_item_list)
copy_data = portal_templates.manage_copyObjects(ids=[ managerA_new, managerB_new = self._copyBusinessManager([
managerA.id, managerA.id,
managerB.id, managerB.id,
]) ])
result = portal_templates.manage_pasteObjects(copy_data)
managerA_new_id = result[0]['new_id']
managerB_new_id = result[1]['new_id']
managerA_new = portal_templates._getOb(managerA_new_id)
managerB_new = portal_templates._getOb(managerB_new_id)
managerA_new.build() managerA_new.build()
managerB_new.build() managerB_new.build()
...@@ -337,16 +349,10 @@ class TestBusinessPackage(ERP5TypeTestCase): ...@@ -337,16 +349,10 @@ class TestBusinessPackage(ERP5TypeTestCase):
managerA._setTemplatePathList(path_item_list) managerA._setTemplatePathList(path_item_list)
managerB._setTemplatePathList([]) managerB._setTemplatePathList([])
copy_data = portal_templates.manage_copyObjects(ids=[ managerA_new, managerB_new = self._copyBusinessManager([
managerA.id, managerA.id,
managerB.id, managerB.id,
]) ])
result = portal_templates.manage_pasteObjects(copy_data)
managerA_new_id = result[0]['new_id']
managerB_new_id = result[1]['new_id']
managerA_new = portal_templates._getOb(managerA_new_id)
managerB_new = portal_templates._getOb(managerB_new_id)
installed_test_folder.edit(title='new_couscous') installed_test_folder.edit(title='new_couscous')
...@@ -363,7 +369,7 @@ class TestBusinessPackage(ERP5TypeTestCase): ...@@ -363,7 +369,7 @@ class TestBusinessPackage(ERP5TypeTestCase):
# Then we change the title of test catalog again # Then we change the title of test catalog again
installed_test_folder.edit(title='new_couscous_change_again') installed_test_folder.edit(title='new_couscous_change_again')
# Match the overall state, # Match the overall state,
# Install both the Business Manager(s) # Install both the Business Manager(s)
portal_templates.installMultipleBusinessManager([ portal_templates.installMultipleBusinessManager([
managerA_new, managerA_new,
...@@ -381,6 +387,89 @@ class TestBusinessPackage(ERP5TypeTestCase): ...@@ -381,6 +387,89 @@ class TestBusinessPackage(ERP5TypeTestCase):
except Exception: except Exception:
pass pass
def _installationOfBusinessManagerViaTemplateTool(self):
"""
We try installing one or multiple Business Manager all via portal_templates,
keeping in mind that any operation done on BM should result in a BM which
can be easlily mapped with OFS.
"""
manager = self._createBusinessManager()
portal_templates = self.portal.portal_templates
test_catalog_1 = self.portal.portal_catalog.newContent(
portal_type = 'Catalog',
title = 'Test Catalog 1 for Multiple BP5 Installation',
)
path_catalog_1 = test_catalog_1.getRelativeUrl()
path_item_catalog_1 = '%s | %s | %s'%(path_catalog_1, 1, 1)
path_item_list = [path_item_catalog_1]
manager._setTemplatePathList(path_item_list)
built_manager = manager.build()
bm_list = []
bm_list.append(built_manager)
self.portal.portal_catalog.manage_delObjects( \
[test_catalog_1.getId(),])
# Test that the catalogs don't exist on site anymore
self.assertRaises(KeyError, lambda: self.portal.restrictedTraverse(path_catalog_1))
portal_templates.installMultipleBusinessManager(bm_list)
catalog_1 = self.portal.restrictedTraverse(path_catalog_1)
self.assertEquals(catalog_1.getTitle(), \
'Test Catalog 1 for Multiple BP5 Installation')
def reduceBusinessManagerWithTwoConflictingPath(self):
"""
Test the final Business Manager for Business Manager which have same path
at different layer
"""
portal_templates = self.portal.portal_templates
manager_1 = self._createBusinessManager()
manager_2 = self._createBusinessManager()
test_catalog_1 = self.portal.portal_catalog.newContent(
portal_type = 'Catalog',
title = 'Test Catalog 1 for Multiple BP5 Installation',
)
path_catalog_1 = test_catalog_1.getRelativeUrl()
path_item_catalog_1 = '%s | %s | %s'%(path_catalog_1, 1, 1)
path_item_list_1 = [path_item_catalog_1]
manager_1._setTemplatePathList(path_item_list_1)
built_manager_1 = manager_1.build()
test_catalog_1.edit(
title = 'Test Catalog 2 for Multiple BP5 Installation',
)
path_item_catalog_2 = '%s | %s | %s'%(path_catalog_1, 1, 2)
path_item_list_2 = [path_item_catalog_2]
manager_2._setTemplatePathList(path_item_list_2)
built_manager_2 = manager_2.build()
self.portal.portal_catalog.manage_delObjects( \
[test_catalog_1.getId(),])
# Test that the catalogs don't exist on site anymore
self.assertRaises(KeyError, lambda: self.portal.restrictedTraverse(path_catalog_1))
bm_list = []
bm_list.append(built_manager_1)
bm_list.append(built_manager_2)
portal_templates.installMultipleBusinessManager(bm_list)
catalog_1 = self.portal.restrictedTraverse(path_catalog_1)
self.assertEquals(catalog_1.getTitle(), \
'Test Catalog 2 for Multiple BP5 Installation')
def _UpdateVersionOfBusinessManager(self): def _UpdateVersionOfBusinessManager(self):
""" """
* install bm A which add one workflow W1 * install bm A which add one workflow W1
......
...@@ -45,7 +45,16 @@ ...@@ -45,7 +45,16 @@
<item> <item>
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple/> <tuple>
<string>W:171, 4: Possible unbalanced tuple unpacking with sequence defined at line 142: left side has 1 label(s), right side has 0 value(s) (unbalanced-tuple-unpacking)</string>
<string>W:191, 4: Possible unbalanced tuple unpacking with sequence defined at line 142: left side has 1 label(s), right side has 0 value(s) (unbalanced-tuple-unpacking)</string>
<string>W:218, 4: Possible unbalanced tuple unpacking with sequence defined at line 142: left side has 1 label(s), right side has 0 value(s) (unbalanced-tuple-unpacking)</string>
<string>W:232, 4: Possible unbalanced tuple unpacking with sequence defined at line 142: left side has 1 label(s), right side has 0 value(s) (unbalanced-tuple-unpacking)</string>
<string>W:262, 4: Possible unbalanced tuple unpacking with sequence defined at line 142: left side has 1 label(s), right side has 0 value(s) (unbalanced-tuple-unpacking)</string>
<string>W:276, 4: Possible unbalanced tuple unpacking with sequence defined at line 142: left side has 1 label(s), right side has 0 value(s) (unbalanced-tuple-unpacking)</string>
<string>W:313, 4: Possible unbalanced tuple unpacking with sequence defined at line 142: left side has 2 label(s), right side has 0 value(s) (unbalanced-tuple-unpacking)</string>
<string>W:352, 4: Possible unbalanced tuple unpacking with sequence defined at line 142: left side has 2 label(s), right side has 0 value(s) (unbalanced-tuple-unpacking)</string>
</tuple>
</value> </value>
</item> </item>
<item> <item>
......
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