Commit b4fee3dc authored by Alexandre Boeglin's avatar Alexandre Boeglin

Added a list of Tests to Business Templates and Portal Classes.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2269 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e12846ca
...@@ -35,6 +35,7 @@ from Products.CMFCore.WorkflowCore import WorkflowMethod ...@@ -35,6 +35,7 @@ from Products.CMFCore.WorkflowCore import WorkflowMethod
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.Utils import readLocalPropertySheet, writeLocalPropertySheet, importLocalPropertySheet, removeLocalPropertySheet from Products.ERP5Type.Utils import readLocalPropertySheet, writeLocalPropertySheet, importLocalPropertySheet, removeLocalPropertySheet
from Products.ERP5Type.Utils import readLocalExtension, writeLocalExtension, removeLocalExtension from Products.ERP5Type.Utils import readLocalExtension, writeLocalExtension, removeLocalExtension
from Products.ERP5Type.Utils import readLocalTest, writeLocalTest, removeLocalTest
from Products.ERP5Type.Utils import readLocalDocument, writeLocalDocument, importLocalDocument, removeLocalDocument from Products.ERP5Type.Utils import readLocalDocument, writeLocalDocument, importLocalDocument, removeLocalDocument
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
import cStringIO import cStringIO
...@@ -712,6 +713,27 @@ class ExtensionTemplateItem(BaseTemplateItem): ...@@ -712,6 +713,27 @@ class ExtensionTemplateItem(BaseTemplateItem):
pass pass
BaseTemplateItem.uninstall(self, context, **kw) BaseTemplateItem.uninstall(self, context, **kw)
class TestTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
BaseTemplateItem.build(self, context, **kw)
for id in self._archive.keys():
self._archive[id] = readLocalTest(id)
def install(self, context, **kw):
BaseTemplateItem.install(self, context, **kw)
for id,text in self._archive.items():
writeLocalTest(id, text, create=1) # This raises an exception if the file exists.
importLocalPropertySheet(id)
def uninstall(self, context, **kw):
for id in self._archive.keys():
try:
removeLocalTest(id)
except OSError:
pass
BaseTemplateItem.uninstall(self, context, **kw)
class ProductTemplateItem(BaseTemplateItem): pass # Not implemented yet class ProductTemplateItem(BaseTemplateItem): pass # Not implemented yet
...@@ -1019,6 +1041,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1019,6 +1041,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
_document_item = None _document_item = None
_property_sheet_item = None _property_sheet_item = None
_extension_item = None _extension_item = None
_test_item = None
_product_item = None _product_item = None
_role_item = None _role_item = None
_catalog_result_key_item = None _catalog_result_key_item = None
...@@ -1087,6 +1110,10 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1087,6 +1110,10 @@ Business Template is a set of definitions, such as skins, portal types and categ
self._extension_item = ExtensionTemplateItem(self.getTemplateExtensionIdList()) self._extension_item = ExtensionTemplateItem(self.getTemplateExtensionIdList())
self._extension_item.build(self) self._extension_item.build(self)
# Copy Test Classes
self._test_item = TestTemplateItem(self.getTemplateTestIdList())
self._test_item.build(self)
# Copy Products # Copy Products
self._product_item = ProductTemplateItem(self.getTemplateProductIdList()) self._product_item = ProductTemplateItem(self.getTemplateProductIdList())
self._product_item.build(self) self._product_item.build(self)
...@@ -1144,6 +1171,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1144,6 +1171,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
if self._property_sheet_item is not None: self._property_sheet_item.install(local_configuration) if self._property_sheet_item is not None: self._property_sheet_item.install(local_configuration)
if self._document_item is not None: self._document_item.install(local_configuration) if self._document_item is not None: self._document_item.install(local_configuration)
if self._extension_item is not None: self._extension_item.install(local_configuration) if self._extension_item is not None: self._extension_item.install(local_configuration)
if self._test_item is not None: self._test_item.install(local_configuration)
if self._role_item is not None: self._role_item.install(local_configuration) if self._role_item is not None: self._role_item.install(local_configuration)
# Message translations # Message translations
...@@ -1218,6 +1246,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1218,6 +1246,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
if self._property_sheet_item is not None: self._property_sheet_item.trash(local_configuration, new_bt._property_sheet_item) if self._property_sheet_item is not None: self._property_sheet_item.trash(local_configuration, new_bt._property_sheet_item)
if self._document_item is not None: self._document_item.trash(local_configuration, new_bt._document_item) if self._document_item is not None: self._document_item.trash(local_configuration, new_bt._document_item)
if self._extension_item is not None: self._extension_item.trash(local_configuration, new_bt._extension_item) if self._extension_item is not None: self._extension_item.trash(local_configuration, new_bt._extension_item)
if self._test_item is not None: self._test_item.trash(local_configuration, new_bt._test_item)
if self._role_item is not None: self._role_item.trash(local_configuration, new_bt._role_item) if self._role_item is not None: self._role_item.trash(local_configuration, new_bt._role_item)
def uninstall(self, **kw): def uninstall(self, **kw):
...@@ -1258,6 +1287,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1258,6 +1287,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
if self._property_sheet_item is not None: self._property_sheet_item.uninstall(local_configuration) if self._property_sheet_item is not None: self._property_sheet_item.uninstall(local_configuration)
if self._document_item is not None: self._document_item.uninstall(local_configuration) if self._document_item is not None: self._document_item.uninstall(local_configuration)
if self._extension_item is not None: self._extension_item.uninstall(local_configuration) if self._extension_item is not None: self._extension_item.uninstall(local_configuration)
if self._test_item is not None: self._test_item.uninstall(local_configuration)
if self._role_item is not None: self._role_item.uninstall(local_configuration) if self._role_item is not None: self._role_item.uninstall(local_configuration)
# It is better to clear cache because the uninstallation of a template # It is better to clear cache because the uninstallation of a template
...@@ -1271,7 +1301,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1271,7 +1301,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
Clean built information. Clean built information.
""" """
# First, remove obsolete attributes if present. # First, remove obsolete attributes if present.
for attr in ('_action_archive', '_document_archive', '_extension_archive', '_module_archive', for attr in ('_action_archive', '_document_archive', '_extension_archive', '_test_archive', '_module_archive',
'_object_archive', '_portal_type_archive', '_property_archive', '_property_sheet_archive'): '_object_archive', '_portal_type_archive', '_property_archive', '_property_sheet_archive'):
if hasattr(self, attr): if hasattr(self, attr):
delattr(self, attr) delattr(self, attr)
...@@ -1288,6 +1318,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1288,6 +1318,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
self._document_item = None self._document_item = None
self._property_sheet_item = None self._property_sheet_item = None
self._extension_item = None self._extension_item = None
self._test_item = None
self._product_item = None self._product_item = None
self._role_item = None self._role_item = None
self._catalog_result_key_item = None self._catalog_result_key_item = None
......
...@@ -107,6 +107,11 @@ class BusinessTemplate: ...@@ -107,6 +107,11 @@ class BusinessTemplate:
'type' : 'lines', 'type' : 'lines',
'mode' : 'w', 'mode' : 'w',
'default' : () }, 'default' : () },
{ 'id' : 'template_test_id',
'description' : 'A list of ids of tests used by this module',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_path', { 'id' : 'template_path',
'description' : 'A list of object paths used by this module', 'description' : 'A list of object paths used by this module',
'type' : 'lines', 'type' : 'lines',
......
...@@ -38,6 +38,7 @@ from Products.ERP5Type.Document.Folder import Folder ...@@ -38,6 +38,7 @@ from Products.ERP5Type.Document.Folder import Folder
from Products.ERP5Type.Utils import readLocalPropertySheet, writeLocalPropertySheet, getLocalPropertySheetList from Products.ERP5Type.Utils import readLocalPropertySheet, writeLocalPropertySheet, getLocalPropertySheetList
from Products.ERP5Type.Utils import readLocalExtension, writeLocalExtension, getLocalExtensionList from Products.ERP5Type.Utils import readLocalExtension, writeLocalExtension, getLocalExtensionList
from Products.ERP5Type.Utils import readLocalTest, writeLocalTest, getLocalTestList
from Products.ERP5Type.Utils import readLocalDocument, writeLocalDocument, getLocalDocumentList from Products.ERP5Type.Utils import readLocalDocument, writeLocalDocument, getLocalDocumentList
from Products.ERP5Type.Utils import readLocalConstraint, writeLocalConstraint, getLocalConstraintList from Products.ERP5Type.Utils import readLocalConstraint, writeLocalConstraint, getLocalConstraintList
from Products.ERP5Type.InitGenerator import getProductDocumentPathList from Products.ERP5Type.InitGenerator import getProductDocumentPathList
...@@ -76,6 +77,9 @@ if allowClassTool(): ...@@ -76,6 +77,9 @@ if allowClassTool():
,{ 'label' : 'Extensions' ,{ 'label' : 'Extensions'
, 'action' : 'manage_viewExtensionList' , 'action' : 'manage_viewExtensionList'
} }
,{ 'label' : 'Tests'
, 'action' : 'manage_viewTestList'
}
, ,
) )
+ tuple ( + tuple (
...@@ -95,6 +99,9 @@ if allowClassTool(): ...@@ -95,6 +99,9 @@ if allowClassTool():
security.declareProtected( Permissions.ManagePortal, 'manage_viewExtensionList' ) security.declareProtected( Permissions.ManagePortal, 'manage_viewExtensionList' )
manage_viewExtensionList = DTMLFile( 'viewExtensionList', _dtmldir ) manage_viewExtensionList = DTMLFile( 'viewExtensionList', _dtmldir )
security.declareProtected( Permissions.ManagePortal, 'manage_viewTestList' )
manage_viewTestList = DTMLFile( 'viewTestList', _dtmldir )
security.declareProtected( Permissions.ManagePortal, 'manage_viewConstraintList' ) security.declareProtected( Permissions.ManagePortal, 'manage_viewConstraintList' )
manage_viewConstraintList = DTMLFile( 'viewConstraintList', _dtmldir ) manage_viewConstraintList = DTMLFile( 'viewConstraintList', _dtmldir )
...@@ -104,6 +111,9 @@ if allowClassTool(): ...@@ -104,6 +111,9 @@ if allowClassTool():
security.declareProtected( Permissions.ManagePortal, 'manage_editExtensionForm' ) security.declareProtected( Permissions.ManagePortal, 'manage_editExtensionForm' )
manage_editExtensionForm = DTMLFile( 'editExtensionForm', _dtmldir ) manage_editExtensionForm = DTMLFile( 'editExtensionForm', _dtmldir )
security.declareProtected( Permissions.ManagePortal, 'manage_editTestForm' )
manage_editTestForm = DTMLFile( 'editTestForm', _dtmldir )
security.declareProtected( Permissions.ManagePortal, 'manage_editConstraintForm' ) security.declareProtected( Permissions.ManagePortal, 'manage_editConstraintForm' )
manage_editConstraintForm = DTMLFile( 'editConstraintForm', _dtmldir ) manage_editConstraintForm = DTMLFile( 'editConstraintForm', _dtmldir )
...@@ -132,6 +142,13 @@ if allowClassTool(): ...@@ -132,6 +142,13 @@ if allowClassTool():
""" """
return getLocalExtensionList() return getLocalExtensionList()
security.declareProtected( Permissions.ManagePortal, 'getLocalTestList' )
def getLocalTestList(self):
"""
Return a list of Test id which can be modified through the web
"""
return getLocalTestList()
security.declareProtected( Permissions.ManagePortal, 'getLocalConstraintList' ) security.declareProtected( Permissions.ManagePortal, 'getLocalConstraintList' )
def getLocalConstraintList(self): def getLocalConstraintList(self):
""" """
...@@ -389,6 +406,132 @@ def myExtensionMethod(self, param=None): ...@@ -389,6 +406,132 @@ def myExtensionMethod(self, param=None):
if REQUEST is not None: if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editExtensionForm?class_id=%s&message=Extension+Saved' % (self.absolute_url(), class_id)) REQUEST.RESPONSE.redirect('%s/manage_editExtensionForm?class_id=%s&message=Extension+Saved' % (self.absolute_url(), class_id))
security.declareProtected( Permissions.ManagePortal, 'getTestText' )
def getTestText(self, class_id):
"""
Updates a Test with a new text
"""
return readLocalTest(class_id)
security.declareProtected( Permissions.ManageExtensions, 'newTest' )
def newTest(self, class_id, REQUEST=None):
"""
Updates a Test with a new text
"""
text = '''
##############################################################################
#
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
# Needed in order to have a log file inside the current folder
os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log')
os.environ['EVENT_LOG_SEVERITY'] = '-300'
from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager
from zLOG import LOG
class Test(ERP5TypeTestCase):
"""
This is a Sample Test
"""
# variable used for this test
run_all_test = 1
def getTitle(self):
return "SampleTest"
def getBusinessTemplateList(self):
"""
Tuple of Business Templates we need to install
"""
return ()
def enableLightInstall(self):
"""
Return if we should do a light install (1) or not (0)
"""
return 1
def enableActivityTool(self):
"""
Return if we should create (1) or not (0) an activity tool
"""
return 1
def login(self, quiet=0, run=run_all_test):
uf = self.getPortal().acl_users
uf._doAddUser('alex', '', ['Manager'], [])
user = uf.getUserById('alex').__of__(uf)
newSecurityManager(None, user)
def afterSetUp(self, quiet=1, run=1):
"""
This is ran before anything, used to set the environment
"""
self.login()
def test_01_SampleTest(self, quiet=0, run=run_all_test):
"""
A Sample Test
"""
if not run: return
if not quiet:
ZopeTestCase._print('\\nTest SampleTest ')
LOG('Testing... ',0,'testSampleTest')
self.assertEqual(0, 1)
if __name__ == '__main__':
framework()
else:
import unittest
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Test))
return suite
'''
writeLocalTest(class_id, text)
if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editTestForm?class_id=%s&message=Test+Created' % (self.absolute_url(), class_id))
security.declareProtected( Permissions.ManageExtensions, 'editTest' )
def editTest(self, class_id, text, REQUEST=None):
"""
Updates a Test with a new text
"""
previous_text = readLocalTest(class_id)
writeLocalTest(class_id, text, create=0)
if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editTestForm?class_id=%s&message=Test+Saved' % (self.absolute_url(), class_id))
security.declareProtected( Permissions.ManagePortal, 'getConstraintText' ) security.declareProtected( Permissions.ManagePortal, 'getConstraintText' )
def getConstraintText(self, class_id): def getConstraintText(self, class_id):
""" """
...@@ -479,4 +622,4 @@ else: ...@@ -479,4 +622,4 @@ else:
manage_overview = DTMLFile( 'explainDummyClassTool', _dtmldir ) manage_overview = DTMLFile( 'explainDummyClassTool', _dtmldir )
InitializeClass(ClassTool) InitializeClass(ClassTool)
\ No newline at end of file
...@@ -373,6 +373,18 @@ def getLocalExtensionList(): ...@@ -373,6 +373,18 @@ def getLocalExtensionList():
result.sort() result.sort()
return result return result
def getLocalTestList():
if not getConfiguration: return []
instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "tests")
file_list = os.listdir(path)
result = []
for fname in file_list:
if python_file_parser.match(fname) is not None:
result.append(python_file_parser.match(fname).groups()[0])
result.sort()
return result
def getLocalConstraintList(): def getLocalConstraintList():
if not getConfiguration: return [] if not getConfiguration: return []
instance_home = getConfiguration().instancehome instance_home = getConfiguration().instancehome
...@@ -400,6 +412,21 @@ def readLocalExtension(class_id): ...@@ -400,6 +412,21 @@ def readLocalExtension(class_id):
f.close() f.close()
return text return text
def removeLocalTest(class_id):
instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "tests")
path = os.path.join(path, "%s.py" % class_id)
os.remove(path)
def readLocalTest(class_id):
instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "tests")
path = os.path.join(path, "%s.py" % class_id)
f = open(path)
text = f.read()
f.close()
return text
def readLocalConstraint(class_id): def readLocalConstraint(class_id):
instance_home = getConfiguration().instancehome instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "Constraint") path = os.path.join(instance_home, "Constraint")
...@@ -419,6 +446,16 @@ def writeLocalExtension(class_id, text, create=1): ...@@ -419,6 +446,16 @@ def writeLocalExtension(class_id, text, create=1):
f = open(path, 'w') f = open(path, 'w')
f.write(text) f.write(text)
def writeLocalTest(class_id, text, create=1):
instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "tests")
path = os.path.join(path, "%s.py" % class_id)
if create:
if os.path.exists(path):
raise IOError, 'the file %s is already present' % path
f = open(path, 'w')
f.write(text)
def writeLocalConstraint(class_id, text, create=1): def writeLocalConstraint(class_id, text, create=1):
instance_home = getConfiguration().instancehome instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "Constraint") path = os.path.join(instance_home, "Constraint")
......
<dtml-var manage_page_header>
<dtml-var manage_tabs>
<h2>Edit Test Class: <dtml-var class_id></h2>
<dtml-if message><dtml-var message></dtml-if>
<form method="POST" action="<dtml-var absolute_url>">
<textarea name="text:text" rows="20" cols="82"><dtml-var "getTestText(class_id)"></textarea>
<br>
<input type="hidden" name="class_id:string" value="<dtml-var class_id>">
<input type="submit" value="Save" name="editTest:method">
</form>
<dtml-var manage_page_footer>
<dtml-var manage_page_header>
<dtml-var manage_tabs>
<div class="std-text"><p><strong>Local Test Classes</strong></p></div>
<form method="POST" action="newTest">
<table width="100%">
<tr class="list-header">
<th>
Class
</th>
<th>
Actions
</th>
<dtml-in getLocalTestList>
<tr>
<td>
<div class="list-item"><dtml-var sequence-item></div>
</td>
<td>
<div class="list-item"><a href="manage_editTestForm?class_id=<dtml-var sequence-item>">edit</a>&nbsp;
</div>
</td>
</tr>
</dtml-in>
</table>
<input type="text" name="class_id" /> <input type="submit" value="Create New Test" />
</form>
<dtml-var manage_page_footer>
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