[CMF-checkins] CVS: CMF/CMFSetup/tests - test_typeinfo.py:1.10.2.3 test_utils.py:1.4.2.3

Florent Guillaume fg at nuxeo.com
Fri Jul 1 09:28:16 EDT 2005


Update of /cvs-repository/CMF/CMFSetup/tests
In directory cvs.zope.org:/tmp/cvs-serv32673/CMFSetup/tests

Modified Files:
      Tag: CMF-1_5-branch
	test_typeinfo.py test_utils.py 
Log Message:
Merge from HEAD:

Use a new XML format for import/export of types, where the properties
are generic. Now arbitrary TypeInformation objects can be used, as long
as they are configured using properties.

Split ConfiguratorBase into ImportConfiguratorBase and
ExportConfiguratorBase, as they really are unrelated.
Split typeinfo configurators and tests into Import and Export version.



=== CMF/CMFSetup/tests/test_typeinfo.py 1.10.2.2 => 1.10.2.3 ===
--- CMF/CMFSetup/tests/test_typeinfo.py:1.10.2.2	Wed Apr 13 09:05:02 2005
+++ CMF/CMFSetup/tests/test_typeinfo.py	Fri Jul  1 09:27:45 2005
@@ -39,393 +39,396 @@
     pass
 
 
-class DummyTypesTool( Folder ):
+class DummyTypesTool(Folder):
 
-    def __init__( self, type_infos ):
+    def __init__(self, type_infos):
 
         self._type_infos = type_infos
+        for id, obj in [(x['id'], DummyTypeInfo(x))
+                        for x in type_infos]:
+            self._setObject(id, obj)
 
-        for id, obj in [ ( x[ 'id' ], DummyTypeInfo( x ) )
-                            for x in type_infos ]:
-            self._setObject( id, obj )
+    def listContentTypes(self):
 
-    def listContentTypes( self ):
+        return [x['id'] for x in self._type_infos]
 
-        return [ x[ 'id' ] for x in self._type_infos ]
+    def getTypeInfo(self, id):
 
-    def getTypeInfo( self, id ):
-
-        info = [ x for x in self._type_infos if x[ 'id' ] == id ]
-
-        if len( info ) == 0:
+        info = [x for x in self._type_infos if x['id'] == id]
+        if len(info) == 0:
             raise KeyError, id
-
-        info = info[ 0 ]
+        info = info[0]
 
         if 'product' in info.keys():
-            return FactoryTypeInformation( **info )
+            return FactoryTypeInformation(**info)
         else:
-            return ScriptableTypeInformation( **info )
-
-class _TypeInfoSetup( BaseRegistryTests ):
+            return ScriptableTypeInformation(**info)
 
-    def _initSite( self, type_infos=() ):
+class _TypeInfoSetup(BaseRegistryTests):
 
-        self.root.site = Folder( id='site' )
-
-        self.root.site.portal_types = DummyTypesTool( type_infos )
+    def _initSite(self, type_infos=()):
 
+        self.root.site = Folder(id='site')
+        self.root.site.portal_types = DummyTypesTool(type_infos)
         return self.root.site
 
-class TypesToolConfiguratorTests( _TypeInfoSetup ):
 
-    def _getTargetClass( self ):
+class TypesToolExportConfiguratorTests(_TypeInfoSetup):
+
+    def _getTargetClass(self):
 
-        from Products.CMFSetup.typeinfo import TypesToolConfigurator
-        return TypesToolConfigurator
+        from Products.CMFSetup.typeinfo import TypesToolExportConfigurator
+        return TypesToolExportConfigurator
 
-    def test_listTypeInfo_empty( self ):
+    def test_listTypeInfo_empty(self):
 
         site = self._initSite()
-        configurator = self._makeOne( site ).__of__( site )
+        configurator = self._makeOne(site).__of__(site)
 
-        self.assertEqual( len( configurator.listTypeInfo() ), 0 )
+        self.assertEqual(len(configurator.listTypeInfo()), 0)
 
-    def test_listTypeInfo_filled ( self ):
+    def test_listTypeInfo_filled (self):
 
-        site = self._initSite( _TI_LIST )
-        configurator = self._makeOne( site ).__of__( site )
+        site = self._initSite(_TI_LIST)
+        configurator = self._makeOne(site).__of__(site)
 
-        self.assertEqual( len( configurator.listTypeInfo() ), len( _TI_LIST ) )
+        self.assertEqual(len(configurator.listTypeInfo()), len(_TI_LIST))
 
         info_list = configurator.listTypeInfo()
-        self.assertEqual( len( info_list ), len( _TI_LIST ) )
+        self.assertEqual(len(info_list), len(_TI_LIST))
 
         _marker = object()
 
-        for i in range( len( _TI_LIST ) ):
-            found = info_list[ i ]
-            expected = _TI_LIST[ i ]
-            self.assertEqual( found[ 'id' ], expected[ 'id' ] )
-            self.failUnless( found.get( 'filename', _marker ) is _marker )
+        for i in range(len(_TI_LIST)):
+            found = info_list[i]
+            expected = _TI_LIST[i]
+            self.assertEqual(found['id'], expected['id'])
+            self.failUnless(found.get('filename', _marker) is _marker)
 
-    def test_listTypeInfo_with_filename ( self ):
+    def test_listTypeInfo_with_filename (self):
 
-        site = self._initSite( _TI_LIST_WITH_FILENAME )
-        configurator = self._makeOne( site ).__of__( site )
+        site = self._initSite(_TI_LIST_WITH_FILENAME)
+        configurator = self._makeOne(site).__of__(site)
 
         info_list = configurator.listTypeInfo()
