Commit b6a363d7 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Add a workaround for the overwriting problem of the instance home in Testing/__init__.py.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@614 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 523df4ca
...@@ -56,6 +56,10 @@ from AccessControl.User import User ...@@ -56,6 +56,10 @@ from AccessControl.User import User
from Acquisition import aq_base from Acquisition import aq_base
import time import time
import md5 import md5
import traceback
import sys
import os
from cStringIO import StringIO
from Products.ERP5.ERP5Site import ERP5Site from Products.ERP5.ERP5Site import ERP5Site
...@@ -85,6 +89,18 @@ class ERP5TypeTestCase(PortalTestCase): ...@@ -85,6 +89,18 @@ class ERP5TypeTestCase(PortalTestCase):
'''Sets up the fixture. Do not override, '''Sets up the fixture. Do not override,
use the hooks instead. use the hooks instead.
''' '''
# This is a workaround for the overwriting problem in Testing/__init__.py in Zope.
# So this overwrites them again to revert the changes made by Testing.
try:
import App.config
except ImportError:
os.environ['INSTANCE_HOME'] = INSTANCE_HOME = os.environ['COPY_OF_INSTANCE_HOME']
os.environ['SOFTWARE_HOME'] = SOFTWARE_HOME = os.environ['COPY_OF_SOFTWARE_HOME']
else:
cfg = App.config.getConfiguration()
cfg.instancehome = os.environ['COPY_OF_INSTANCE_HOME']
App.config.setConfiguration(cfg)
setupERP5Site(business_template_list = self.getBusinessTemplateList(), setupERP5Site(business_template_list = self.getBusinessTemplateList(),
portal_name = self.getPortalName()) portal_name = self.getPortalName())
PortalTestCase.setUp(self) PortalTestCase.setUp(self)
...@@ -110,41 +126,49 @@ class ERP5TypeTestCase(PortalTestCase): ...@@ -110,41 +126,49 @@ class ERP5TypeTestCase(PortalTestCase):
def getTypeTool(self): def getTypeTool(self):
return getattr(self.getPortal(), 'portal_types', None) return getattr(self.getPortal(), 'portal_types', None)
def setupERP5Site(business_template_list=(), app=None, portal_name=portal_name, quiet=0): def setupERP5Site(business_template_list=(), app=None, portal_name=portal_name, quiet=0):
''' '''
Creates an ERP5 site. Creates an ERP5 site.
business_template_list must be specified correctly (e.g. '("erp5_common", )'). business_template_list must be specified correctly (e.g. '("erp5_common", )').
''' '''
if app is None: try:
app = ZopeTestCase.app() if app is None:
if not hasattr(aq_base(app), portal_name): app = ZopeTestCase.app()
_start = time.time() if not hasattr(aq_base(app), portal_name):
# Add user and log in try:
if not quiet: ZopeTestCase._print('\nAdding ERP5TypeTestCase user ... \n') _start = time.time()
uf = app.acl_users # Add user and log in
uf._doAddUser('ERP5TypeTestCase', '', ['Manager'], []) if not quiet: ZopeTestCase._print('\nAdding ERP5TypeTestCase user ... \n')
user = uf.getUserById('ERP5TypeTestCase').__of__(uf) uf = app.acl_users
newSecurityManager(None, user) uf._doAddUser('ERP5TypeTestCase', '', ['Manager'], [])
# Add ERP5 Site user = uf.getUserById('ERP5TypeTestCase').__of__(uf)
#factory = app.manage_addProduct['CMFDefault'] newSecurityManager(None, user)
#factory.manage_addCMFSite(id) # Add ERP5 Site
if not quiet: ZopeTestCase._print('Adding %s ERP5 Site ... \n' % portal_name) #factory = app.manage_addProduct['CMFDefault']
factory = app.manage_addProduct['ERP5'] # Not needed by ERP5Type #factory.manage_addCMFSite(id)
factory.manage_addERP5Site(portal_name) if not quiet: ZopeTestCase._print('Adding %s ERP5 Site ... \n' % portal_name)
portal=app[portal_name] factory = app.manage_addProduct['ERP5'] # Not needed by ERP5Type
# VERY IMPORTANT: Add some business templates factory.manage_addERP5Site(portal_name)
for id in business_template_list: portal=app[portal_name]
ZopeTestCase._print('Adding %s business template ... \n' % id) # VERY IMPORTANT: Add some business templates
portal.portal_templates.download('%s.zexp' % id, id=id) for id in business_template_list:
portal.portal_templates[id].install() ZopeTestCase._print('Adding %s business template ... \n' % id)
# Log out portal.portal_templates.download('%s.zexp' % id, id=id)
if not quiet: ZopeTestCase._print('Logout ... \n') portal.portal_templates[id].install()
noSecurityManager() # Log out
get_transaction().commit() if not quiet: ZopeTestCase._print('Logout ... \n')
if not quiet: ZopeTestCase._print('done (%.3fs)\n' % (time.time()-_start,)) noSecurityManager()
ZopeTestCase.close(app) if not quiet: ZopeTestCase._print('done (%.3fs)\n' % (time.time()-_start,))
finally:
get_transaction().commit()
ZopeTestCase.close(app)
except:
f = StringIO()
traceback.print_exc(file=f)
ZopeTestCase._print(f.getvalue())
f.close()
def optimize(): def optimize():
......
export INSTANCE_HOME=/home/$USER/zope export INSTANCE_HOME=/home/$USER/zope
export SOFTWARE_HOME=/usr/lib/zope/lib/python/ export SOFTWARE_HOME=/usr/lib/zope/lib/python/
export COPY_OF_INSTANCE_HOME=$INSTANCE_HOME
export COPY_OF_SOFTWARE_HOME=$SOFTWARE_HOME
dir="`dirname $0`" dir="`dirname $0`"
if test -n "$dir"; then if test -n "$dir"; then
......
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