Commit 283f7d8a authored by Jérome Perrin's avatar Jérome Perrin

Unify indentation



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8480 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d5eff119
...@@ -199,121 +199,124 @@ class ERP5TypeTestCase(PortalTestCase): ...@@ -199,121 +199,124 @@ class ERP5TypeTestCase(PortalTestCase):
uf._doAddUser(user_name, 'secret', ['Member'], []) uf._doAddUser(user_name, 'secret', ['Member'], [])
def setUp(self): def setUp(self):
'''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. # This is a workaround for the overwriting problem in Testing/__init__.py
# So this overwrites them again to revert the changes made by Testing. # in Zope. So this overwrites them again to revert the changes made by
try: # Testing.
import App.config try:
except ImportError: import App.config
os.environ['INSTANCE_HOME'] = INSTANCE_HOME = os.environ['COPY_OF_INSTANCE_HOME'] except ImportError:
os.environ['SOFTWARE_HOME'] = SOFTWARE_HOME = os.environ['COPY_OF_SOFTWARE_HOME'] os.environ['INSTANCE_HOME'] = INSTANCE_HOME =\
else: os.environ['COPY_OF_INSTANCE_HOME']
cfg = App.config.getConfiguration() os.environ['SOFTWARE_HOME'] = SOFTWARE_HOME =\
cfg.instancehome = os.environ['COPY_OF_INSTANCE_HOME'] os.environ['COPY_OF_SOFTWARE_HOME']
App.config.setConfiguration(cfg) else:
INSTANCE_HOME = os.environ['INSTANCE_HOME'] cfg = App.config.getConfiguration()
cfg.instancehome = os.environ['COPY_OF_INSTANCE_HOME']
template_list = self.getBusinessTemplateList() App.config.setConfiguration(cfg)
new_template_list = [] INSTANCE_HOME = os.environ['INSTANCE_HOME']
LOG('template_list',0,template_list)
for template in template_list: template_list = self.getBusinessTemplateList()
id = template new_template_list = []
try : LOG('template_list',0,template_list)
file, headers = urlretrieve(template) for template in template_list:
except IOError : id = template
# First, try the bt5 directory itself. try :
path = os.path.join(INSTANCE_HOME, 'bt5', template) file, headers = urlretrieve(template)
except IOError :
# First, try the bt5 directory itself.
path = os.path.join(INSTANCE_HOME, 'bt5', template)
if os.path.exists(path):
template = path
else:
path = '%s.bt5' % path
if os.path.exists(path): if os.path.exists(path):
template = path template = path
else: else:
path = '%s.bt5' % path # Otherwise, look at sub-directories.
if os.path.exists(path): # This is for backward-compatibility.
template = path path = os.path.join(INSTANCE_HOME, 'bt5', '*', template)
template_list = glob(path)
if len(template_list) == 0:
template_list = glob('%s.bt5' % path)
if len(template_list) and template_list[0]:
template = template_list[0]
else: else:
# Otherwise, look at sub-directories. # The last resort is current directory.
# This is for backward-compatibility. template = '%s' % id
path = os.path.join(INSTANCE_HOME, 'bt5', '*', template) if not os.path.exists(template):
template_list = glob(path) template = '%s.bt5' % id
if len(template_list) == 0: else:
template_list = glob('%s.bt5' % path) template = '%s' % template
if len(template_list) and template_list[0]: if not os.path.exists(template):
template = template_list[0] template = '%s.bt5' % template
else: new_template_list.append((template,id))
# The last resort is current directory.
template = '%s' % id light_install = self.enableLightInstall()
if not os.path.exists(template): create_activities = self.enableActivityTool()
template = '%s.bt5' % id hot_reindexing = self.enableHotReindexing()
else: setupERP5Site(business_template_list=new_template_list,
template = '%s' % template light_install=light_install,
if not os.path.exists(template): portal_name=self.getPortalName(),
template = '%s.bt5' % template title=self.getTitle(),
new_template_list.append((template,id)) create_activities=create_activities,
hot_reindexing=hot_reindexing)
light_install = self.enableLightInstall() PortalTestCase.setUp(self)
create_activities = self.enableActivityTool()
hot_reindexing = self.enableHotReindexing()
setupERP5Site(business_template_list=new_template_list,
light_install=light_install,
portal_name=self.getPortalName(),
title=self.getTitle(),
create_activities=create_activities,
hot_reindexing=hot_reindexing)
PortalTestCase.setUp(self)
def afterSetUp(self): def afterSetUp(self):
'''Called after setUp() has completed. This is '''Called after setUp() has completed. This is
far and away the most useful hook. far and away the most useful hook.
''' '''
pass pass
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
""" """
You must override this. Return the list of business templates. You must override this. Return the list of business templates.
""" """
return () return ()
def logMessage(self, message): def logMessage(self, message):
""" """
Shortcut function to log a message Shortcut function to log a message
""" """
ZopeTestCase._print('\n%s ' % message) ZopeTestCase._print('\n%s ' % message)
LOG('Testing ... ', DEBUG, message) LOG('Testing ... ', DEBUG, message)
# Utility methods specific to ERP5Type # Utility methods specific to ERP5Type
def getTemplateTool(self): def getTemplateTool(self):
return getToolByName(self.getPortal(), 'portal_templates', None) return getToolByName(self.getPortal(), 'portal_templates', None)
def getTrashTool(self): def getTrashTool(self):
return getToolByName(self.getPortal(), 'portal_trash', None) return getToolByName(self.getPortal(), 'portal_trash', None)
def getSkinsTool(self): def getSkinsTool(self):
return getToolByName(self.getPortal(), 'portal_skins', None) return getToolByName(self.getPortal(), 'portal_skins', None)
def getCategoryTool(self): def getCategoryTool(self):
return getToolByName(self.getPortal(), 'portal_categories', None) return getToolByName(self.getPortal(), 'portal_categories', None)
def getWorkflowTool(self): def getWorkflowTool(self):
return getToolByName(self.getPortal(), 'portal_workflow', None) return getToolByName(self.getPortal(), 'portal_workflow', None)
def getCatalogTool(self): def getCatalogTool(self):
return getToolByName(self.getPortal(), 'portal_catalog', None) return getToolByName(self.getPortal(), 'portal_catalog', None)
def getTypeTool(self): def getTypeTool(self):
return getToolByName(self.getPortal(), 'portal_types', None) return getToolByName(self.getPortal(), 'portal_types', None)
def getRuleTool(self): def getRuleTool(self):
return getattr(self.getPortal(), 'portal_rules', None) return getattr(self.getPortal(), 'portal_rules', None)
def getClassTool(self): def getClassTool(self):
return getattr(self.getPortal(), 'portal_classes', None) return getattr(self.getPortal(), 'portal_classes', None)
def getSimulationTool(self): def getSimulationTool(self):
return getToolByName(self.getPortal(), 'portal_simulation', None) return getToolByName(self.getPortal(), 'portal_simulation', None)
def getSqlConnection(self): def getSqlConnection(self):
return getToolByName(self.getPortal(), 'erp5_sql_connection', None) return getToolByName(self.getPortal(), 'erp5_sql_connection', None)
def getPortalId(self): def getPortalId(self):
return self.getPortal().getId() return self.getPortal().getId()
...@@ -367,11 +370,18 @@ class ERP5TypeTestCase(PortalTestCase): ...@@ -367,11 +370,18 @@ class ERP5TypeTestCase(PortalTestCase):
self.failUnless(i in a, msg) self.failUnless(i in a, msg)
self.assertEquals(len(a), len(b), msg) self.assertEquals(len(a), len(b), msg)
def setupERP5Site(business_template_list=(), app=None, portal_name=portal_name, title='',quiet=0, def setupERP5Site( business_template_list=(),
light_install=1,create_activities=1,hot_reindexing=1): app=None,
portal_name=portal_name,
title='',
quiet=0,
light_install=1,
create_activities=1,
hot_reindexing=1 ):
''' '''
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", )').
''' '''
try: try:
if app is None: if app is None:
...@@ -379,79 +389,83 @@ def setupERP5Site(business_template_list=(), app=None, portal_name=portal_name, ...@@ -379,79 +389,83 @@ def setupERP5Site(business_template_list=(), app=None, portal_name=portal_name,
global current_app global current_app
current_app = app current_app = app
if not hasattr(aq_base(app), portal_name): if not hasattr(aq_base(app), portal_name):
try: try:
_start = time.time() _start = time.time()
# Add user and log in # Add user and log in
if not quiet: ZopeTestCase._print('\nAdding ERP5TypeTestCase user ... \n') if not quiet:
uf = app.acl_users ZopeTestCase._print('\nAdding ERP5TypeTestCase user ... \n')
uf._doAddUser('ERP5TypeTestCase', '', ['Manager'], []) uf = app.acl_users
user = uf.getUserById('ERP5TypeTestCase').__of__(uf) uf._doAddUser('ERP5TypeTestCase', '', ['Manager'], [])
newSecurityManager(None, user) user = uf.getUserById('ERP5TypeTestCase').__of__(uf)
# Add ERP5 Site newSecurityManager(None, user)
reindex = 1 # Add ERP5 Site
if hot_reindexing: reindex = 1
setattr(app,'isIndexable',0) if hot_reindexing:
reindex = 0 setattr(app,'isIndexable',0)
if not quiet: reindex = 0
ZopeTestCase._print('Adding %s ERP5 Site ... ' % portal_name) if not quiet:
factory = app.manage_addProduct['ERP5'] # Not needed by ERP5Type ZopeTestCase._print('Adding %s ERP5 Site ... ' % portal_name)
factory.manage_addERP5Site(portal_name,light_install=light_install, factory = app.manage_addProduct['ERP5'] # Not needed by ERP5Type
reindex=reindex,create_activities=create_activities) factory.manage_addERP5Site(portal_name,light_install=light_install,
if not quiet: reindex=reindex,create_activities=create_activities)
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - _start)) if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - _start))
# Release locks
get_transaction().commit()
portal=app[portal_name]
# Remove all local PropertySheets, Documents
for id in getLocalPropertySheetList():
removeLocalPropertySheet(id)
for id in getLocalDocumentList():
removeLocalDocument(id)
for id in getLocalConstraintList():
removeLocalConstraint(id)
# Disable reindexing before adding templates
# VERY IMPORTANT: Add some business templates
for url, id in business_template_list:
start = time.time()
ZopeTestCase._print('Adding %s business template ... ' % id)
portal.portal_templates.download(url, id=id)
portal.portal_templates[id].install(light_install=light_install)
# Release locks # Release locks
get_transaction().commit() get_transaction().commit()
portal=app[portal_name] ZopeTestCase._print('done (%.3fs)\n' % (time.time() - start))
# Remove all local PropertySheets, Documents # Enbable reindexing
for id in getLocalPropertySheetList(): # Do hot reindexing # Does not work
removeLocalPropertySheet(id) if hot_reindexing:
for id in getLocalDocumentList(): setattr(app,'isIndexable', 1)
removeLocalDocument(id) portal.portal_catalog.manage_hotReindexAll()
for id in getLocalConstraintList():
removeLocalConstraint(id) get_transaction().commit()
# Disable reindexing before adding templates portal_activities = getattr(portal, 'portal_activities', None)
# VERY IMPORTANT: Add some business templates if portal_activities is not None:
for url, id in business_template_list: count = 1000
start = time.time() while len(portal_activities.getMessageList()) > 0:
ZopeTestCase._print('Adding %s business template ... ' % id) portal_activities.distribute()
portal.portal_templates.download(url, id=id) portal_activities.tic()
portal.portal_templates[id].install(light_install=light_install)
# Release locks
get_transaction().commit() get_transaction().commit()
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - start)) count -= 1
# Enbable reindexing if count == 0:
# Do hot reindexing # Does not work raise RuntimeError, \
if hot_reindexing: 'tic is looping forever. These messages are pending: %r' % (
setattr(app,'isIndexable', 1) [('/'.join(m.object_path), m.method_id,
portal.portal_catalog.manage_hotReindexAll() m.processing_node, m.priority)
for m in portal_activities.getMessageList()],)
get_transaction().commit() # Reset aq dynamic, so all unit tests will start again
portal_activities = getattr(portal, 'portal_activities', None) from Products.ERP5Type.Base import _aq_reset
if portal_activities is not None: _aq_reset()
count = 1000 # Log out
while len(portal_activities.getMessageList()) > 0: if not quiet:
portal_activities.distribute() ZopeTestCase._print('Logout ... \n')
portal_activities.tic() noSecurityManager()
get_transaction().commit() if not quiet:
count -= 1 ZopeTestCase._print('done (%.3fs)\n' % (time.time()-_start,))
if count == 0: if not quiet:
raise RuntimeError, \ ZopeTestCase._print('Ran Unit test of %s\n' % title)
'tic is looping forever. These messages are pending: %r' % ( finally:
[('/'.join(m.object_path), m.method_id, get_transaction().commit()
m.processing_node, m.priority) ZopeTestCase.close(app)
for m in portal_activities.getMessageList()],) pass
# Reset aq dynamic, so all unit tests will start again
from Products.ERP5Type.Base import _aq_reset
_aq_reset()
# Log out
if not quiet: ZopeTestCase._print('Logout ... \n')
noSecurityManager()
if not quiet: ZopeTestCase._print('done (%.3fs)\n' % (time.time()-_start,))
if not quiet: ZopeTestCase._print('Ran Unit test of %s\n' % title)
finally:
get_transaction().commit()
ZopeTestCase.close(app)
pass
except: except:
f = StringIO() f = StringIO()
traceback.print_exc(file=f) traceback.print_exc(file=f)
...@@ -460,16 +474,16 @@ def setupERP5Site(business_template_list=(), app=None, portal_name=portal_name, ...@@ -460,16 +474,16 @@ def setupERP5Site(business_template_list=(), app=None, portal_name=portal_name,
def optimize(): def optimize():
'''Significantly reduces portal creation time.''' '''Significantly reduces portal creation time.'''
def __init__(self, text): def __init__(self, text):
# Don't compile expressions on creation # Don't compile expressions on creation
self.text = text self.text = text
from Products.CMFCore.Expression import Expression from Products.CMFCore.Expression import Expression
Expression.__init__ = __init__ Expression.__init__ = __init__
def _cloneActions(self): def _cloneActions(self):
# Don't clone actions but convert to list only # Don't clone actions but convert to list only
return list(self._actions) return list(self._actions)
from Products.CMFCore.ActionProviderBase import ActionProviderBase from Products.CMFCore.ActionProviderBase import ActionProviderBase
ActionProviderBase._cloneActions = _cloneActions ActionProviderBase._cloneActions = _cloneActions
optimize() optimize()
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