-        self.assertEqual( len( info_list ), len( _TI_LIST_WITH_FILENAME ) )
+        self.assertEqual(len(info_list), len(_TI_LIST_WITH_FILENAME))
+
+        for i in range(len(_TI_LIST_WITH_FILENAME)):
+            found = info_list[i]
+            expected = _TI_LIST_WITH_FILENAME[i]
+            self.assertEqual(found['id'], expected['id'])
+            self.assertEqual(found['filename'],
+                             'types/%s.xml'
+                             % expected['id'].replace(' ', '_')
+                             )
+
+    def test_generateXML_empty(self):
+
+        site = self._initSite()
+        configurator = self._makeOne(site).__of__(site)
+        self._compareDOM(configurator.generateXML(), _EMPTY_TOOL_EXPORT)
+
+    def test_generateXML_normal(self):
+
+        site = self._initSite(_TI_LIST)
+        configurator = self._makeOne(site).__of__(site)
+        self._compareDOM(configurator.generateXML(), _NORMAL_TOOL_EXPORT)
+
+    def test_generateXML_explicit_filename(self):
+
+        site = self._initSite(_TI_LIST_WITH_FILENAME)
+        configurator = self._makeOne(site).__of__(site)
+        self._compareDOM(configurator.generateXML(), _FILENAME_EXPORT)
+
+
+class TypesToolImportConfiguratorTests(_TypeInfoSetup):
+
+    def _getTargetClass(self):
+
+        from Products.CMFSetup.typeinfo import TypesToolImportConfigurator
+        return TypesToolImportConfigurator
+
+    def test_parseXML_empty(self):
+
+        site = self._initSite()
+        configurator = self._makeOne(site).__of__(site)
+
+        tool_info = configurator.parseXML(_EMPTY_TOOL_EXPORT)
+        self.assertEqual(len(tool_info['types']), 0)
+
+    def test_parseXML_normal(self):
+
+        site = self._initSite()
+        configurator = self._makeOne(site).__of__(site)
+
+        tool_info = configurator.parseXML(_NORMAL_TOOL_EXPORT)
+        self.assertEqual(len(tool_info['types']), 2)
+
+        type_info = tool_info['types'][0]
+        self.assertEqual(type_info['id'], 'foo')
+        self.assertEqual(type_info['filename'], 'types/foo.xml')
+        type_info = tool_info['types'][1]
+        self.assertEqual(type_info['id'], 'bar')
+        self.assertEqual(type_info['filename'], 'types/bar.xml')
+
+    def test_parseXML_with_filename(self):
+
+        site = self._initSite()
+        configurator = self._makeOne(site).__of__(site)
+
+        tool_info = configurator.parseXML(_FILENAME_EXPORT)
+        self.assertEqual(len(tool_info['types']), 2)
+
+        type_info = tool_info['types'][0]
+        self.assertEqual(type_info['id'], 'foo object')
+        self.assertEqual(type_info['filename'], 'types/foo_object.xml')
+        type_info = tool_info['types'][1]
+        self.assertEqual(type_info['id'], 'bar object')
+        self.assertEqual(type_info['filename'], 'types/bar_object.xml')
+
+
+class TypeInfoExportConfiguratorTests(_TypeInfoSetup):
+
+    def _getTargetClass(self):
+
+        from Products.CMFSetup.typeinfo import TypeInfoExportConfigurator
+        return TypeInfoExportConfigurator
+
+    def test_getTypeInfo_nonesuch(self):
+
+        site = self._initSite(_TI_LIST)
+        configurator = self._makeOne(site).__of__(site)
+
+        self.assertRaises(ValueError, configurator.getTypeInfo, 'qux')
+
+    def test_getTypeInfo_FTI(self):
+
+        site = self._initSite(_TI_LIST)
+        configurator = self._makeOne(site).__of__(site)
+        found = configurator.getTypeInfo('foo')
+        expected = _TI_LIST[0]
+
+        self.assertEqual(found['kind'], 'Factory-based Type Information')
+
+        for key in ('id', 'aliases'):
+            self.assertEqual(found[key], expected[key])
+
+        self.assertEqual(len(found['actions']), len(expected['actions']))
+
+        for i in range(len(expected['actions'])):
+
+            a_expected = expected['actions'][i]
+            a_found = found['actions'][i]
+
+            for k in ('id', 'action', 'permissions'):
+                self.assertEqual(a_expected[k], a_found[k])
+
+            for lk, rk in (('name', 'title'),):
+                self.assertEqual(a_expected[lk], a_found[rk])
+
+    def test_getTypeInfo_STI(self):
+
+        site = self._initSite(_TI_LIST)
+        configurator = self._makeOne(site).__of__(site)
+        found = configurator.getTypeInfo('bar')
+        expected = _TI_LIST[1]
+
+        self.assertEqual(found['kind'], 'Scriptable Type Information')
 
