[CMF-checkins] CVS: CMF/CMFSetup/tests - conformance.py:1.3
test_all.py:1.11 test_registry.py:1.11 test_tool.py:1.11
test_toolset.py:NONE
Tres Seaver
tseaver at zope.com
Wed Jun 30 14:13:30 EDT 2004
Update of /cvs-repository/CMF/CMFSetup/tests
In directory cvs.zope.org:/tmp/cvs-serv26029/tests
Modified Files:
conformance.py test_all.py test_registry.py test_tool.py
Removed Files:
test_toolset.py
Log Message:
- The "toolset" handler had a bootstrapping problem; it relies on
state which is not kept anywhere in the site! Solve the problem
by making the handler a sub-object of the setup tool, and renaming
it "ToolsetRegistry" (note that its code migrated into the 'registry'
module).
- Add tests for export / import of toolset on actual site.
=== CMF/CMFSetup/tests/conformance.py 1.2 => 1.3 ===
--- CMF/CMFSetup/tests/conformance.py:1.2 Sun May 23 14:57:39 2004
+++ CMF/CMFSetup/tests/conformance.py Wed Jun 30 14:13:00 2004
@@ -60,6 +60,15 @@
verifyClass( IExportStepRegistry, self._getTargetClass() )
+class ConformsToIToolsetRegistry:
+
+ def test_IToolsetRegistry_conformance( self ):
+
+ from Products.CMFSetup.interfaces import IToolsetRegistry
+ from Interface.Verify import verifyClass
+
+ verifyClass( IToolsetRegistry, self._getTargetClass() )
+
class ConformsToISetupTool:
def test_ISetupTool_conformance( self ):
=== CMF/CMFSetup/tests/test_all.py 1.10 => 1.11 ===
--- CMF/CMFSetup/tests/test_all.py:1.10 Fri Jun 25 16:21:57 2004
+++ CMF/CMFSetup/tests/test_all.py Wed Jun 30 14:13:00 2004
@@ -19,7 +19,7 @@
, 'test_rolemap'
, 'test_skins'
, 'test_tool'
- , 'test_toolset'
+ # , 'test_toolset'
, 'test_typeinfo'
, 'test_utils'
, 'test_workflow'
=== CMF/CMFSetup/tests/test_registry.py 1.10 => 1.11 ===
--- CMF/CMFSetup/tests/test_registry.py:1.10 Tue Jun 8 15:44:19 2004
+++ CMF/CMFSetup/tests/test_registry.py Wed Jun 30 14:13:00 2004
@@ -5,11 +5,13 @@
import unittest
import os
+from OFS.Folder import Folder
from Products.CMFSetup.tests.common import BaseRegistryTests
from conformance import ConformsToIStepRegistry
from conformance import ConformsToIImportStepRegistry
from conformance import ConformsToIExportStepRegistry
+from conformance import ConformsToIToolsetRegistry
#==============================================================================
# Dummy handlers
@@ -801,11 +803,211 @@
</export-steps>
""" % ( ONE_FUNC_NAME, THREE_FUNC_NAME, TWO_FUNC_NAME )
+#==============================================================================
+# ToolsetRegistry tests
+#==============================================================================
+class ToolsetRegistryTests( BaseRegistryTests
+ , ConformsToIToolsetRegistry
+ ):
+
+ def _getTargetClass( self ):
+
+ from Products.CMFSetup.registry import ToolsetRegistry
+ return ToolsetRegistry
+
+ def _initSite( self ):
+
+ self.root.site = Folder( id='site' )
+ site = self.root.site
+
+ return site
+
+ def test_empty( self ):
+
+ site = self._initSite()
+ configurator = self._makeOne().__of__( site )
+
+ self.assertEqual( len( configurator.listForbiddenTools() ), 0 )
+ self.assertEqual( len( configurator.listRequiredTools() ), 0 )
+ self.assertEqual( len( configurator.listRequiredToolInfo() ), 0 )
+
+ self.assertRaises( KeyError
+ , configurator.getRequiredToolInfo, 'nonesuch' )
+
+ def test_addForbiddenTool_multiple( self ):
+
+ VERBOTTEN = ( 'foo', 'bar', 'bam' )
+
+ site = self._initSite()
+ configurator = self._makeOne().__of__( site )
+
+ for verbotten in VERBOTTEN:
+ configurator.addForbiddenTool( verbotten )
+
+ self.assertEqual( len( configurator.listForbiddenTools() )
+ , len( VERBOTTEN ) )
+
+ for verbotten in configurator.listForbiddenTools():
+ self.failUnless( verbotten in VERBOTTEN )
+
+ def test_addForbiddenTool_duplicate( self ):
+
+ site = self._initSite()
+ configurator = self._makeOne().__of__( site )
+
+ configurator.addForbiddenTool( 'once' )
+
+ self.assertRaises( KeyError, configurator.addForbiddenTool, 'once' )
+
+ def test_addForbiddenTool_but_required( self ):
+
+ site = self._initSite()
+ configurator = self._makeOne().__of__( site )
+
+ configurator.addRequiredTool( 'required', 'some.dotted.name' )
+
+ self.assertRaises( ValueError
+ , configurator.addForbiddenTool, 'required' )
+
+ def test_addRequiredTool_multiple( self ):
+
+ REQUIRED = ( ( 'one', 'path.to.one' )
+ , ( 'two', 'path.to.two' )
+ , ( 'three', 'path.to.three' )
+ )
+
+ site = self._initSite()
+ configurator = self._makeOne().__of__( site )
+
+ for tool_id, dotted_name in REQUIRED:
+ configurator.addRequiredTool( tool_id, dotted_name )
+
+ self.assertEqual( len( configurator.listRequiredTools() )
+ , len( REQUIRED ) )
+
+ for id in [ x[0] for x in REQUIRED ]:
+ self.failUnless( id in configurator.listRequiredTools() )
+
+ self.assertEqual( len( configurator.listRequiredToolInfo() )
+ , len( REQUIRED ) )
+
+ for tool_id, dotted_name in REQUIRED:
+ info = configurator.getRequiredToolInfo( tool_id )
+ self.assertEqual( info[ 'id' ], tool_id )
+ self.assertEqual( info[ 'class' ], dotted_name )
+
+ def test_addRequiredTool_duplicate( self ):
+
+ site = self._initSite()
+ configurator = self._makeOne().__of__( site )
+
+ configurator.addRequiredTool( 'required', 'some.dotted.name' )
+
+ self.assertRaises( KeyError
+ , configurator.addRequiredTool
+ , 'required'
+ , 'another.name'
+ )
+
+ def test_addRequiredTool_but_forbidden( self ):
+
+ site = self._initSite()
+ configurator = self._makeOne().__of__( site )
+
+ configurator.addForbiddenTool( 'forbidden' )
+
+ self.assertRaises( ValueError
+ , configurator.addRequiredTool
+ , 'forbidden'
+ , 'a.name'
+ )
+
+ def test_generateXML_empty( self ):
+
+ site = self._initSite()
+ configurator = self._makeOne().__of__( site )
+
+ self._compareDOM( configurator.generateXML(), _EMPTY_TOOLSET_XML )
+
+ def test_generateXML_normal( self ):
+
+ site = self._initSite()
+ configurator = self._makeOne().__of__( site )
+
+ configurator.addForbiddenTool( 'doomed' )
+ configurator.addRequiredTool( 'mandatory', 'path.to.one' )
+ configurator.addRequiredTool( 'obligatory', 'path.to.another' )
+
+ configurator.parseXML( _NORMAL_TOOLSET_XML )
+
+ def test_parseXML_empty( self ):
+
+ site = self._initSite()
+ configurator = self._makeOne().__of__( site )
+
+ configurator.parseXML( _EMPTY_TOOLSET_XML )
+
+ self.assertEqual( len( configurator.listForbiddenTools() ), 0 )
+ self.assertEqual( len( configurator.listRequiredTools() ), 0 )
+
+ def test_parseXML_normal( self ):
+
+ site = self._initSite()
+ configurator = self._makeOne().__of__( site )
+
+ configurator.parseXML( _NORMAL_TOOLSET_XML )
+
+ self.assertEqual( len( configurator.listForbiddenTools() ), 1 )
+ self.failUnless( 'doomed' in configurator.listForbiddenTools() )
+
+ self.assertEqual( len( configurator.listRequiredTools() ), 2 )
+
+ self.failUnless( 'mandatory' in configurator.listRequiredTools() )
+ info = configurator.getRequiredToolInfo( 'mandatory' )
+ self.assertEqual( info[ 'class' ], 'path.to.one' )
+
+ self.failUnless( 'obligatory' in configurator.listRequiredTools() )
+ info = configurator.getRequiredToolInfo( 'obligatory' )
+ self.assertEqual( info[ 'class' ], 'path.to.another' )
+
+ def test_parseXML_confused( self ):
+
+ site = self._initSite()
+ configurator = self._makeOne().__of__( site )
+
+ self.assertRaises( ValueError
+ , configurator.parseXML, _CONFUSED_TOOLSET_XML )
+
+
+_EMPTY_TOOLSET_XML = """\
+<?xml version="1.0"?>
+<tool-setup>
+</tool-setup>
+"""
+
+_NORMAL_TOOLSET_XML = """\
+<?xml version="1.0"?>
+<tool-setup>
+ <forbidden tool_id="doomed" />
+ <required tool_id="mandatory" class="path.to.one" />
+ <required tool_id="obligatory" class="path.to.another" />
+</tool-setup>
+"""
+
+_CONFUSED_TOOLSET_XML = """\
+<?xml version="1.0"?>
+<tool-setup>
+ <forbidden tool_id="confused" />
+ <required tool_id="confused" class="path.to.one" />
+</tool-setup>
+"""
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite( ImportStepRegistryTests ),
unittest.makeSuite( ExportStepRegistryTests ),
+ unittest.makeSuite( ToolsetRegistryTests ),
))
if __name__ == '__main__':
=== CMF/CMFSetup/tests/test_tool.py 1.10 => 1.11 ===
--- CMF/CMFSetup/tests/test_tool.py:1.10 Tue May 25 09:18:22 2004
+++ CMF/CMFSetup/tests/test_tool.py Wed Jun 30 14:13:00 2004
@@ -7,8 +7,16 @@
import os
from StringIO import StringIO
+from Acquisition import aq_base
+from OFS.Folder import Folder
+
+from common import SecurityRequestTest
+
from common import FilesystemTestBase
from common import TarballTester
+from common import DOMComparator
+from common import DummyExportContext
+from common import DummyImportContext
from conformance import ConformsToISetupTool
class SetupToolTests( FilesystemTestBase
@@ -29,8 +37,6 @@
def _makeSite( self, title="Don't care" ):
- from OFS.Folder import Folder
-
site = Folder()
site._setId( 'site' )
site.title = title
@@ -53,24 +59,37 @@
self.assertEqual( len( export_steps ), 1 )
self.assertEqual( export_steps[ 0 ], 'step_registries' )
+ toolset_registry = tool.getToolsetRegistry()
+ self.assertEqual( len( toolset_registry.listForbiddenTools() ), 0 )
+ self.assertEqual( len( toolset_registry.listRequiredTools() ), 0 )
+
def test_getProfileDirectory_relative_no_product( self ):
+ from Products.CMFSetup.tool import IMPORT_STEPS_XML
+ from Products.CMFSetup.tool import EXPORT_STEPS_XML
+ from Products.CMFSetup.tool import TOOLSET_XML
from test_registry import _EMPTY_IMPORT_XML
from test_registry import _EMPTY_EXPORT_XML
+ from test_registry import _EMPTY_TOOLSET_XML
from common import _makeTestFile
tool = self._makeOne()
- _makeTestFile( tool.IMPORT_STEPS_XML
+ _makeTestFile( IMPORT_STEPS_XML
, self._PROFILE_PATH
, _EMPTY_IMPORT_XML
)
- _makeTestFile( tool.EXPORT_STEPS_XML
+ _makeTestFile( EXPORT_STEPS_XML
, self._PROFILE_PATH
, _EMPTY_EXPORT_XML
)
+ _makeTestFile( TOOLSET_XML
+ , self._PROFILE_PATH
+ , _EMPTY_TOOLSET_XML
+ )
+
tool.setProfileDirectory( self._PROFILE_PATH )
self.assertEqual( tool.getProfileDirectory( True ), self._PROFILE_PATH )
@@ -86,23 +105,32 @@
def test_setProfileDirectory_absolute( self ):
+ from Products.CMFSetup.tool import IMPORT_STEPS_XML
+ from Products.CMFSetup.tool import EXPORT_STEPS_XML
+ from Products.CMFSetup.tool import TOOLSET_XML
from test_registry import _SINGLE_IMPORT_XML
from test_registry import _SINGLE_EXPORT_XML
+ from test_registry import _NORMAL_TOOLSET_XML
from test_registry import ONE_FUNC
from common import _makeTestFile
tool = self._makeOne()
- _makeTestFile( tool.IMPORT_STEPS_XML
+ _makeTestFile( IMPORT_STEPS_XML
, self._PROFILE_PATH
, _SINGLE_IMPORT_XML
)
- _makeTestFile( tool.EXPORT_STEPS_XML
+ _makeTestFile( EXPORT_STEPS_XML
, self._PROFILE_PATH
, _SINGLE_EXPORT_XML
)
+ _makeTestFile( TOOLSET_XML
+ , self._PROFILE_PATH
+ , _NORMAL_TOOLSET_XML
+ )
+
tool.setProfileDirectory( self._PROFILE_PATH )
self.assertEqual( tool.getProfileProduct(), None )
@@ -133,6 +161,17 @@
self.assertEqual( export_registry.getStep( 'one' ), ONE_FUNC )
+ toolset = tool.getToolsetRegistry()
+ self.assertEqual( len( toolset.listForbiddenTools() ), 1 )
+ self.failUnless( 'doomed' in toolset.listForbiddenTools() )
+ self.assertEqual( len( toolset.listRequiredTools() ), 2 )
+ self.failUnless( 'mandatory' in toolset.listRequiredTools() )
+ info = toolset.getRequiredToolInfo( 'mandatory' )
+ self.assertEqual( info[ 'class' ], 'path.to.one' )
+ self.failUnless( 'obligatory' in toolset.listRequiredTools() )
+ info = toolset.getRequiredToolInfo( 'obligatory' )
+ self.assertEqual( info[ 'class' ], 'path.to.another' )
+
def test_setProfileDirectory_relative_invalid( self ):
_PATH = 'tests/nonesuch'
@@ -184,6 +223,17 @@
, 'Products.CMFSetup.tests.common.dummy_handler' )
self.assertEqual( export_registry.getStep( 'one' ), dummy_handler )
+ toolset = tool.getToolsetRegistry()
+ self.assertEqual( len( toolset.listForbiddenTools() ), 1 )
+ self.failUnless( 'doomed' in toolset.listForbiddenTools() )
+ self.assertEqual( len( toolset.listRequiredTools() ), 2 )
+ self.failUnless( 'mandatory' in toolset.listRequiredTools() )
+ info = toolset.getRequiredToolInfo( 'mandatory' )
+ self.assertEqual( info[ 'class' ], 'path.to.one' )
+ self.failUnless( 'obligatory' in toolset.listRequiredTools() )
+ info = toolset.getRequiredToolInfo( 'obligatory' )
+ self.assertEqual( info[ 'class' ], 'path.to.another' )
+
def test_setProfileDirectory_relative_encode_as_ascii( self ):
import Products.CMFSetup
@@ -206,6 +256,17 @@
self.failUnless( 'one' in import_registry.listSteps() )
self.assertEqual( export_registry.getStep( 'one' ), dummy_handler )
+ toolset = tool.getToolsetRegistry()
+ self.assertEqual( len( toolset.listForbiddenTools() ), 1 )
+ self.failUnless( 'doomed' in toolset.listForbiddenTools() )
+ self.assertEqual( len( toolset.listRequiredTools() ), 2 )
+ self.failUnless( 'mandatory' in toolset.listRequiredTools() )
+ info = toolset.getRequiredToolInfo( 'mandatory' )
+ self.assertEqual( info[ 'class' ], 'path.to.one' )
+ self.failUnless( 'obligatory' in toolset.listRequiredTools() )
+ info = toolset.getRequiredToolInfo( 'obligatory' )
+ self.assertEqual( info[ 'class' ], 'path.to.another' )
+
def test_setProfileDirectory_relative_invalid_product( self ):
_PATH = 'tests/default_profile'
@@ -674,9 +735,206 @@
return 'Exported properties'
+class _ToolsetSetup( SecurityRequestTest ):
+
+ def _initSite( self ):
+
+ from Products.CMFSetup.tool import SetupTool
+ site = Folder()
+ site._setId( 'site' )
+ self.root._setObject( 'site', site )
+ site = self.root._getOb( 'site' )
+ site._setObject( 'portal_setup', SetupTool() )
+ return site
+
+class Test_exportToolset( _ToolsetSetup
+ , DOMComparator
+ ):
+
+ def test_empty( self ):
+
+ from Products.CMFSetup.tool import TOOLSET_XML
+ from Products.CMFSetup.tool import exportToolset
+
+ site = self._initSite()
+ context = DummyExportContext( site )
+
+ exportToolset( context )
+
+ self.assertEqual( len( context._wrote ), 1 )
+ filename, text, content_type = context._wrote[ 0 ]
+ self.assertEqual( filename, TOOLSET_XML )
+ self._compareDOM( text, _EMPTY_TOOLSET_XML )
+ self.assertEqual( content_type, 'text/xml' )
+
+ def test_normal( self ):
+
+ from Products.CMFSetup.tool import TOOLSET_XML
+ from Products.CMFSetup.tool import exportToolset
+
+ site = self._initSite()
+ toolset = site.portal_setup.getToolsetRegistry()
+ toolset.addForbiddenTool( 'doomed' )
+ toolset.addRequiredTool( 'mandatory', 'path.to.one' )
+ toolset.addRequiredTool( 'obligatory', 'path.to.another' )
+
+ context = DummyExportContext( site )
+
+ exportToolset( context )
+
+ self.assertEqual( len( context._wrote ), 1 )
+ filename, text, content_type = context._wrote[ 0 ]
+ self.assertEqual( filename, TOOLSET_XML )
+ self._compareDOM( text, _EMPTY_TOOLSET_XML )
+ self.assertEqual( content_type, 'text/xml' )
+
+class Test_importToolset( _ToolsetSetup ):
+
+ def test_forbidden_tools( self ):
+
+ from Products.CMFSetup.tool import TOOLSET_XML
+ from Products.CMFSetup.tool import importToolset
+ TOOL_IDS = ( 'doomed', 'blasted', 'saved' )
+
+ site = self._initSite()
+
+ for tool_id in TOOL_IDS:
+ pseudo = Folder()
+ pseudo._setId( tool_id )
+ site._setObject( tool_id, pseudo )
+
+ self.assertEqual( len( site.objectIds() ), len( TOOL_IDS ) + 1 )
+
+ for tool_id in TOOL_IDS:
+ self.failUnless( tool_id in site.objectIds() )
+
+ context = DummyImportContext( site )
+ context._files[ TOOLSET_XML ] = _FORBIDDEN_TOOLSET_XML
+
+ importToolset( context )
+
+ self.assertEqual( len( site.objectIds() ), 2 )
+ self.failUnless( 'portal_setup' in site.objectIds() )
+ self.failUnless( 'saved' in site.objectIds() )
+
+ def test_required_tools_missing( self ):
+
+ from Products.CMFSetup.tool import TOOLSET_XML
+ from Products.CMFSetup.tool import importToolset
+
+ site = self._initSite()
+ self.assertEqual( len( site.objectIds() ), 1 )
+
+ context = DummyImportContext( site )
+ context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML
+
+ importToolset( context )
+
+ self.assertEqual( len( site.objectIds() ), 3 )
+ self.failUnless( isinstance( aq_base( site._getOb( 'mandatory' ) )
+ , DummyTool ) )
+ self.failUnless( isinstance( aq_base( site._getOb( 'obligatory' ) )
+ , DummyTool ) )
+
+ def test_required_tools_no_replacement( self ):
+
+ from Products.CMFSetup.tool import TOOLSET_XML
+ from Products.CMFSetup.tool import importToolset
+
+ site = self._initSite()
+
+ mandatory = DummyTool()
+ mandatory._setId( 'mandatory' )
+ site._setObject( 'mandatory', mandatory )
+
+ obligatory = DummyTool()
+ obligatory._setId( 'obligatory' )
+ site._setObject( 'obligatory', obligatory )
+
+ self.assertEqual( len( site.objectIds() ), 3 )
+
+ context = DummyImportContext( site )
+ context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML
+
+ importToolset( context )
+
+ self.assertEqual( len( site.objectIds() ), 3 )
+ self.failUnless( aq_base( site._getOb( 'mandatory' ) ) is mandatory )
+ self.failUnless( aq_base( site._getOb( 'obligatory' ) ) is obligatory )
+
+ def test_required_tools_with_replacement( self ):
+
+ from Products.CMFSetup.tool import TOOLSET_XML
+ from Products.CMFSetup.tool import importToolset
+
+ site = self._initSite()
+
+ mandatory = AnotherDummyTool()
+ mandatory._setId( 'mandatory' )
+ site._setObject( 'mandatory', mandatory )
+
+ obligatory = AnotherDummyTool()
+ obligatory._setId( 'obligatory' )
+ site._setObject( 'obligatory', obligatory )
+
+ self.assertEqual( len( site.objectIds() ), 3 )
+
+ context = DummyImportContext( site )
+ context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML
+
+ importToolset( context )
+
+ self.assertEqual( len( site.objectIds() ), 3 )
+
+ self.failIf( aq_base( site._getOb( 'mandatory' ) ) is mandatory )
+ self.failUnless( isinstance( aq_base( site._getOb( 'mandatory' ) )
+ , DummyTool ) )
+
+ self.failIf( aq_base( site._getOb( 'obligatory' ) ) is obligatory )
+ self.failUnless( isinstance( aq_base( site._getOb( 'obligatory' ) )
+ , DummyTool ) )
+
+
+class DummyTool( Folder ):
+
+ pass
+
+class AnotherDummyTool( Folder ):
+
+ pass
+
+_EMPTY_TOOLSET_XML = """\
+<?xml version="1.0"?>
+<tool-setup>
+</tool-setup>
+"""
+
+_FORBIDDEN_TOOLSET_XML = """\
+<?xml version="1.0"?>
+<tool-setup>
+ <forbidden tool_id="doomed" />
+ <forbidden tool_id="damned" />
+ <forbidden tool_id="blasted" />
+</tool-setup>
+"""
+
+_REQUIRED_TOOLSET_XML = """\
+<?xml version="1.0"?>
+<tool-setup>
+ <required
+ tool_id="mandatory"
+ class="Products.CMFSetup.tests.test_tool.DummyTool" />
+ <required
+ tool_id="obligatory"
+ class="Products.CMFSetup.tests.test_tool.DummyTool" />
+</tool-setup>
+"""
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite( SetupToolTests ),
+ unittest.makeSuite( Test_exportToolset ),
+ unittest.makeSuite( Test_importToolset ),
))
if __name__ == '__main__':
=== Removed File CMF/CMFSetup/tests/test_toolset.py ===
More information about the CMF-checkins
mailing list