From a3c40d0b7e717daa9ffe7e1ef7ac97859b2bc32e Mon Sep 17 00:00:00 2001
From: Arnaud Fontaine <arnaud.fontaine@nexedi.com>
Date: Fri, 4 Oct 2019 10:07:06 +0900
Subject: [PATCH] runUnitTest: 6f1c45c6 wrongly assumed that
 '--erp5_sql_connection_string' is always passed.

This is the case with runUnitTest wrapper created by SlapOS but is not actually required
as manage_addERP5Site has 'test test' as default value.

This fixes:
  File "custom_zodb.py", line 70, in <module>
    sql_db = Products.ZMySQLDA.db.DB(os.environ['erp5_sql_connection_string'])
  File "UserDict.py", line 40, in __getitem__
    raise KeyError(key)
KeyError: 'erp5_sql_connection_string'
---
 product/ERP5/ERP5Site.py              | 6 ++++--
 product/ERP5Type/tests/custom_zodb.py | 4 +++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/product/ERP5/ERP5Site.py b/product/ERP5/ERP5Site.py
index 85917edb4a..7be738b764 100644
--- a/product/ERP5/ERP5Site.py
+++ b/product/ERP5/ERP5Site.py
@@ -58,6 +58,8 @@ def manage_addERP5SiteForm(*args, **kw):
   kw['getCatalogStorageList'] = getCatalogStorageList
   return manage_addERP5SiteFormDtml(*args, **kw)
 
+default_sql_connection_string = 'test test'
+
 # ERP5Site Constructor
 def manage_addERP5Site(self,
                        id,
@@ -69,8 +71,8 @@ def manage_addERP5Site(self,
                        email_from_name='Portal Administrator',
                        validate_email=0,
                        erp5_catalog_storage='erp5_mysql_innodb_catalog',
-                       erp5_sql_connection_string='test test',
-                       cmf_activity_sql_connection_string='test test',
+                       erp5_sql_connection_string=default_sql_connection_string,
+                       cmf_activity_sql_connection_string=default_sql_connection_string,
                        bt5_repository_url='',
                        bt5='',
                        id_store_interval='',
diff --git a/product/ERP5Type/tests/custom_zodb.py b/product/ERP5Type/tests/custom_zodb.py
index a738d287ae..a875700f9e 100644
--- a/product/ERP5Type/tests/custom_zodb.py
+++ b/product/ERP5Type/tests/custom_zodb.py
@@ -66,7 +66,9 @@ else:
   # must be cleared of data from previous execution if any
   _print("Catalog will be recreated to clear data (if any) from previous execution")
   import Products.ZMySQLDA.db
-  sql_db = Products.ZMySQLDA.db.DB(os.environ['erp5_sql_connection_string'])
+  from Products.ERP5.ERP5Site import default_sql_connection_string
+  sql_db = Products.ZMySQLDA.db.DB(os.environ.get('erp5_sql_connection_string',
+                                                  default_sql_connection_string))
   table_list = sql_db.tables()
   if table_list:
     sql_db.query('DROP TABLE ' +
-- 
2.30.9