-        for i in range( len( _TI_LIST_WITH_FILENAME ) ):
-            found = info_list[ i ]
-            expected = _TI_LIST_WITH_FILENAME[ i ]
-            self.assertEqual( found[ 'id' ], expected[ 'id' ] )
-            self.assertEqual( found[ 'filename' ]
-                            , 'types/%s.xml'
-                                % expected[ 'id' ].replace( ' ', '_' )
-                            )
-
-    def test_generateXML_empty( self ):
-
-        site = self._initSite()
-        configurator = self._makeOne( site ).__of__( site )
-        self._compareDOM( configurator.generateXML(), _EMPTY_TOOL_EXPORT )
-
-    def test_generateXML_normal( self ):
-
-        site = self._initSite( _TI_LIST )
-        configurator = self._makeOne( site ).__of__( site )
-        self._compareDOM( configurator.generateXML(), _NORMAL_TOOL_EXPORT )
-
-    def test_generateXML_explicit_filename( self ):
-
-        site = self._initSite( _TI_LIST_WITH_FILENAME )
-        configurator = self._makeOne( site ).__of__( site )
-        self._compareDOM( configurator.generateXML(), _FILENAME_EXPORT )
-
-    def test_parseXML_empty( self ):
-
-        site = self._initSite()
-        configurator = self._makeOne( site ).__of__( site )
-
-        tool_info = configurator.parseXML( _EMPTY_TOOL_EXPORT )
-        self.assertEqual( len( tool_info[ 'types' ] ), 0 )
-
-    def test_parseXML_normal( self ):
-
-        site = self._initSite()
-        configurator = self._makeOne( site ).__of__( site )
-
-        tool_info = configurator.parseXML( _NORMAL_TOOL_EXPORT )
-        self.assertEqual( len( tool_info[ 'types' ] ), 2 )
-
-        type_info = tool_info[ 'types' ][ 0 ]
-        self.assertEqual( type_info[ 'id' ], 'foo' )
-        self.assertEqual( type_info[ 'filename' ], 'types/foo.xml' )
-        type_info = tool_info[ 'types' ][ 1 ]
-        self.assertEqual( type_info[ 'id' ], 'bar' )
-        self.assertEqual( type_info[ 'filename' ], 'types/bar.xml' )
-
-    def test_parseXML_with_filename( self ):
-
-        site = self._initSite()
-        configurator = self._makeOne( site ).__of__( site )
-
-        tool_info = configurator.parseXML( _FILENAME_EXPORT )
-        self.assertEqual( len( tool_info[ 'types' ] ), 2 )
-
-        type_info = tool_info[ 'types' ][ 0 ]
-        self.assertEqual( type_info[ 'id' ], 'foo object' )
-        self.assertEqual( type_info[ 'filename' ], 'types/foo_object.xml' )
-        type_info = tool_info[ 'types' ][ 1 ]
-        self.assertEqual( type_info[ 'id' ], 'bar object' )
-        self.assertEqual( type_info[ 'filename' ], 'types/bar_object.xml' )
-
-
-class TypeInfoConfiguratorTests( _TypeInfoSetup ):
-
-    def _getTargetClass( self ):
-
-        from Products.CMFSetup.typeinfo import TypeInfoConfigurator
-        return TypeInfoConfigurator
-
-    def test_getTypeInfo_nonesuch( self ):
-
-        site = self._initSite( _TI_LIST )
-        configurator = self._makeOne( site ).__of__( site )
-
-        self.assertRaises( ValueError, configurator.getTypeInfo, 'qux' )
-
-    def test_getTypeInfo_FTI( self ):
-
-        site = self._initSite( _TI_LIST )
-        configurator = self._makeOne( site ).__of__( site )
-        found = configurator.getTypeInfo( 'foo' )
-        expected = _TI_LIST[ 0 ]
-
-        for key in ( 'id'
-                   , 'title'
-                   , 'description'
-                   , 'factory'
-                   , 'product'
-                   , 'factory'
-                   , 'immediate_view'
-                   , 'filter_content_types'
-                   , 'allowed_content_types'
-                   , 'allow_discussion'
-                   , 'global_allow'
-                   , 'aliases'
-                   ):
-            self.assertEqual( found[ key ], expected[ key ] )
-
-        for lkey, rkey in ( ( 'meta_type', 'content_meta_type' )
-                          , ( 'icon', 'content_icon' )
-                          ):
-            self.assertEqual( found[ lkey ], expected[ rkey ] )
-
-        self.assertEqual( len( found[ 'actions' ] )
-                        , len( expected[ 'actions' ] )
-                        )
-
-        for i in range( len( expected[ 'actions' ] ) ):
-
-            a_expected = expected[ 'actions' ][ i ]
-            a_found = found[ 'actions' ][ i ]
-
-            for k in ( 'id'
-                     , 'action'
-                     , 'permissions'
-                     ):
-                self.assertEqual( a_expected[ k ], a_found[ k ] )
-
-            for lk, rk in ( ( 'name', 'title' )
-                          ,
-                          ):
-                self.assertEqual( a_expected[ lk ], a_found[ rk ] )
-
-    def test_getTypeInfo_STI( self ):
-
-        site = self._initSite( _TI_LIST )
-        configurator = self._makeOne( site ).__of__( site )
-        found = configurator.getTypeInfo( 'bar' )
-        expected = _TI_LIST[ 1 ]
-
-        for key in ( 'id'
-                   , 'title'
-                   , 'description'
-                   , 'constructor_path'
-                   , 'permission'
-                   , 'immediate_view'
-                   , 'filter_content_types'
-                   , 'allowed_content_types'
-                   , 'allow_discussion'
-                   , 'global_allow'
-                   , 'aliases'
-                   ):
-            self.assertEqual( found[ key ], expected[ key ] )
-
-        for lkey, rkey in ( ( 'meta_type', 'content_meta_type' )
-                          , ( 'icon', 'content_icon' )
-                          ):
-            self.assertEqual( found[ lkey ], expected[ rkey ] )
-
-        self.assertEqual( len( found[ 'actions' ] )
-                        , len( expected[ 'actions' ] )
-                        )
-
-        for i in range( len( expected[ 'actions' ] ) ):
-
-            a_expected = expected[ 'actions' ][ i ]
-            a_found = found[ 'actions' ][ i ]
-
-            for k in ( 'id'
-                     , 'action'
-                     , 'permissions'
-                     ):
-                self.assertEqual( a_expected[ k ], a_found[ k ] )
-
-            for lk, rk in ( ( 'name', 'title' )
-                          ,
-                          ):
-                self.assertEqual( a_expected[ lk ], a_found[ rk ] )
-
-    def test_generateXML_FTI( self ):
-
-        site = self._initSite( _TI_LIST )
-        configurator = self._makeOne( site ).__of__( site )
-        self._compareDOM( configurator.generateXML( type_id='foo' )
-                        , _FOO_EXPORT % 'foo' )
-
-    def test_generateXML_STI( self ):
-
-        site = self._initSite( _TI_LIST )
-        configurator = self._makeOne( site ).__of__( site )
-        self._compareDOM( configurator.generateXML( type_id='bar' )
-                        , _BAR_EXPORT % 'bar' )
-
-    def test_parseXML_FTI( self ):
-
-        site = self._initSite()
-        tool = site.portal_types
-        configurator = self._makeOne( site ).__of__( site )
-        self.assertEqual( len( tool.objectIds() ), 0 )
-
-        info = configurator.parseXML( _FOO_EXPORT % 'foo' )
-
-        self.assertEqual( info[ 'id' ], 'foo' )
-        self.assertEqual( info[ 'title' ], 'Foo' )
-        self.assertEqual( len( info[ 'aliases' ] ), 2 )
-
-    def test_parseXML_STI( self ):
-
-        site = self._initSite()
-        tool = site.portal_types
-        configurator = self._makeOne( site ).__of__( site )
-        self.assertEqual( len( tool.objectIds() ), 0 )
-
-        info = configurator.parseXML( _BAR_EXPORT % 'bar' )
-
-        self.assertEqual( info[ 'id' ], 'bar' )
-        self.assertEqual( info[ 'title' ], 'Bar' )
-        self.assertEqual( len( info[ 'aliases' ] ), 2 )
-
-    def test_parseXML_actions( self ):
-
-        site = self._initSite()
-        tool = site.portal_types
-        configurator = self._makeOne( site ).__of__( site )
-
-        info = configurator.parseXML( _FOO_EXPORT % 'foo' )
-
-        action_info_list = info[ 'actions' ]
-        self.assertEqual( len( action_info_list ), 3 )
-
-        action_info = action_info_list[ 0 ]
-        self.assertEqual( action_info[ 'id' ], 'view' )
-        self.assertEqual( action_info[ 'title' ], 'View' )
-        self.assertEqual( action_info[ 'permissions' ], ( 'View', ) )
-
-
-_TI_LIST = ( { 'id'                     : 'foo'
-             , 'title'                  : 'Foo'
-             , 'description'            : 'Foo things'
-             , 'content_meta_type'      : 'Foo Thing'
-             , 'content_icon'           : 'foo.png'
-             , 'product'                : 'CMFSetup'
-             , 'factory'                : 'addFoo'
-             , 'immediate_view'         : 'foo_view'
-             , 'filter_content_types'   : False
-             , 'allowed_content_types'  : ()
-             , 'allow_discussion'       : False
-             , 'global_allow'           : False
-             , 'aliases'                : { '(Default)' : 'foo_view'
-                                          , 'view'      : 'foo_view'
-                                          }
-             , 'actions'        :
-                ( { 'id'            : 'view'
-                  , 'name'          : 'View'
-                  , 'action': 'string:${object_url}/foo_view'
-                  , 'permissions'   : (View,)
-                  }
-                , { 'id'            : 'edit'
-                  , 'name'          : 'Edit'
-                  , 'action': 'string:${object_url}/foo_edit_form'
-                  , 'permissions'   : (ModifyPortalContent,)
-                  }
-                , { 'id'            : 'metadata'
-                  , 'name'          : 'Metadata'
-                  , 'action': 'string:${object_url}/metadata_edit_form'
-                  , 'permissions'   : (ModifyPortalContent,)
-                  }
-                )
-             }
-           , { 'id'                     : 'bar'
-             , 'title'                  : 'Bar'
-             , 'description'            : 'Bar things'
-             , 'content_meta_type'      : 'Bar Thing'
-             , 'content_icon'           : 'bar.png'
-             , 'constructor_path'       : 'make_bar'
-             , 'permission'             : 'Add portal content'
-             , 'immediate_view'         : 'bar_view'
-             , 'filter_content_types'   : True
-             , 'allowed_content_types'  : ( 'foo', )
-             , 'allow_discussion'       : True
-             , 'global_allow'           : True
-             , 'aliases'                : { '(Default)' : 'bar_view'
-                                          , 'view'      : 'bar_view'
-                                          }
-             , 'actions'        :
-                ( { 'id'            : 'view'
-                  , 'name'          : 'View'
-                  , 'action': 'string:${object_url}/bar_view'
-                  , 'permissions'   : (View,)
-                  }
-                , { 'id'            : 'edit'
-                  , 'name'          : 'Edit'
-                  , 'action': 'string:${object_url}/bar_edit_form'
-                  , 'permissions'   : (ModifyPortalContent,)
-                  }
-                , { 'id'            : 'contents'
-                  , 'name'          : 'Contents'
-                  , 'action': 'string:${object_url}/folder_contents'
-                  , 'permissions'   : (AccessContentsInformation,)
-                  }
-                , { 'id'            : 'metadata'
-                  , 'name'          : 'Metadata'
-                  , 'action': 'string:${object_url}/metadata_edit_form'
-                  , 'permissions'   : (ModifyPortalContent,)
-                  }
-                )
-             }
-           )
+        for key in ('id', 'aliases'):
+            self.assertEqual(found[key], expected[key])
+
+        self.assertEqual(len(found['actions']), len(expected['actions']))
+
+        for i in range(len(expected['actions'])):
+
+            a_expected = expected['actions'][i]
+            a_found = found['actions'][i]
+
+            for k in ('id', 'action', 'permissions'):
+                self.assertEqual(a_expected[k], a_found[k])
+
+            for lk, rk in (('name', 'title'),):
+                self.assertEqual(a_expected[lk], a_found[rk])
+
+    def test_generateXML_FTI(self):
+
+        site = self._initSite(_TI_LIST)
+        configurator = self._makeOne(site).__of__(site)
+        self._compareDOM(configurator.generateXML(type_id='foo'),
+                         _FOO_EXPORT % 'foo')
+
+    def test_generateXML_STI(self):
+
+        site = self._initSite(_TI_LIST)
+        configurator = self._makeOne(site).__of__(site)
+        self._compareDOM(configurator.generateXML(type_id='bar'),
+                         _BAR_EXPORT % 'bar')
+
+
+class OldTypeInfoImportConfiguratorTests(_TypeInfoSetup):
+
+    def _getTargetClass(self):
+
+        from Products.CMFSetup.typeinfo import OldTypeInfoImportConfigurator
+        return OldTypeInfoImportConfigurator
+
+    def test_old_parseXML_FTI(self):
+
+        site = self._initSite()
+        tool = site.portal_types
+        configurator = self._makeOne(site).__of__(site)
+        self.assertEqual(len(tool.objectIds()), 0)
+
+        info = configurator.parseXML(_FOO_OLD_EXPORT % 'foo')
+
+        self.assertEqual(info['id'], 'foo')
+        self.assertEqual(info['title'], 'Foo')
+        self.assertEqual(len(info['aliases']), 2)
+
+    def test_old_parseXML_STI(self):
+
+        site = self._initSite()
+        tool = site.portal_types
+        configurator = self._makeOne(site).__of__(site)
+        self.assertEqual(len(tool.objectIds()), 0)
+
+        info = configurator.parseXML(_BAR_OLD_EXPORT % 'bar')
+
+        self.assertEqual(info['id'], 'bar')
+        self.assertEqual(info['title'], 'Bar')
+        self.assertEqual(len(info['aliases']), 2)
+
+
+class TypeInfoImportConfiguratorTests(_TypeInfoSetup):
+
+    def _getTargetClass(self):
+
+        from Products.CMFSetup.typeinfo import TypeInfoImportConfigurator
+        return TypeInfoImportConfigurator
+
+    def test_parseXML_FTI(self):
+
+        site = self._initSite()
+        tool = site.portal_types
+        configurator = self._makeOne(site).__of__(site)
+        self.assertEqual(len(tool.objectIds()), 0)
+
+        info = configurator.parseXML(_FOO_EXPORT % 'foo')
+        props = dict([(e['id'], e) for e in info['properties']])
+
+        self.assertEqual(info['id'], 'foo')
+        self.assertEqual(props['title']['value'], 'Foo')
+        self.assertEqual(len(info['aliases']), 2)
+
+    def test_parseXML_STI(self):
+
+        site = self._initSite()
+        tool = site.portal_types
+        configurator = self._makeOne(site).__of__(site)
+        self.assertEqual(len(tool.objectIds()), 0)
+
+        info = configurator.parseXML(_BAR_EXPORT % 'bar')
+        props = dict([(e['id'], e) for e in info['properties']])
+
+        self.assertEqual(info['id'], 'bar')
+        self.assertEqual(props['title']['value'], 'Bar')
+        self.assertEqual(len(info['aliases']), 2)
+
+    def test_parseXML_actions(self):
+
+        site = self._initSite()
+        tool = site.portal_types
+        configurator = self._makeOne(site).__of__(site)
+
+        info = configurator.parseXML(_FOO_EXPORT % 'foo')
+
+        action_info_list = info['actions']
+        self.assertEqual(len(action_info_list), 3)
+
+        action_info = action_info_list[0]
+        self.assertEqual(action_info['id'], 'view')
+        self.assertEqual(action_info['title'], 'View')
+        self.assertEqual(action_info['permissions'], ('View',))
+
+
+_TI_LIST = ({
+    'id':                    'foo',
+    'title':                 'Foo',
+    'description':           'Foo things',
+    'content_meta_type':     'Foo Thing',
+    'content_icon':          'foo.png',
+    'product':               'CMFSetup',
+    'factory':               'addFoo',
+    'immediate_view':        'foo_view',
+    'filter_content_types':  False,
+    'allowed_content_types': (),
+    'allow_discussion':      False,
+    'global_allow':          False,
+    'aliases': {'(Default)': 'foo_view',
+                'view':      'foo_view',
+                },
+    'actions': ({'id':     'view',
+                 'name':   'View',
+                 'action': 'string:${object_url}/foo_view',
+                 'permissions': (View,),
+                 },
+                {'id':     'edit',
+                 'name':   'Edit',
+                 'action': 'string:${object_url}/foo_edit_form',
+                 'permissions': (ModifyPortalContent,),
+                 },
+                {'id':     'metadata',
+                 'name':   'Metadata',
+                 'action': 'string:${object_url}/metadata_edit_form',
+                 'permissions': (ModifyPortalContent,),
+                 },
+                ),
+    }, {
+    'id':                    'bar',
+    'title':                 'Bar',
+    'description':           'Bar things',
+    'content_meta_type':     'Bar Thing',
+    'content_icon':          'bar.png',
+    'constructor_path':      'make_bar',
+    'permission':            'Add portal content',
+    'immediate_view':        'bar_view',
+    'filter_content_types':  True,
+    'allowed_content_types': ('foo',),
+    'allow_discussion':      True,
+    'global_allow':          True,
+    'aliases': {'(Default)': 'bar_view',
+                'view':      'bar_view',
+                },
+    'actions': ({'id':     'view',
+                 'name':   'View',
+                 'action': 'string:${object_url}/bar_view',
+                 'permissions': (View,),
+                 },
+                {'id':     'edit',
+                 'name':   'Edit',
+                 'action': 'string:${object_url}/bar_edit_form',
+                 'permissions': (ModifyPortalContent,),
+                 },
+                {'id':     'contents',
+                 'name':   'Contents',
+                 'action': 'string:${object_url}/folder_contents',
+                 'permissions': (AccessContentsInformation,),
+                 },
+                {'id':     'metadata',
+                 'name':   'Metadata',
+                 'action': 'string:${object_url}/metadata_edit_form',
+                 'permissions': (ModifyPortalContent,),
+                 },
+               ),
+    })
 
 _TI_LIST_WITH_FILENAME = []
 
 for original in _TI_LIST:
     duplicate = original.copy()
