Commit 6c03bc28 authored by Julien Muchembled's avatar Julien Muchembled

Unit test: provide a way to specify extra connection strings

This allows to not hardcode connection strings in testArchive and
testERP5Catalog, which need several databases.

A new environment variable (extra_sql_connection_string_list) is recognized:
it is a colon-separated string of connection strings.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30863 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent eaa1a2a7
...@@ -37,7 +37,8 @@ from zLOG import LOG ...@@ -37,7 +37,8 @@ from zLOG import LOG
from DateTime import DateTime from DateTime import DateTime
from Products.CMFCore.tests.base.testcase import LogInterceptor from Products.CMFCore.tests.base.testcase import LogInterceptor
from Testing.ZopeTestCase.PortalTestCase import PortalTestCase from Testing.ZopeTestCase.PortalTestCase import PortalTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript, \
getExtraSqlConnectionStringList
from Products.ZSQLCatalog.ZSQLCatalog import HOT_REINDEXING_FINISHED_STATE,\ from Products.ZSQLCatalog.ZSQLCatalog import HOT_REINDEXING_FINISHED_STATE,\
HOT_REINDEXING_RECORDING_STATE, HOT_REINDEXING_DOUBLE_INDEXING_STATE HOT_REINDEXING_RECORDING_STATE, HOT_REINDEXING_DOUBLE_INDEXING_STATE
from Products.CMFActivity.Errors import ActivityFlushError from Products.CMFActivity.Errors import ActivityFlushError
...@@ -168,27 +169,28 @@ class TestArchive(InventoryAPITestCase): ...@@ -168,27 +169,28 @@ class TestArchive(InventoryAPITestCase):
# Create new connectors for destination # Create new connectors for destination
self.new_connection_id = 'erp5_sql_connection1' self.new_connection_id = 'erp5_sql_connection1'
db1, db2 = getExtraSqlConnectionStringList()[:2]
portal.manage_addZMySQLConnection(self.new_connection_id,'', portal.manage_addZMySQLConnection(self.new_connection_id,'',
'test2 test2') db1)
new_connection = portal[self.new_connection_id] new_connection = portal[self.new_connection_id]
new_connection.manage_open_connection() new_connection.manage_open_connection()
# the deferred one # the deferred one
self.new_deferred_connection_id = 'erp5_sql_connection2' self.new_deferred_connection_id = 'erp5_sql_connection2'
portal.manage_addZMySQLConnection(self.new_deferred_connection_id,'', portal.manage_addZMySQLConnection(self.new_deferred_connection_id,'',
'test2 test2') db1)
new_deferred_connection = portal[self.new_deferred_connection_id] new_deferred_connection = portal[self.new_deferred_connection_id]
new_deferred_connection.manage_open_connection() new_deferred_connection.manage_open_connection()
# Create new connectors for archive # Create new connectors for archive
self.archive_connection_id = 'erp5_sql_connection3' self.archive_connection_id = 'erp5_sql_connection3'
portal.manage_addZMySQLConnection(self.archive_connection_id,'', portal.manage_addZMySQLConnection(self.archive_connection_id,'',
'test3 test3') db2)
archive_connection = portal[self.archive_connection_id] archive_connection = portal[self.archive_connection_id]
archive_connection.manage_open_connection() archive_connection.manage_open_connection()
# the deferred one # the deferred one
self.archive_deferred_connection_id = 'erp5_sql_connection4' self.archive_deferred_connection_id = 'erp5_sql_connection4'
portal.manage_addZMySQLConnection(self.archive_deferred_connection_id,'', portal.manage_addZMySQLConnection(self.archive_deferred_connection_id,'',
'test3 test3') db2)
archive_deferred_connection = portal[self.archive_deferred_connection_id] archive_deferred_connection = portal[self.archive_deferred_connection_id]
archive_deferred_connection.manage_open_connection() archive_deferred_connection.manage_open_connection()
......
...@@ -36,7 +36,8 @@ from AccessControl.SecurityManagement import newSecurityManager ...@@ -36,7 +36,8 @@ from AccessControl.SecurityManagement import newSecurityManager
from zLOG import LOG from zLOG import LOG
from DateTime import DateTime from DateTime import DateTime
from Products.CMFCore.tests.base.testcase import LogInterceptor from Products.CMFCore.tests.base.testcase import LogInterceptor
from Products.ERP5Type.tests.utils import createZODBPythonScript, todo_erp5 from Products.ERP5Type.tests.utils import createZODBPythonScript, todo_erp5, \
getExtraSqlConnectionStringList
from Products.ZSQLCatalog.ZSQLCatalog import HOT_REINDEXING_FINISHED_STATE,\ from Products.ZSQLCatalog.ZSQLCatalog import HOT_REINDEXING_FINISHED_STATE,\
HOT_REINDEXING_RECORDING_STATE, HOT_REINDEXING_DOUBLE_INDEXING_STATE HOT_REINDEXING_RECORDING_STATE, HOT_REINDEXING_DOUBLE_INDEXING_STATE
from Products.CMFActivity.Errors import ActivityFlushError from Products.CMFActivity.Errors import ActivityFlushError
...@@ -1467,7 +1468,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -1467,7 +1468,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
portal = self.getPortal() portal = self.getPortal()
self.original_connection_id = 'erp5_sql_connection' self.original_connection_id = 'erp5_sql_connection'
self.new_connection_id = 'erp5_sql_connection2' self.new_connection_id = 'erp5_sql_connection2'
new_connection_string = 'test2 test2' new_connection_string = getExtraSqlConnectionStringList()[0]
# Skip this test if default connection string is not "test test". # Skip this test if default connection string is not "test test".
original_connection = getattr(portal, self.original_connection_id) original_connection = getattr(portal, self.original_connection_id)
......
...@@ -237,6 +237,12 @@ def getMySQLArguments(): ...@@ -237,6 +237,12 @@ def getMySQLArguments():
return '-u %s %s %s %s' % (user, password, host, db) return '-u %s %s %s %s' % (user, password, host, db)
def getExtraSqlConnectionStringList():
"""Return list of extra available SQL connection string
"""
return os.environ.get('extra_sql_connection_string_list',
'test2 test2:test3 test3').split(':')
# decorators # decorators
class reindex(object): class reindex(object):
"""Decorator to commit transaction and flush activities after the method is """Decorator to commit transaction and flush activities after the method is
......
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