Commit 4b44364c authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

* support --save and --load option.

* in --save mode, all test_* methods are skipped.
* in --load mode, use a DemoStorage based on a Data.fs made by --save mode.
* install bin/zopectl, bin/runzope and etc/zope.conf to the unit_test
  directory to make possible to run real zope server on it.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12589 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4f02a0a6
...@@ -26,9 +26,15 @@ Globals.get_request = get_request ...@@ -26,9 +26,15 @@ Globals.get_request = get_request
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Testing.ZopeTestCase.PortalTestCase import PortalTestCase, user_name from Testing.ZopeTestCase.PortalTestCase import PortalTestCase, user_name
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.Utils import getLocalPropertySheetList, removeLocalPropertySheet from Products.ERP5Type.Utils import getLocalPropertySheetList, \
from Products.ERP5Type.Utils import getLocalDocumentList, removeLocalDocument removeLocalPropertySheet, \
from Products.ERP5Type.Utils import getLocalConstraintList, removeLocalConstraint importLocalPropertySheet
from Products.ERP5Type.Utils import getLocalDocumentList, \
removeLocalDocument, \
importLocalDocument
from Products.ERP5Type.Utils import getLocalConstraintList, \
removeLocalConstraint, \
importLocalConstraint
from zLOG import LOG, DEBUG from zLOG import LOG, DEBUG
try: try:
...@@ -37,7 +43,7 @@ except ImportError: ...@@ -37,7 +43,7 @@ except ImportError:
pass pass
# Quiet messages when installing products # Quiet messages when installing products
install_product_quiet = 0 install_product_quiet = 1
# Quiet messages when installing business templates # Quiet messages when installing business templates
install_bt5_quiet = 0 install_bt5_quiet = 0
...@@ -142,6 +148,7 @@ import os ...@@ -142,6 +148,7 @@ import os
from cStringIO import StringIO from cStringIO import StringIO
from urllib import urlretrieve from urllib import urlretrieve
from glob import glob from glob import glob
import pysvn
from Products.ERP5.ERP5Site import ERP5Site from Products.ERP5.ERP5Site import ERP5Site
...@@ -176,6 +183,15 @@ def _getConnectionStringDict(): ...@@ -176,6 +183,15 @@ def _getConnectionStringDict():
class ERP5TypeTestCase(PortalTestCase): class ERP5TypeTestCase(PortalTestCase):
def dummy_test(self):
ZopeTestCase._print('All tests are skipped with --save option.')
def getRevision(self):
try:
return pysvn.Client().info('%s/Products/ERP5' % os.environ['INSTANCE_HOME']).revision.number
except:
return None
def getTitle(self): def getTitle(self):
"""Returns the title of the test, for test reports. """Returns the title of the test, for test reports.
""" """
...@@ -515,6 +531,15 @@ def setupERP5Site( business_template_list=(), ...@@ -515,6 +531,15 @@ def setupERP5Site( business_template_list=(),
get_transaction().commit() get_transaction().commit()
portal = app[portal_name] portal = app[portal_name]
if os.environ.get('erp5_load_data_fs'):
# Import local PropertySheets, Documents
for id_ in getLocalPropertySheetList():
importLocalPropertySheet(id_)
for id_ in getLocalDocumentList():
importLocalDocument(id_)
for id_ in getLocalConstraintList():
importLocalConstraint(id_)
else:
# Remove all local PropertySheets, Documents # Remove all local PropertySheets, Documents
for id_ in getLocalPropertySheetList(): for id_ in getLocalPropertySheetList():
removeLocalPropertySheet(id_) removeLocalPropertySheet(id_)
...@@ -527,6 +552,8 @@ def setupERP5Site( business_template_list=(), ...@@ -527,6 +552,8 @@ def setupERP5Site( business_template_list=(),
# VERY IMPORTANT: Add some business templates # VERY IMPORTANT: Add some business templates
for url, id_ in business_template_list: for url, id_ in business_template_list:
start = time.time() start = time.time()
if id_ in portal.portal_templates.objectIds():
continue
if not quiet: if not quiet:
ZopeTestCase._print('Adding %s business template ... ' % id_) ZopeTestCase._print('Adding %s business template ... ' % id_)
portal.portal_templates.download(url, id=id_) portal.portal_templates.download(url, id=id_)
...@@ -562,6 +589,26 @@ def setupERP5Site( business_template_list=(), ...@@ -562,6 +589,26 @@ def setupERP5Site( business_template_list=(),
from Products.ERP5Type.Base import _aq_reset from Products.ERP5Type.Base import _aq_reset
_aq_reset() _aq_reset()
if os.environ.get('erp5_save_data_fs'):
# Quit the test in order to get a clean site
if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time()-_start,))
get_transaction().commit()
ZopeTestCase.close(app)
if not quiet:
ZopeTestCase._print('Data.fs created\n')
get_transaction().commit()
ZopeTestCase.close(app)
if not quiet:
ZopeTestCase._print('Dumping MySQL database ... ')
instance_home = os.environ['INSTANCE_HOME']
os.system('mysqldump -u test test > %s/dump.sql' % instance_home)
if not quiet:
ZopeTestCase._print('Dumping static files ... ')
for dir in ('Constraint', 'Document', 'PropertySheet'):
os.system('rm -rf %s/%s.bak' % (instance_home, dir))
os.system('cp -ar %s/%s %s/%s.bak' % (instance_home, dir, instance_home, dir))
# Log out # Log out
if not quiet: if not quiet:
ZopeTestCase._print('Logout ... \n') ZopeTestCase._print('Logout ... \n')
...@@ -585,6 +632,11 @@ def setupERP5Site( business_template_list=(), ...@@ -585,6 +632,11 @@ def setupERP5Site( business_template_list=(),
% title) # run_unit_test depends on this string. % title) # run_unit_test depends on this string.
raise raise
from unittest import _makeLoader, TestSuite
def dummy_makeSuite(testCaseClass, prefix='dummy_test', sortUsing=cmp, suiteClass=TestSuite):
return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromTestCase(testCaseClass)
def optimize(): def optimize():
'''Significantly reduces portal creation time.''' '''Significantly reduces portal creation time.'''
def __init__(self, text): def __init__(self, text):
......
...@@ -3,9 +3,27 @@ import os ...@@ -3,9 +3,27 @@ import os
from ZODB.DemoStorage import DemoStorage from ZODB.DemoStorage import DemoStorage
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
instance_home = os.environ.get('INSTANCE_HOME')
data_fs_path = os.environ.get('erp5_tests_data_fs_path') data_fs_path = os.environ.get('erp5_tests_data_fs_path')
if data_fs_path: new_data_fs_path = os.path.join(instance_home, 'Data.fs')
if os.environ.get('erp5_save_data_fs'):
if os.path.exists(new_data_fs_path):
os.remove(new_data_fs_path)
Storage = FileStorage(new_data_fs_path)
elif os.environ.get('erp5_load_data_fs'):
if os.environ.get('erp5_force_data_fs'):
Storage = FileStorage(new_data_fs_path)
else:
Storage = DemoStorage(base=FileStorage(new_data_fs_path), quota=(1<<20))
print("Restoring MySQL database ... ")
os.system("mysql -u test test < %s/dump.sql" % instance_home)
print("Restoring static files ... ")
for dir in ('Constraint', 'Document', 'PropertySheet'):
if os.path.exists('%s/%s.bak' % (instance_home, dir)):
os.system('rm -rf %s/%s' % (instance_home, dir))
os.system('cp -ar %s/%s.bak %s/%s' % (instance_home, dir, instance_home, dir))
elif data_fs_path:
Storage = DemoStorage(base=FileStorage(data_fs_path), quota=(1<<20)) Storage = DemoStorage(base=FileStorage(data_fs_path), quota=(1<<20))
else: else:
Storage = DemoStorage(quota=(1<<20)) Storage = DemoStorage(quota=(1<<20))
...@@ -20,6 +20,11 @@ Options: ...@@ -20,6 +20,11 @@ Options:
--recreate_catalog=0 or 1 recreate the content of the sql catalog. Defaults --recreate_catalog=0 or 1 recreate the content of the sql catalog. Defaults
is to recreate, when using an existing Data.fs is to recreate, when using an existing Data.fs
--save add erp5 sites and business templates in Data.fs
and exit without invoking any tests
--load load Data.fs and skip adding erp5 sites and
business templates
--erp5_sql_connection_string=STRING --erp5_sql_connection_string=STRING
ZSQL Connection string for erp5_sql_connection, by ZSQL Connection string for erp5_sql_connection, by
default, it will use "test test" default, it will use "test test"
...@@ -52,11 +57,11 @@ def initializeInstanceHome(tests_framework_home, ...@@ -52,11 +57,11 @@ def initializeInstanceHome(tests_framework_home,
instance_home): instance_home):
if not os.path.exists(instance_home): if not os.path.exists(instance_home):
os.mkdir(instance_home) os.mkdir(instance_home)
for d in ('Constraint', 'Document', 'PropertySheet', 'tests', 'var'): for d in ('Constraint', 'Document', 'PropertySheet', 'bin', 'etc', 'tests', 'var', 'log'):
path = os.path.join(instance_home, d) path = os.path.join(instance_home, d)
if not os.path.exists(path): if not os.path.exists(path):
os.mkdir(path) os.mkdir(path)
for d in ('Extensions', 'Products', 'bt5'): for d in ('Extensions', 'Products', 'bt5', 'svn'):
src = os.path.join(real_instance_home, d) src = os.path.join(real_instance_home, d)
dst = os.path.join(instance_home, d) dst = os.path.join(instance_home, d)
if not os.path.exists(dst): if not os.path.exists(dst):
...@@ -69,13 +74,25 @@ def initializeInstanceHome(tests_framework_home, ...@@ -69,13 +74,25 @@ def initializeInstanceHome(tests_framework_home,
if os.path.lexists(dst): if os.path.lexists(dst):
raise RuntimeError, '%s is a broken symlink' % dst raise RuntimeError, '%s is a broken symlink' % dst
os.symlink(src, dst) os.symlink(src, dst)
sys.path.append(os.path.join(zope_home, "bin"))
import copyzopeskel
kw = {
"PYTHON":sys.executable,
"INSTANCE_HOME": instance_home,
"SOFTWARE_HOME": software_home,
"ZOPE_HOME": zope_home,
}
skelsrc = os.path.abspath(os.path.join(os.path.dirname(__file__), "skel"))
copyzopeskel.copyskel(skelsrc, instance_home, None, None, **kw)
# site specific variables # site specific variables
# handle 64bit architecture # handle 64bit architecture
if os.path.isdir('/usr/lib64/zope/lib/python'): if os.path.isdir('/usr/lib64/zope/lib/python'):
software_home = '/usr/lib64/zope/lib/python' software_home = '/usr/lib64/zope/lib/python'
zope_home = '/usr/lib64/zope'
else: else:
software_home = '/usr/lib/zope/lib/python' software_home = '/usr/lib/zope/lib/python'
zope_home = '/usr/lib/zope'
tests_framework_home = os.path.dirname(os.path.abspath(__file__)) tests_framework_home = os.path.dirname(os.path.abspath(__file__))
# handle 'system global' instance # handle 'system global' instance
...@@ -153,6 +170,11 @@ def runUnitTestList(test_list) : ...@@ -153,6 +170,11 @@ def runUnitTestList(test_list) :
# it is then possible to run the debugger by "import pdb; pdb.set_trace()" # it is then possible to run the debugger by "import pdb; pdb.set_trace()"
sys.path.insert(0, tests_framework_home) sys.path.insert(0, tests_framework_home)
# override unittest.makeSuite to skip all tests in save mode
if os.environ.get('erp5_save_data_fs'):
from Products.ERP5Type.tests.ERP5TypeTestCase import dummy_makeSuite
unittest.makeSuite = dummy_makeSuite
filtered_tests_class_names = 0 filtered_tests_class_names = 0
for test in test_list: for test in test_list:
if ':' in test: if ':' in test:
...@@ -196,6 +218,8 @@ def main(): ...@@ -196,6 +218,8 @@ def main():
"cmf_activity_sql_connection_string=", "cmf_activity_sql_connection_string=",
"erp5_sql_deferred_connection_string=", "erp5_sql_deferred_connection_string=",
"erp5_catalog_storage=", "erp5_catalog_storage=",
"save",
"load",
"email_from_address="] ) "email_from_address="] )
except getopt.GetoptError, msg: except getopt.GetoptError, msg:
usage(sys.stderr, msg) usage(sys.stderr, msg)
...@@ -232,6 +256,10 @@ def main(): ...@@ -232,6 +256,10 @@ def main():
os.environ["erp5_sql_deferred_connection_string"] = arg os.environ["erp5_sql_deferred_connection_string"] = arg
elif opt == "--email_from_address": elif opt == "--email_from_address":
os.environ["email_from_address"] = arg os.environ["email_from_address"] = arg
elif opt == "--save":
os.environ["erp5_save_data_fs"] = "1"
elif opt == "--load":
os.environ["erp5_load_data_fs"] = "1"
elif opt == "--erp5_catalog_storage": elif opt == "--erp5_catalog_storage":
os.environ["erp5_catalog_storage"] = arg os.environ["erp5_catalog_storage"] = arg
......
#! /bin/sh
PYTHON="<<PYTHON>>"
ZOPE_HOME="<<ZOPE_HOME>>"
INSTANCE_HOME="<<INSTANCE_HOME>>"
CONFIG_FILE="<<INSTANCE_HOME>>/etc/zope.conf"
SOFTWARE_HOME="<<SOFTWARE_HOME>>"
PYTHONPATH="$SOFTWARE_HOME"
export PYTHONPATH INSTANCE_HOME SOFTWARE_HOME
export erp5_load_data_fs="1"
ZOPE_RUN="$SOFTWARE_HOME/Zope/Startup/run.py"
exec "$PYTHON" "$ZOPE_RUN" -C "$CONFIG_FILE" "$@"
#! /bin/sh
PYTHON="<<PYTHON>>"
ZOPE_HOME="<<ZOPE_HOME>>"
INSTANCE_HOME="<<INSTANCE_HOME>>"
CONFIG_FILE="<<INSTANCE_HOME>>/etc/zope.conf"
SOFTWARE_HOME="<<SOFTWARE_HOME>>"
PYTHONPATH="$SOFTWARE_HOME"
export PYTHONPATH INSTANCE_HOME SOFTWARE_HOME
export erp5_load_data_fs="1"
ZDCTL="$SOFTWARE_HOME/Zope/Startup/zopectl.py"
exec "$PYTHON" "$ZDCTL" -C "$CONFIG_FILE" "$@"
This diff is collapsed.
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