-    duplicate[ 'id' ] = '%s object' % original[ 'id' ]
-    _TI_LIST_WITH_FILENAME.append( duplicate )
+    duplicate['id'] = '%s object' % original['id']
+    _TI_LIST_WITH_FILENAME.append(duplicate)
 
 _EMPTY_TOOL_EXPORT = """\
 <?xml version="1.0"?>
@@ -456,7 +459,7 @@
 </types-tool>
 """
 
-_FOO_EXPORT = """\
+_FOO_OLD_EXPORT = """\
 <type-info
    id="%s"
    kind="Factory-based Type Information"
@@ -504,7 +507,56 @@
 </type-info>
 """
 
-_BAR_EXPORT = """\
+_FOO_EXPORT = """\
+<type-info
+   id="%s"
+   kind="Factory-based Type Information">
+  <property name="title">Foo</property>
+  <property name="description">Foo things</property>
+  <property name="content_icon">foo.png</property>
+  <property name="content_meta_type">Foo Thing</property>
+  <property name="product">CMFSetup</property>
+  <property name="factory">addFoo</property>
+  <property name="immediate_view">foo_view</property>
+  <property name="global_allow">False</property>
+  <property name="filter_content_types">False</property>
+  <property name="allowed_content_types"/>
+  <property name="allow_discussion">False</property>
+  <aliases>
+   <alias from="(Default)" to="foo_view" />
+   <alias from="view" to="foo_view" />
+  </aliases>
+  <action
+     action_id="view"
+     title="View"
+     url_expr="string:${object_url}/foo_view"
+     condition_expr=""
+     category="object"
+     visible="True">
+   <permission>View</permission>
+  </action>
+  <action
+     action_id="edit"
+     title="Edit"
+     url_expr="string:${object_url}/foo_edit_form"
+     condition_expr=""
+     category="object"
+     visible="True">
+   <permission>Modify portal content</permission>
+  </action>
+  <action
+     action_id="metadata"
+     title="Metadata"
+     url_expr="string:${object_url}/metadata_edit_form"
+     condition_expr=""
+     category="object"
+     visible="True">
+   <permission>Modify portal content</permission>
+  </action>
+</type-info>
+"""
+
+_BAR_OLD_EXPORT = """\
 <type-info
    id="%s"
    kind="Scriptable Type Information"
@@ -562,6 +614,65 @@
 </type-info>
 """
 
