[CMF-checkins] SVN: CMF/trunk/CMFSetup/t - Ensure that tools
without a "fixed" ID get an ID set during import
Jens Vagelpohl
jens at dataflake.org
Fri Sep 23 05:53:18 EDT 2005
Log message for revision 38569:
- Ensure that tools without a "fixed" ID get an ID set during import
Changed:
U CMF/trunk/CMFSetup/tests/test_tool.py
U CMF/trunk/CMFSetup/tool.py
-=-
Modified: CMF/trunk/CMFSetup/tests/test_tool.py
===================================================================
--- CMF/trunk/CMFSetup/tests/test_tool.py 2005-09-23 09:52:42 UTC (rev 38568)
+++ CMF/trunk/CMFSetup/tests/test_tool.py 2005-09-23 09:53:17 UTC (rev 38569)
@@ -727,6 +727,24 @@
class Test_importToolset( _ToolsetSetup ):
+ def test_tool_ids( self ):
+ # The tool import mechanism used to rely on the fact that all tools
+ # have unique IDs set at the class level and that you can call their
+ # constructor with no arguments. However, there might be tools
+ # that need IDs set.
+ from Products.CMFSetup.tool import TOOLSET_XML
+ from Products.CMFSetup.tool import importToolset
+
+ site = self._initSite()
+ context = DummyImportContext( site )
+ context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML
+
+ importToolset( context )
+
+ for tool_id in ( 'mandatory', 'obligatory' ):
+ tool = getattr( site, tool_id )
+ self.assertEqual( tool.getId(), tool_id )
+
def test_forbidden_tools( self ):
from Products.CMFSetup.tool import TOOLSET_XML
@@ -840,6 +858,7 @@
pass
+
_EMPTY_TOOLSET_XML = """\
<?xml version="1.0"?>
<tool-setup>
Modified: CMF/trunk/CMFSetup/tool.py
===================================================================
--- CMF/trunk/CMFSetup/tool.py 2005-09-23 09:52:42 UTC (rev 38568)
+++ CMF/trunk/CMFSetup/tool.py 2005-09-23 09:53:17 UTC (rev 38569)
@@ -26,6 +26,7 @@
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.CMFCore.utils import UniqueObject
+from Products.CMFCore.utils import ImmutableId
from Products.CMFCore.utils import getToolByName
from interfaces import EXTENSION
@@ -93,15 +94,19 @@
tool_class = _resolveDottedName( info[ 'class' ] )
existing = getToolByName( site, tool_id, None )
+ new_tool = tool_class()
+ if not isinstance( new_tool, ImmutableId ):
+ new_tool._setId( tool_id )
+
if existing is None:
- site._setObject( tool_id, tool_class() )
+ site._setObject( tool_id, new_tool )
else:
unwrapped = aq_base( existing )
if not isinstance( unwrapped, tool_class ):
site._delObject( tool_id )
- site._setObject( tool_id, tool_class() )
+ site._setObject( tool_id, new_tool )
return 'Toolset imported.'
More information about the CMF-checkins
mailing list