Commit f7e1b92b authored by Yoshinori Okuji's avatar Yoshinori Okuji

Support multiple test suites.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@260 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a3ce1de5
...@@ -56,6 +56,7 @@ from AccessControl.User import User ...@@ -56,6 +56,7 @@ from AccessControl.User import User
from Acquisition import aq_base from Acquisition import aq_base
import time import time
import md5
from Products.ERP5.ERP5Site import ERP5Site from Products.ERP5.ERP5Site import ERP5Site
...@@ -63,18 +64,31 @@ portal_name = 'erp5_portal' ...@@ -63,18 +64,31 @@ portal_name = 'erp5_portal'
class ERP5TypeTestCase(PortalTestCase): class ERP5TypeTestCase(PortalTestCase):
def getPortalName(self):
"""
Return the name of a portal for this test case.
This is necessary for each test case to use a different portal built by
different business templates.
"""
m = md5.new()
m.update(repr(self.getBusinessTemplateList()))
uid = m.hexdigest()
return portal_name + '_' + uid
def getPortal(self): def getPortal(self):
'''Returns the portal object, i.e. the "fixture root". '''Returns the portal object, i.e. the "fixture root".
Override if you don't like the default. Override if you don't like the default.
''' '''
return self.app[portal_name] return self.app[self.getPortalName()]
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.
''' '''
setupERP5Site(business_template_list = self.getBusinessTemplateList(),
portal_name = self.getPortalName())
PortalTestCase.setUp(self) PortalTestCase.setUp(self)
self._buildERP5Site()
def afterSetUp(self): def afterSetUp(self):
'''Called after setUp() has completed. This is '''Called after setUp() has completed. This is
...@@ -82,24 +96,24 @@ class ERP5TypeTestCase(PortalTestCase): ...@@ -82,24 +96,24 @@ class ERP5TypeTestCase(PortalTestCase):
''' '''
pass pass
def _buildERP5Site(self):
"""
ERP5 Specific - includes all steps to build a basic site
"""
pass
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
""" """
You must override this. Return the list of business templates.
""" """
return ('erp5_common', ) return ()
def setupERP5Site(app, id='portal', quiet=0): def setupERP5Site(business_template_list=(), app=None, portal_name=portal_name, quiet=0):
'''Creates a ERP5 site.''' '''
if not hasattr(aq_base(app), id): Creates an ERP5 site.
business_template_list must be specified correctly (e.g. '("erp5_common", )').
'''
if app is None:
app = ZopeTestCase.app()
if not hasattr(aq_base(app), portal_name):
_start = time.time() _start = time.time()
# Add user and log in # Add user and log in
if not quiet: ZopeTestCase._print('Adding ERP5TypeTestCase user ... \n') if not quiet: ZopeTestCase._print('\nAdding ERP5TypeTestCase user ... \n')
uf = app.acl_users uf = app.acl_users
uf._doAddUser('ERP5TypeTestCase', '', ['Manager'], []) uf._doAddUser('ERP5TypeTestCase', '', ['Manager'], [])
user = uf.getUserById('ERP5TypeTestCase').__of__(uf) user = uf.getUserById('ERP5TypeTestCase').__of__(uf)
...@@ -107,12 +121,12 @@ def setupERP5Site(app, id='portal', quiet=0): ...@@ -107,12 +121,12 @@ def setupERP5Site(app, id='portal', quiet=0):
# Add ERP5 Site # Add ERP5 Site
#factory = app.manage_addProduct['CMFDefault'] #factory = app.manage_addProduct['CMFDefault']
#factory.manage_addCMFSite(id) #factory.manage_addCMFSite(id)
if not quiet: ZopeTestCase._print('Adding ERP5 Site ... \n') if not quiet: ZopeTestCase._print('Adding %s ERP5 Site ... \n' % portal_name)
factory = app.manage_addProduct['ERP5'] # Not needed by ERP5Type factory = app.manage_addProduct['ERP5'] # Not needed by ERP5Type
factory.manage_addERP5Site(id) factory.manage_addERP5Site(portal_name)
portal=app[id] portal=app[portal_name]
# VERY IMPORTANT: Add some business templates # VERY IMPORTANT: Add some business templates
business_template_list = ('erp5_common', ) #business_template_list = ('erp5_common', 'erp5_accounting', )
for id in business_template_list: for id in business_template_list:
ZopeTestCase._print('Adding %s business template ... \n' % id) ZopeTestCase._print('Adding %s business template ... \n' % id)
portal.portal_templates.download('%s.zexp' % id, id=id) portal.portal_templates.download('%s.zexp' % id, id=id)
...@@ -122,6 +136,7 @@ def setupERP5Site(app, id='portal', quiet=0): ...@@ -122,6 +136,7 @@ def setupERP5Site(app, id='portal', quiet=0):
noSecurityManager() noSecurityManager()
get_transaction().commit() get_transaction().commit()
if not quiet: ZopeTestCase._print('done (%.3fs)\n' % (time.time()-_start,)) if not quiet: ZopeTestCase._print('done (%.3fs)\n' % (time.time()-_start,))
ZopeTestCase.close(app)
def optimize(): def optimize():
...@@ -138,12 +153,3 @@ def optimize(): ...@@ -138,12 +153,3 @@ def optimize():
ActionProviderBase._cloneActions = _cloneActions ActionProviderBase._cloneActions = _cloneActions
optimize() optimize()
# Create a ERP5 site in the test (demo-) storage
app = ZopeTestCase.app()
setupERP5Site(app, id=portal_name)
#print "Object Ids"
#print app.objectIds()
#print app.erp5.objectIds()
ZopeTestCase.close(app)
...@@ -17,6 +17,12 @@ class TestERP5Type(ERP5TypeTestCase): ...@@ -17,6 +17,12 @@ class TestERP5Type(ERP5TypeTestCase):
#def afterSetUp(self): #def afterSetUp(self):
def getBusinessTemplateList(self):
"""
Return the list of business templates.
"""
return ('erp5_common', )
def getRandomString(self): def getRandomString(self):
return str(randint(-10000000,100000000)) return str(randint(-10000000,100000000))
...@@ -80,4 +86,3 @@ else: ...@@ -80,4 +86,3 @@ else:
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5Type)) suite.addTest(unittest.makeSuite(TestERP5Type))
return suite return suite
\ No newline at end of file
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