+_BAR_EXPORT = """\
+<type-info
+   id="%s"
+   kind="Scriptable Type Information">
+  <property name="title">Bar</property>
+  <property name="description">Bar things</property>
+  <property name="content_icon">bar.png</property>
+  <property name="content_meta_type">Bar Thing</property>
+  <property name="permission">Add portal content</property>
+  <property name="constructor_path">make_bar</property>
+  <property name="immediate_view">bar_view</property>
+  <property name="global_allow">True</property>
+  <property name="filter_content_types">True</property>
+  <property name="allowed_content_types">
+   <element value="foo"/></property>
+  <property name="allow_discussion">True</property>
+  <aliases>
+   <alias from="(Default)" to="bar_view" />
+   <alias from="view" to="bar_view" />
+  </aliases>
+  <action
+     action_id="view"
+     title="View"
+     url_expr="string:${object_url}/bar_view"
+     condition_expr=""
+     category="object"
+     visible="True">
+   <permission>View</permission>
+  </action>
+  <action
+     action_id="edit"
+     title="Edit"
+     url_expr="string:${object_url}/bar_edit_form"
+     condition_expr=""
+     category="object"
+     visible="True">
+   <permission>Modify portal content</permission>
+  </action>
+  <action
+     action_id="contents"
+     title="Contents"
+     url_expr="string:${object_url}/folder_contents"
+     condition_expr=""
+     category="object"
+     visible="True">
+   <permission>Access contents information</permission>
+  </action>
+  <action
+     action_id="metadata"
+     title="Metadata"
+     url_expr="string:${object_url}/metadata_edit_form"
+     condition_expr=""
+     category="object"
+     visible="True">
+   <permission>Modify portal content</permission>
+  </action>
+</type-info>
+"""
+
 _UPDATE_FOO_IMPORT = """\
 <type-info id="foo">
   <aliases>
@@ -571,156 +682,175 @@
 """
 
 
