From 6c03bc28ec94dafc9674854b739a97773ca2feee Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Wed, 25 Nov 2009 17:07:59 +0000
Subject: [PATCH] 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
---
 product/ERP5Catalog/tests/testArchive.py     | 12 +++++++-----
 product/ERP5Catalog/tests/testERP5Catalog.py |  5 +++--
 product/ERP5Type/tests/utils.py              |  6 ++++++
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/product/ERP5Catalog/tests/testArchive.py b/product/ERP5Catalog/tests/testArchive.py
index 60354bc9f7..45a9cdfd05 100644
--- a/product/ERP5Catalog/tests/testArchive.py
+++ b/product/ERP5Catalog/tests/testArchive.py
@@ -37,7 +37,8 @@ from zLOG import LOG
 from DateTime import DateTime
 from Products.CMFCore.tests.base.testcase import LogInterceptor
 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,\
       HOT_REINDEXING_RECORDING_STATE, HOT_REINDEXING_DOUBLE_INDEXING_STATE
 from Products.CMFActivity.Errors import ActivityFlushError
@@ -168,27 +169,28 @@ class TestArchive(InventoryAPITestCase):
     
     # Create new connectors for destination
     self.new_connection_id = 'erp5_sql_connection1'
+    db1, db2 = getExtraSqlConnectionStringList()[:2]
     portal.manage_addZMySQLConnection(self.new_connection_id,'',
-                                      'test2 test2')
+                                      db1)
     new_connection = portal[self.new_connection_id]
     new_connection.manage_open_connection()
     # the deferred one
     self.new_deferred_connection_id = 'erp5_sql_connection2'
     portal.manage_addZMySQLConnection(self.new_deferred_connection_id,'',
-                                      'test2 test2')
+                                      db1)
     new_deferred_connection = portal[self.new_deferred_connection_id]
     new_deferred_connection.manage_open_connection()
 
     # Create new connectors for archive
     self.archive_connection_id = 'erp5_sql_connection3'
     portal.manage_addZMySQLConnection(self.archive_connection_id,'',
-                                      'test3 test3')
+                                      db2)
     archive_connection = portal[self.archive_connection_id]
     archive_connection.manage_open_connection()
     # the deferred one
     self.archive_deferred_connection_id = 'erp5_sql_connection4'
     portal.manage_addZMySQLConnection(self.archive_deferred_connection_id,'',
-                                      'test3 test3')
+                                      db2)
     archive_deferred_connection = portal[self.archive_deferred_connection_id]
     archive_deferred_connection.manage_open_connection()
 
diff --git a/product/ERP5Catalog/tests/testERP5Catalog.py b/product/ERP5Catalog/tests/testERP5Catalog.py
index 2ab4168597..5d4cc10e07 100644
--- a/product/ERP5Catalog/tests/testERP5Catalog.py
+++ b/product/ERP5Catalog/tests/testERP5Catalog.py
@@ -36,7 +36,8 @@ from AccessControl.SecurityManagement import newSecurityManager
 from zLOG import LOG
 from DateTime import DateTime
 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,\
       HOT_REINDEXING_RECORDING_STATE, HOT_REINDEXING_DOUBLE_INDEXING_STATE
 from Products.CMFActivity.Errors import ActivityFlushError
@@ -1467,7 +1468,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
     portal = self.getPortal()
     self.original_connection_id = 'erp5_sql_connection'
     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".
     original_connection = getattr(portal, self.original_connection_id)
diff --git a/product/ERP5Type/tests/utils.py b/product/ERP5Type/tests/utils.py
index 095d6a6455..121e248e7b 100644
--- a/product/ERP5Type/tests/utils.py
+++ b/product/ERP5Type/tests/utils.py
@@ -237,6 +237,12 @@ def getMySQLArguments():
 
   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
 class reindex(object):
   """Decorator to commit transaction and flush activities after the method is
-- 
2.30.9