Commit 6c34465a authored by Ayush Tiwari's avatar Ayush Tiwari

erp5_catalog: Update testBusinessTemplate according to changes in portal_catalog

Also, migrate the catalog before running tests
parent 5ce72b86
......@@ -100,8 +100,8 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor):
###
def afterSetUp(self):
portal = self.getPortalObject()
self.login()
portal = self.getPortal()
# create the fake catalog table
sql_connection = self.getSQLConnection()
sql = 'create table if not exists `fake_catalog` (`toto` BIGINT)'
......@@ -1580,13 +1580,16 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor):
"""
Create ZSQL Method into catalog
"""
self.tic()
portal = self.getPortalObject()
portal.migrateSQLCatalogToERP5Catalog()
pc = self.getCatalogTool()
catalog = pc.getSQLCatalog()
self.assertTrue(catalog is not None)
method_id = "z_fake_method"
addSQLMethod = catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod
addSQLMethod(id=method_id, title='', connection_id='erp5_sql_connection',
arguments='', template='')
addSQLMethod = catalog.newContent
addSQLMethod(portal_type='SQL Method', id=method_id, title='',
connection_id='erp5_sql_connection', arguments_src='', src='')
zsql_method = catalog._getOb(method_id, None)
self.assertTrue(zsql_method is not None)
sequence.edit(zsql_method_id = method_id)
......@@ -1598,21 +1601,20 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor):
# set filter for this method
expression = 'python: context.isPredicate()'
expr_instance = Expression(expression)
catalog.filter_dict[method_id] = PersistentMapping()
catalog.filter_dict[method_id]['filtered'] = 1
catalog.filter_dict[method_id]['expression'] = expression
catalog.filter_dict[method_id]['expression_instance'] = expr_instance
catalog.filter_dict[method_id]['expression_cache_key'] = 'portal_type',
catalog.filter_dict[method_id]['type'] = []
zsql_method.setFiltered(1)
zsql_method.setExpression(expression)
zsql_method.setExpressionInstance(expr_instance)
zsql_method.setExpressionCacheKey('portal_type')
zsql_method.setTypeList([])
def stepCreateUpdateCatalogMethod(self, sequence=None, **kw):
pc = self.getCatalogTool()
catalog = pc.getSQLCatalog()
self.assertTrue(catalog is not None)
method_id = "z_fake_method"
addSQLMethod = catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod
addSQLMethod(id=method_id, title='', connection_id='erp5_sql_connection',
arguments='', template='')
addSQLMethod = catalog.newContent
addSQLMethod(portal_type='SQL Method', id=method_id, title='',
connection_id='erp5_sql_connection', arguments_src='', src='')
zsql_method = catalog._getOb(method_id, None)
self.assertTrue(zsql_method is not None)
sequence.edit(zsql_method_id = method_id)
......@@ -1624,20 +1626,19 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor):
# set filter for this method
expression = 'python: context.isDelivery()'
expr_instance = Expression(expression)
catalog.filter_dict[method_id] = PersistentMapping()
catalog.filter_dict[method_id]['filtered'] = 1
catalog.filter_dict[method_id]['expression'] = expression
catalog.filter_dict[method_id]['expression_instance'] = expr_instance
catalog.filter_dict[method_id]['expression_cache_key'] = 'portal_type',
catalog.filter_dict[method_id]['type'] = []
zsql_method.setFiltered(1)
zsql_method.setExpression(expression)
zsql_method.setExpressionInstance(expr_instance)
zsql_method.setExpressionCacheKey('portal_type')
zsql_method.setTypeList([])
def stepCreateNewCatalogMethod(self, sequence=None, **kw):
pc = self.getCatalogTool()
catalog = pc.getSQLCatalog()
method_id = "z_another_fake_method"
addSQLMethod =catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod
addSQLMethod(id=method_id, title='', connection_id='erp5_sql_connection',
arguments='', template='')
addSQLMethod =catalog.newContent
addSQLMethod(portal_type='SQL Method', id=method_id, title='',
connection_id='erp5_sql_connection', arguments_src='', src='')
zsql_method = catalog._getOb(method_id, None)
self.assertTrue(zsql_method is not None)
sequence.edit(another_zsql_method_id = method_id)
......@@ -1716,11 +1717,17 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor):
# check catalog properties
self.assertIn(method_id, catalog.sql_uncatalog_object)
# check filter
filter_dict = catalog.filter_dict[method_id]
if catalog.meta_type == 'ERP5 Catalog':
filter_dict = catalog.getFilterDict()
filter_dict = filter_dict[method_id]
self.assertEqual(filter_dict['expression_cache_key'], ['portal_type'])
self.assertEqual(filter_dict['type'], [])
elif catalog.meta_type == 'SQLCatalog':
filter_dict = catalog.filter_dict[method_id]
self.assertEqual(filter_dict['expression_cache_key'], ('portal_type',))
self.assertEqual(filter_dict['type'], ())
self.assertEqual(filter_dict['filtered'], 1)
self.assertEqual(filter_dict['expression'], 'python: context.isPredicate()')
self.assertEqual(filter_dict['expression_cache_key'], ('portal_type',))
self.assertEqual(filter_dict['type'], ())
def stepCheckUpdatedCatalogMethodExists(self, sequence=None, **kw):
pc = self.getCatalogTool()
......@@ -1732,11 +1739,17 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor):
# check catalog properties
self.assertIn(method_id, catalog.sql_uncatalog_object)
# check filter
filter_dict = catalog.filter_dict[method_id]
if catalog.meta_type == 'ERP5 Catalog':
filter_dict = catalog.getFilterDict()
filter_dict = filter_dict[method_id]
self.assertEqual(filter_dict['expression_cache_key'], ['portal_type'])
self.assertEqual(filter_dict['type'], [])
elif catalog.meta_type == 'SQLCatalog':
filter_dict = catalog.filter_dict[method_id]
self.assertEqual(filter_dict['expression_cache_key'], ('portal_type',))
self.assertEqual(filter_dict['type'], ())
self.assertEqual(filter_dict['filtered'], 1)
self.assertEqual(filter_dict['expression'], 'python: context.isDelivery()')
self.assertEqual(filter_dict['expression_cache_key'], ('portal_type',))
self.assertEqual(filter_dict['type'], ())
def stepCheckCatalogMethodRemoved(self, sequence=None, **kw):
"""
......@@ -1771,8 +1784,7 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor):
catalog.sql_uncatalog_object = tuple(sql_uncatalog_object)
self.assertNotIn(method_id, catalog.sql_uncatalog_object)
# remove filter
del catalog.filter_dict[method_id]
self.assertNotIn(method_id, catalog.filter_dict.keys())
self.assertNotIn(method_id, catalog.getFilterDict().keys())
# Related key, Result key and table, and others
def stepCreateKeysAndTable(self, sequence=list, **kw):
......
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