-class Test_exportTypesTool( _TypeInfoSetup ):
+class Test_exportTypesTool(_TypeInfoSetup):
 
-    def test_empty( self ):
+    def test_empty(self):
 
         site = self._initSite()
-        context = DummyExportContext( site )
+        context = DummyExportContext(site)
 
         from Products.CMFSetup.typeinfo import exportTypesTool
-        exportTypesTool( context )
+        exportTypesTool(context)
 
-        self.assertEqual( len( context._wrote ), 1 )
-        filename, text, content_type = context._wrote[ 0 ]
-        self.assertEqual( filename, 'typestool.xml' )
-        self._compareDOM( text, _EMPTY_TOOL_EXPORT )
-        self.assertEqual( content_type, 'text/xml' )
+        self.assertEqual(len(context._wrote), 1)
+        filename, text, content_type = context._wrote[0]
+        self.assertEqual(filename, 'typestool.xml')
+        self._compareDOM(text, _EMPTY_TOOL_EXPORT)
+        self.assertEqual(content_type, 'text/xml')
 
-    def test_normal( self ):
+    def test_normal(self):
 
-        site = self._initSite( _TI_LIST )
-        context = DummyExportContext( site )
+        site = self._initSite(_TI_LIST)
+        context = DummyExportContext(site)
 
         from Products.CMFSetup.typeinfo import exportTypesTool
-        exportTypesTool( context )
+        exportTypesTool(context)
 
-        self.assertEqual( len( context._wrote ), 3 )
+        self.assertEqual(len(context._wrote), 3)
 
-        filename, text, content_type = context._wrote[ 0 ]
-        self.assertEqual( filename, 'typestool.xml' )
-        self._compareDOM( text, _NORMAL_TOOL_EXPORT )
-        self.assertEqual( content_type, 'text/xml' )
+        filename, text, content_type = context._wrote[0]
+        self.assertEqual(filename, 'typestool.xml')
+        self._compareDOM(text, _NORMAL_TOOL_EXPORT)
+        self.assertEqual(content_type, 'text/xml')
 
-        filename, text, content_type = context._wrote[ 1 ]
-        self.assertEqual( filename, 'types/foo.xml' )
-        self._compareDOM( text, _FOO_EXPORT % 'foo' )
-        self.assertEqual( content_type, 'text/xml' )
+        filename, text, content_type = context._wrote[1]
+        self.assertEqual(filename, 'types/foo.xml')
+        self._compareDOM(text, _FOO_EXPORT % 'foo')
+        self.assertEqual(content_type, 'text/xml')
 
-        filename, text, content_type = context._wrote[ 2 ]
-        self.assertEqual( filename, 'types/bar.xml' )
-        self._compareDOM( text, _BAR_EXPORT % 'bar' )
-        self.assertEqual( content_type, 'text/xml' )
+        filename, text, content_type = context._wrote[2]
+        self.assertEqual(filename, 'types/bar.xml')
+        self._compareDOM(text, _BAR_EXPORT % 'bar')
+        self.assertEqual(content_type, 'text/xml')
 
-    def test_with_filenames( self ):
+    def test_with_filenames(self):
 
-        site = self._initSite( _TI_LIST_WITH_FILENAME )
-        context = DummyExportContext( site )
+        site = self._initSite(_TI_LIST_WITH_FILENAME)
+        context = DummyExportContext(site)
 
         from Products.CMFSetup.typeinfo import exportTypesTool
-        exportTypesTool( context )
+        exportTypesTool(context)
 
-        self.assertEqual( len( context._wrote ), 3 )
+        self.assertEqual(len(context._wrote), 3)
 
-        filename, text, content_type = context._wrote[ 0 ]
-        self.assertEqual( filename, 'typestool.xml' )
-        self._compareDOM( text, _FILENAME_EXPORT )
-        self.assertEqual( content_type, 'text/xml' )
+        filename, text, content_type = context._wrote[0]
+        self.assertEqual(filename, 'typestool.xml')
+        self._compareDOM(text, _FILENAME_EXPORT)
+        self.assertEqual(content_type, 'text/xml')
 
-        filename, text, content_type = context._wrote[ 1 ]
-        self.assertEqual( filename, 'types/foo_object.xml' )
-        self._compareDOM( text, _FOO_EXPORT % 'foo object' )
-        self.assertEqual( content_type, 'text/xml' )
+        filename, text, content_type = context._wrote[1]
+        self.assertEqual(filename, 'types/foo_object.xml')
+        self._compareDOM(text, _FOO_EXPORT % 'foo object')
+        self.assertEqual(content_type, 'text/xml')
 
