[CMF-checkins] SVN: CMF/branches/1.5/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:52:43 EDT 2005


Log message for revision 38568:
  - Ensure that tools without a "fixed" ID get an ID set during import
  

Changed:
  U   CMF/branches/1.5/CMFSetup/tests/test_tool.py
  U   CMF/branches/1.5/CMFSetup/tool.py

-=-
Modified: CMF/branches/1.5/CMFSetup/tests/test_tool.py
===================================================================
--- CMF/branches/1.5/CMFSetup/tests/test_tool.py	2005-09-23 08:55:09 UTC (rev 38567)
+++ CMF/branches/1.5/CMFSetup/tests/test_tool.py	2005-09-23 09:52:42 UTC (rev 38568)
@@ -730,6 +730,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
@@ -843,6 +861,7 @@
 
     pass
 
+
 _EMPTY_TOOLSET_XML = """\
 <?xml version="1.0"?>
 <tool-setup>

Modified: CMF/branches/1.5/CMFSetup/tool.py
===================================================================
--- CMF/branches/1.5/CMFSetup/tool.py	2005-09-23 08:55:09 UTC (rev 38567)
+++ CMF/branches/1.5/CMFSetup/tool.py	2005-09-23 09:52:42 UTC (rev 38568)
@@ -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