Commit 57f5a452 authored by Ayush Tiwari's avatar Ayush Tiwari

erp5_catalog: Update tests according to the changes in ERP5Catalog

Also, add test for migration in testERP5Catalog(as the first test to be run)
and migrate Catalog in afterSetup in testERP5CatalogSecurityUidOptimization.
parent 068d4a72
...@@ -170,6 +170,24 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -170,6 +170,24 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
self.assertTrue(path not in path_list) self.assertTrue(path not in path_list)
LOG('checkRelativeUrlInSQLPathList not found path:',0,path) LOG('checkRelativeUrlInSQLPathList not found path:',0,path)
def test_00_MigrateCatalog(self):
portal = self.getPortalObject()
portal_catalog = portal.portal_catalog
# Check if portal_catalog has meta_type of older portal_catalog
# In that case, create new portal_catalog of ERP5 Catalog Tool object
# of portal_type 'Catalog Tool'
self.assertEquals(portal_catalog.meta_type, 'ERP5 Catalog')
# Now, run the migration
portal.migrateSQLCatalogToERP5Catalog()
portal_catalog = portal.portal_catalog
self.assertEquals(portal_catalog.meta_type, 'Catalog Tool')
erp5_catalog = portal_catalog.getERP5Catalog()
self.assertEquals(portal_catalog.getSQLCatalog(), erp5_catalog)
self.assertEquals(erp5_catalog.__class__.__name__, 'Catalog')
def test_01_HasEverything(self): def test_01_HasEverything(self):
self.assertNotEquals(self.getCategoryTool(), None) self.assertNotEquals(self.getCategoryTool(), None)
self.assertNotEquals(self.getSimulationTool(), None) self.assertNotEquals(self.getSimulationTool(), None)
...@@ -582,14 +600,14 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -582,14 +600,14 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
""" % {'query_table' : query_table} """ % {'query_table' : query_table}
portal_skins_custom = portal.portal_skins.custom portal_skins_custom = portal.portal_skins.custom
portal_skins_custom.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( portal_skins_custom.newContent(portal_type='SQL Method',
id = 'testMethod', id = 'testMethod',
title = '', title = '',
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
arguments = "\n".join([ 'from_table_list', arguments_src = "\n".join([ 'from_table_list',
'where_expression', 'where_expression',
'order_by_expression' ]), 'order_by_expression' ]),
template = sql_squeleton) src = sql_squeleton)
testMethod = portal_skins_custom['testMethod'] testMethod = portal_skins_custom['testMethod']
default_parametrs = {} default_parametrs = {}
...@@ -1476,14 +1494,14 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -1476,14 +1494,14 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
""" """
for catalog, connection_id in ((original_catalog, original_connection_id), for catalog, connection_id in ((original_catalog, original_connection_id),
(new_catalog, self.new_erp5_sql_connection)): (new_catalog, self.new_erp5_sql_connection)):
catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( catalog.newContent(portal_type='SQL Method',
id='z_create_dummy_table', title='', arguments="", id='z_create_dummy_table', title='', arguments_src="",
connection_id=connection_id, connection_id=connection_id,
template=create_dummy_table_sql) src=create_dummy_table_sql)
catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( catalog.newContent(portal_type='SQL Method',
id='z0_drop_dummy_table', title='', arguments="", id='z0_drop_dummy_table', title='', arguments_src="",
connection_id=connection_id, connection_id=connection_id,
template=drop_summy_table_sql) src=drop_summy_table_sql)
# update catalog configuration and declare new ZSQLMethods # update catalog configuration and declare new ZSQLMethods
sql_clear_catalog_list = list(original_catalog.sql_clear_catalog) sql_clear_catalog_list = list(original_catalog.sql_clear_catalog)
...@@ -2389,6 +2407,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -2389,6 +2407,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
# Add a new table to the catalog # Add a new table to the catalog
sql_catalog = self.portal.portal_catalog.getSQLCatalog() sql_catalog = self.portal.portal_catalog.getSQLCatalog()
sql_catalog.manage_setLocalRoles(user1, ['Author', 'Auditor', 'Manager'])
local_roles_table = "test_local_roles" local_roles_table = "test_local_roles"
...@@ -2400,22 +2419,22 @@ CREATE TABLE `%s` ( ...@@ -2400,22 +2419,22 @@ CREATE TABLE `%s` (
KEY `version` (`owner_reference`) KEY `version` (`owner_reference`)
) ENGINE=InnoDB; ) ENGINE=InnoDB;
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z_create_%s' % local_roles_table, id = 'z_create_%s' % local_roles_table,
title = '', title = '',
arguments = "", arguments_src = "",
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
template = create_local_role_table_sql) src = create_local_role_table_sql)
drop_local_role_table_sql = """ drop_local_role_table_sql = """
DROP TABLE IF EXISTS %s DROP TABLE IF EXISTS %s
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z0_drop_%s' % local_roles_table, id = 'z0_drop_%s' % local_roles_table,
title = '', title = '',
arguments = "", arguments_src = "",
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
template = drop_local_role_table_sql) src = drop_local_role_table_sql)
catalog_local_role_sql = """ catalog_local_role_sql = """
REPLACE INTO REPLACE INTO
...@@ -2432,13 +2451,13 @@ VALUES ...@@ -2432,13 +2451,13 @@ VALUES
</dtml-if> </dtml-if>
</dtml-in> </dtml-in>
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z_catalog_%s_list' % local_roles_table, id = 'z_catalog_%s_list' % local_roles_table,
title = '', title = '',
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
arguments = "\n".join(['uid', arguments_src = "\n".join(['uid',
'Base_getOwnerId']), 'Base_getOwnerId']),
template = catalog_local_role_sql) src = catalog_local_role_sql)
self.commit() self.commit()
current_sql_catalog_object_list = sql_catalog.sql_catalog_object_list current_sql_catalog_object_list = sql_catalog.sql_catalog_object_list
...@@ -2571,6 +2590,7 @@ VALUES ...@@ -2571,6 +2590,7 @@ VALUES
# Add a new table to the catalog # Add a new table to the catalog
sql_catalog = self.portal.portal_catalog.getSQLCatalog() sql_catalog = self.portal.portal_catalog.getSQLCatalog()
sql_catalog.manage_setLocalRoles(user1, ['Author', 'Auditor', 'Manager'])
local_roles_table = "test_assignee_local_roles" local_roles_table = "test_assignee_local_roles"
...@@ -2584,22 +2604,22 @@ CREATE TABLE `%s` ( ...@@ -2584,22 +2604,22 @@ CREATE TABLE `%s` (
KEY `viewable_assignee_reference` (`viewable_assignee_reference`) KEY `viewable_assignee_reference` (`viewable_assignee_reference`)
) ENGINE=InnoDB; ) ENGINE=InnoDB;
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z_create_%s' % local_roles_table, id = 'z_create_%s' % local_roles_table,
title = '', title = '',
arguments = "", arguments_src = "",
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
template = create_local_role_table_sql) src = create_local_role_table_sql)
drop_local_role_table_sql = """ drop_local_role_table_sql = """
DROP TABLE IF EXISTS %s DROP TABLE IF EXISTS %s
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z0_drop_%s' % local_roles_table, id = 'z0_drop_%s' % local_roles_table,
title = '', title = '',
arguments = "", arguments_src = "",
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
template = drop_local_role_table_sql) src = drop_local_role_table_sql)
catalog_local_role_sql = """ catalog_local_role_sql = """
REPLACE INTO REPLACE INTO
...@@ -2617,14 +2637,14 @@ VALUES ...@@ -2617,14 +2637,14 @@ VALUES
</dtml-if> </dtml-if>
</dtml-in> </dtml-in>
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z_catalog_%s_list' % local_roles_table, id = 'z_catalog_%s_list' % local_roles_table,
title = '', title = '',
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
arguments = "\n".join(['uid', arguments_src = "\n".join(['uid',
'getAssignee', 'getAssignee',
'getViewPermissionAssignee']), 'getViewPermissionAssignee']),
template = catalog_local_role_sql) src = catalog_local_role_sql)
self.commit() self.commit()
current_sql_catalog_object_list = sql_catalog.sql_catalog_object_list current_sql_catalog_object_list = sql_catalog.sql_catalog_object_list
...@@ -2729,6 +2749,7 @@ VALUES ...@@ -2729,6 +2749,7 @@ VALUES
# Add a new table to the catalog # Add a new table to the catalog
sql_catalog = self.portal.portal_catalog.getSQLCatalog() sql_catalog = self.portal.portal_catalog.getSQLCatalog()
sql_catalog.manage_setLocalRoles(user1, ['Author', 'Auditor', 'Manager'])
local_roles_table = "test_user_or_group_local_roles" local_roles_table = "test_user_or_group_local_roles"
...@@ -2742,22 +2763,22 @@ CREATE TABLE `%s` ( ...@@ -2742,22 +2763,22 @@ CREATE TABLE `%s` (
KEY `viewable_assignee_reference` (`viewable_assignee_reference`) KEY `viewable_assignee_reference` (`viewable_assignee_reference`)
) ENGINE=InnoDB; ) ENGINE=InnoDB;
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z_create_%s' % local_roles_table, id = 'z_create_%s' % local_roles_table,
title = '', title = '',
arguments = "", arguments_src = "",
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
template = create_local_role_table_sql) src = create_local_role_table_sql)
drop_local_role_table_sql = """ drop_local_role_table_sql = """
DROP TABLE IF EXISTS %s DROP TABLE IF EXISTS %s
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z0_drop_%s' % local_roles_table, id = 'z0_drop_%s' % local_roles_table,
title = '', title = '',
arguments = "", arguments_src = "",
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
template = drop_local_role_table_sql) src = drop_local_role_table_sql)
catalog_local_role_sql = """ catalog_local_role_sql = """
REPLACE INTO REPLACE INTO
...@@ -2775,14 +2796,14 @@ VALUES ...@@ -2775,14 +2796,14 @@ VALUES
</dtml-if> </dtml-if>
</dtml-in> </dtml-in>
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z_catalog_%s_list' % local_roles_table, id = 'z_catalog_%s_list' % local_roles_table,
title = '', title = '',
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
arguments = "\n".join(['uid', arguments_src = "\n".join(['uid',
'getAssignee', 'getAssignee',
'getViewPermissionAssignee']), 'getViewPermissionAssignee']),
template = catalog_local_role_sql) src = catalog_local_role_sql)
self.commit() self.commit()
current_sql_catalog_object_list = sql_catalog.sql_catalog_object_list current_sql_catalog_object_list = sql_catalog.sql_catalog_object_list
...@@ -2983,6 +3004,7 @@ VALUES ...@@ -2983,6 +3004,7 @@ VALUES
# Add a new table to the catalog # Add a new table to the catalog
sql_catalog = self.portal.portal_catalog.getSQLCatalog() sql_catalog = self.portal.portal_catalog.getSQLCatalog()
sql_catalog.manage_setLocalRoles(user1, ['Author', 'Auditor', 'Manager'])
local_roles_table = "another_test_user_or_group_local_roles" local_roles_table = "another_test_user_or_group_local_roles"
...@@ -2994,22 +3016,22 @@ CREATE TABLE `%s` ( ...@@ -2994,22 +3016,22 @@ CREATE TABLE `%s` (
KEY `viewable_assignee_reference` (`viewable_assignee_reference`) KEY `viewable_assignee_reference` (`viewable_assignee_reference`)
) ENGINE=InnoDB; ) ENGINE=InnoDB;
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z_create_%s' % local_roles_table, id = 'z_create_%s' % local_roles_table,
title = '', title = '',
arguments = "", arguments_src = "",
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
template = create_local_role_table_sql) src = create_local_role_table_sql)
drop_local_role_table_sql = """ drop_local_role_table_sql = """
DROP TABLE IF EXISTS %s DROP TABLE IF EXISTS %s
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z0_drop_%s' % local_roles_table, id = 'z0_drop_%s' % local_roles_table,
title = '', title = '',
arguments = "", arguments_src = "",
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
template = drop_local_role_table_sql) src = drop_local_role_table_sql)
catalog_local_role_sql = """ catalog_local_role_sql = """
REPLACE INTO REPLACE INTO
...@@ -3026,13 +3048,13 @@ VALUES ...@@ -3026,13 +3048,13 @@ VALUES
</dtml-if> </dtml-if>
</dtml-in> </dtml-in>
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z_catalog_%s_list' % local_roles_table, id = 'z_catalog_%s_list' % local_roles_table,
title = '', title = '',
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
arguments = "\n".join(['uid', arguments_src = "\n".join(['uid',
'getViewPermissionAssignee']), 'getViewPermissionAssignee']),
template = catalog_local_role_sql) src = catalog_local_role_sql)
self.commit() self.commit()
current_sql_catalog_object_list = sql_catalog.sql_catalog_object_list current_sql_catalog_object_list = sql_catalog.sql_catalog_object_list
...@@ -3223,22 +3245,22 @@ CREATE TABLE `%s` ( ...@@ -3223,22 +3245,22 @@ CREATE TABLE `%s` (
KEY `viewable_assignee_reference` (`viewable_assignee_reference`) KEY `viewable_assignee_reference` (`viewable_assignee_reference`)
) ENGINE=InnoDB; ) ENGINE=InnoDB;
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z_create_%s' % local_roles_table, id = 'z_create_%s' % local_roles_table,
title = '', title = '',
arguments = "", arguments_src = "",
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
template = create_local_role_table_sql) src = create_local_role_table_sql)
drop_local_role_table_sql = """ drop_local_role_table_sql = """
DROP TABLE IF EXISTS %s DROP TABLE IF EXISTS %s
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z0_drop_%s' % local_roles_table, id = 'z0_drop_%s' % local_roles_table,
title = '', title = '',
arguments = "", arguments_src = "",
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
template = drop_local_role_table_sql) src = drop_local_role_table_sql)
catalog_local_role_sql = """ catalog_local_role_sql = """
REPLACE INTO REPLACE INTO
...@@ -3255,13 +3277,13 @@ VALUES ...@@ -3255,13 +3277,13 @@ VALUES
</dtml-if> </dtml-if>
</dtml-in> </dtml-in>
""" % local_roles_table """ % local_roles_table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id = 'z_catalog_%s_list' % local_roles_table, id = 'z_catalog_%s_list' % local_roles_table,
title = '', title = '',
connection_id = 'erp5_sql_connection', connection_id = 'erp5_sql_connection',
arguments = "\n".join(['uid', arguments_src = "\n".join(['uid',
'getViewPermissionAssignee']), 'getViewPermissionAssignee']),
template = catalog_local_role_sql) src = catalog_local_role_sql)
self.commit() self.commit()
current_sql_catalog_object_list = sql_catalog.sql_catalog_object_list current_sql_catalog_object_list = sql_catalog.sql_catalog_object_list
......
...@@ -48,6 +48,7 @@ class TestERP5CatalogSecurityUidOptimization(ERP5TypeTestCase): ...@@ -48,6 +48,7 @@ class TestERP5CatalogSecurityUidOptimization(ERP5TypeTestCase):
def afterSetUp(self): def afterSetUp(self):
self.login() self.login()
portal = self.getPortal() portal = self.getPortal()
portal.migrateSQLCatalogToERP5Catalog()
group = portal.portal_categories.group group = portal.portal_categories.group
if 'g1' not in group.objectIds(): if 'g1' not in group.objectIds():
group.newContent(portal_type='Category', id='g1', codification='GROUP1') group.newContent(portal_type='Category', id='g1', codification='GROUP1')
...@@ -73,12 +74,12 @@ CREATE TABLE alternate_roles_and_users ( ...@@ -73,12 +74,12 @@ CREATE TABLE alternate_roles_and_users (
'alternate_roles_and_users'] 'alternate_roles_and_users']
# Configure sql method to insert this table # Configure sql method to insert this table
sql_catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod( sql_catalog.newContent(portal_type='SQL Method',
id='z_catalog_alternate_roles_and_users_list', id='z_catalog_alternate_roles_and_users_list',
title='', title='',
connection_id='erp5_sql_connection', connection_id='erp5_sql_connection',
arguments="\n".join(['uid', 'alternate_security_uid']), arguments_src="\n".join(['uid', 'alternate_security_uid']),
template="""REPLACE INTO alternate_roles_and_users VALUES src="""REPLACE INTO alternate_roles_and_users VALUES
<dtml-in prefix="loop" expr="_.range(_.len(uid))"> <dtml-in prefix="loop" expr="_.range(_.len(uid))">
( <dtml-sqlvar expr="uid[loop_item]" type="int">, ( <dtml-sqlvar expr="uid[loop_item]" type="int">,
<dtml-sqlvar expr="alternate_security_uid[loop_item]" type="int" optional> <dtml-sqlvar expr="alternate_security_uid[loop_item]" type="int" optional>
......
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