-        filename, text, content_type = context._wrote[ 2 ]
-        self.assertEqual( filename, 'types/bar_object.xml' )
-        self._compareDOM( text, _BAR_EXPORT % 'bar object' )
-        self.assertEqual( content_type, 'text/xml' )
+        filename, text, content_type = context._wrote[2]
+        self.assertEqual(filename, 'types/bar_object.xml')
+        self._compareDOM(text, _BAR_EXPORT % 'bar object')
+        self.assertEqual(content_type, 'text/xml')
 
-class Test_importTypesTool( _TypeInfoSetup ):
+class Test_importTypesTool(_TypeInfoSetup):
 
-    def test_empty_default_purge( self ):
+    def test_empty_default_purge(self):
 
-        site = self._initSite( _TI_LIST )
+        site = self._initSite(_TI_LIST)
         tool = site.portal_types
 
-        self.assertEqual( len( tool.objectIds() ), 2 )
+        self.assertEqual(len(tool.objectIds()), 2)
 
-        context = DummyImportContext( site )
-        context._files[ 'typestool.xml' ] = _EMPTY_TOOL_EXPORT
+        context = DummyImportContext(site)
+        context._files['typestool.xml'] = _EMPTY_TOOL_EXPORT
 
         from Products.CMFSetup.typeinfo import importTypesTool
-        importTypesTool( context )
+        importTypesTool(context)
 
-        self.assertEqual( len( tool.objectIds() ), 0 )
+        self.assertEqual(len(tool.objectIds()), 0)
 
-    def test_empty_explicit_purge( self ):
+    def test_empty_explicit_purge(self):
 
-        site = self._initSite( _TI_LIST )
+        site = self._initSite(_TI_LIST)
         tool = site.portal_types
 
-        self.assertEqual( len( tool.objectIds() ), 2 )
+        self.assertEqual(len(tool.objectIds()), 2)
 
-        context = DummyImportContext( site, True )
-        context._files[ 'typestool.xml' ] = _EMPTY_TOOL_EXPORT
+        context = DummyImportContext(site, True)
+        context._files['typestool.xml'] = _EMPTY_TOOL_EXPORT
 
         from Products.CMFSetup.typeinfo import importTypesTool
-        importTypesTool( context )
+        importTypesTool(context)
 
-        self.assertEqual( len( tool.objectIds() ), 0 )
+        self.assertEqual(len(tool.objectIds()), 0)
 
-    def test_empty_skip_purge( self ):
+    def test_empty_skip_purge(self):
 
-        site = self._initSite( _TI_LIST )
+        site = self._initSite(_TI_LIST)
         tool = site.portal_types
 
-        self.assertEqual( len( tool.objectIds() ), 2 )
+        self.assertEqual(len(tool.objectIds()), 2)
 
-        context = DummyImportContext( site, False )
-        context._files[ 'typestool.xml' ] = _EMPTY_TOOL_EXPORT
+        context = DummyImportContext(site, False)
+        context._files['typestool.xml'] = _EMPTY_TOOL_EXPORT
 
         from Products.CMFSetup.typeinfo import importTypesTool
-        importTypesTool( context )
+        importTypesTool(context)
 
-        self.assertEqual( len( tool.objectIds() ), 2 )
+        self.assertEqual(len(tool.objectIds()), 2)
 
-    def test_normal( self ):
+    def test_normal(self):
 
         site = self._initSite()
         tool = site.portal_types
 
-        self.assertEqual( len( tool.objectIds() ), 0 )
+        self.assertEqual(len(tool.objectIds()), 0)
 
-        context = DummyImportContext( site )
-        context._files[ 'typestool.xml' ] = _NORMAL_TOOL_EXPORT
-        context._files[ 'types/foo.xml' ] = _FOO_EXPORT % 'foo'
-        context._files[ 'types/bar.xml' ] = _BAR_EXPORT % 'bar'
+        context = DummyImportContext(site)
+        context._files['typestool.xml'] = _NORMAL_TOOL_EXPORT
+        context._files['types/foo.xml'] = _FOO_EXPORT % 'foo'
+        context._files['types/bar.xml'] = _BAR_EXPORT % 'bar'
 
         from Products.CMFSetup.typeinfo import importTypesTool
-        importTypesTool( context )
+        importTypesTool(context)
 
-        self.assertEqual( len( tool.objectIds() ), 2 )
-        self.failUnless( 'foo' in tool.objectIds() )
-        self.failUnless( 'bar' in tool.objectIds() )
+        self.assertEqual(len(tool.objectIds()), 2)
+        self.failUnless('foo' in tool.objectIds())
+        self.failUnless('bar' in tool.objectIds())
 
-    def test_with_filenames_ascii( self ):
+    def test_old_xml(self):
 
         site = self._initSite()
         tool = site.portal_types
 
-        self.assertEqual( len( tool.objectIds() ), 0 )
+        self.assertEqual(len(tool.objectIds()), 0)
 
-        context = DummyImportContext( site, encoding='ascii' )
-        context._files[ 'typestool.xml' ] = _FILENAME_EXPORT
-        context._files[ 'types/foo_object.xml' ] = _FOO_EXPORT % 'foo object'
-        context._files[ 'types/bar_object.xml' ] = _BAR_EXPORT % 'bar object'
+        context = DummyImportContext(site)
+        context._files['typestool.xml'] = _NORMAL_TOOL_EXPORT
+        context._files['types/foo.xml'] = _FOO_OLD_EXPORT % 'foo'
+        context._files['types/bar.xml'] = _BAR_OLD_EXPORT % 'bar'
 
         from Products.CMFSetup.typeinfo import importTypesTool
-        importTypesTool( context )
+        importTypesTool(context)
+
+        self.assertEqual(len(tool.objectIds()), 2)
+        self.failUnless('foo' in tool.objectIds())
+        self.failUnless('bar' in tool.objectIds())
+
+    def test_with_filenames_ascii(self):
+
+        site = self._initSite()
+        tool = site.portal_types
+
+        self.assertEqual(len(tool.objectIds()), 0)
+
+        context = DummyImportContext(site, encoding='ascii')
+        context._files['typestool.xml'] = _FILENAME_EXPORT
+        context._files['types/foo_object.xml'] = _FOO_EXPORT % 'foo object'
+        context._files['types/bar_object.xml'] = _BAR_EXPORT % 'bar object'
+
+        from Products.CMFSetup.typeinfo import importTypesTool
+        importTypesTool(context)
 
-        self.assertEqual( len( tool.objectIds() ), 2 )
-        self.failUnless( 'foo object' in tool.objectIds() )
-        self.failUnless( 'bar object' in tool.objectIds() )
+        self.assertEqual(len(tool.objectIds()), 2)
+        self.failUnless('foo object' in tool.objectIds())
+        self.failUnless('bar object' in tool.objectIds())
 
     def test_fragment_skip_purge_ascii(self):
 
@@ -735,33 +865,36 @@
         context._files['types/bar.xml'] = _BAR_EXPORT % 'bar'
         importTypesTool(context)
 
-        self.assertEqual( tool.foo.title, 'Foo' )
-        self.assertEqual( tool.foo.content_meta_type, 'Foo Thing' )
-        self.assertEqual( tool.foo.content_icon, 'foo.png' )
-        self.assertEqual( tool.foo.immediate_view, 'foo_view' )
-        self.assertEqual( tool.foo._aliases,
-                          {'(Default)': 'foo_view', 'view': 'foo_view'} )
+        self.assertEqual(tool.foo.title, 'Foo')
+        self.assertEqual(tool.foo.content_meta_type, 'Foo Thing')
+        self.assertEqual(tool.foo.content_icon, 'foo.png')
+        self.assertEqual(tool.foo.immediate_view, 'foo_view')
+        self.assertEqual(tool.foo._aliases,
+                         {'(Default)': 'foo_view', 'view': 'foo_view'})
 
         context = DummyImportContext(site, False, encoding='ascii')
         context._files['typestool.xml'] = _UPDATE_TOOL_IMPORT
         context._files['types/foo.xml'] = _UPDATE_FOO_IMPORT
         importTypesTool(context)
 
-        self.assertEqual( tool.foo.title, 'Foo' )
-        self.assertEqual( tool.foo.content_meta_type, 'Foo Thing' )
-        self.assertEqual( tool.foo.content_icon, 'foo.png' )
-        self.assertEqual( tool.foo.immediate_view, 'foo_view' )
-        self.assertEqual( tool.foo._aliases,
-               {'(Default)': 'foo_view', 'view': 'foo_view', 'spam': 'eggs'} )
+        self.assertEqual(tool.foo.title, 'Foo')
+        self.assertEqual(tool.foo.content_meta_type, 'Foo Thing')
+        self.assertEqual(tool.foo.content_icon, 'foo.png')
+        self.assertEqual(tool.foo.immediate_view, 'foo_view')
+        self.assertEqual(tool.foo._aliases,
+               {'(Default)': 'foo_view', 'view': 'foo_view', 'spam': 'eggs'})
 
 
 def test_suite():
     return unittest.TestSuite((
-        unittest.makeSuite( TypesToolConfiguratorTests ),
-        unittest.makeSuite( TypeInfoConfiguratorTests ),
-        unittest.makeSuite( Test_exportTypesTool ),
-        unittest.makeSuite( Test_importTypesTool ),
-        ))
+        unittest.makeSuite(TypesToolExportConfiguratorTests),
+        unittest.makeSuite(TypesToolImportConfiguratorTests),
+        unittest.makeSuite(TypeInfoExportConfiguratorTests),
+        unittest.makeSuite(TypeInfoImportConfiguratorTests),
+        unittest.makeSuite(OldTypeInfoImportConfiguratorTests),
+        unittest.makeSuite(Test_exportTypesTool),
+        unittest.makeSuite(Test_importTypesTool),
+       ))
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')


=== CMF/CMFSetup/tests/test_utils.py 1.4.2.2 => 1.4.2.3 ===
--- CMF/CMFSetup/tests/test_utils.py:1.4.2.2	Sun May  8 14:58:33 2005
+++ CMF/CMFSetup/tests/test_utils.py	Fri Jul  1 09:27:45 2005
@@ -139,7 +139,7 @@
 <dummy>
 %s
 </dummy>
-""" % _NORMAL_PROPERTY_NODES
+""" % _FIXED_PROPERTY_NODES
 
 _NORMAL_OBJECT_EXPORT = """\
 <?xml version="1.0"?>
@@ -229,25 +229,7 @@
     _properties = ()
 
 
-class ConfiguratorBaseTests(BaseRegistryTests):
-
-    def _getTargetClass(self):
-
-        from Products.CMFSetup.utils import ConfiguratorBase
-        from Products.CMFSetup.utils import CONVERTER, DEFAULT, KEY
-
-        class Configurator(ConfiguratorBase):
-
-            def _getExportTemplate(self):
-                return None
-
-            def _getImportMapping(self):
-                return {
-                  'dummy':
-                    { 'property':    {KEY: 'properties', DEFAULT: ()},
-                      'description': {CONVERTER: self._convertToUnique} } }
-
-        return Configurator
+class _ConfiguratorBaseTests(BaseRegistryTests):
 
     def _initSite(self, foo=2):
 
@@ -286,6 +268,19 @@
 
         return site
 
+
+class ExportConfiguratorBaseTests(_ConfiguratorBaseTests):
+
+    def _getTargetClass(self):
+
+        from Products.CMFSetup.utils import ExportConfiguratorBase
+
+        class Configurator(ExportConfiguratorBase):
+            def _getExportTemplate(self):
+                return None
+
+        return Configurator
+
     def test__extractProperty_normal(self):
 
         site = self._initSite()
@@ -337,6 +332,24 @@
 
         self._compareDOM(xml, _NORMAL_OBJECT_EXPORT)
 
+
+class ImportConfiguratorBaseTests(_ConfiguratorBaseTests):
+
+    def _getTargetClass(self):
+
+        from Products.CMFSetup.utils import ImportConfiguratorBase
+        from Products.CMFSetup.utils import CONVERTER, DEFAULT, KEY
+
+        class Configurator(ImportConfiguratorBase):
+            def _getImportMapping(self):
+                return {
+                  'dummy':
+                    { 'property':    {KEY: 'properties', DEFAULT: ()},
+                      'description': {CONVERTER: self._convertToUnique} } }
+
+        return Configurator
+
+
     def test_parseXML_normal(self):
 
         site = self._initSite()
@@ -484,7 +497,8 @@
 
     return unittest.TestSuite((
         unittest.makeSuite( UtilsTests ),
-        unittest.makeSuite( ConfiguratorBaseTests ),
+        unittest.makeSuite( ImportConfiguratorBaseTests ),
+        unittest.makeSuite( ExportConfiguratorBaseTests ),
         ))
 
 if __name__ == '__main__':



More information about the CMF-checkins mailing list