[CMF-checkins] CVS: CMF/CMFCore/tests - test_TypesTool.py:1.7.12.1

Jeffrey P Shell jeffrey@zope.com
Fri, 28 Dec 2001 16:19:45 -0500


Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv24541

Modified Files:
      Tag: jshell-tracker_409-branch
	test_TypesTool.py 
Log Message:
Added a new test, TypesToolTests#test_AddingOtherTypeInfos(), to
verify the (proposed) fix to Tracker #409.  This deals with the
ability to write new Type Information components and register them
with the types tool (much in the same way you can write new workflow
agents and register them with the workflow tool).


=== CMF/CMFCore/tests/test_TypesTool.py 1.7 => 1.7.12.1 ===
     getUserName = getId
 
+    def has_permission(self, permission, obj):
+        # For types tool tests dealing with filtered_meta_types
+        return 1
+
     def allowed( self, object, object_roles=None ):
         # for testing permissions on actions
         if object.getId() == 'actions_dummy':
@@ -105,6 +109,10 @@
 def extra_meta_types():
     return (  { 'name' : 'Dummy', 'action' : 'manage_addFolder' }, )
 
+class DummyTypeInfo(TypeInformation):
+    """ new class of type info object """
+    meta_type = "Dummy Test Type Info"
+
 class TypesToolTests( unittest.TestCase ):
 
     def setUp( self ):
@@ -182,10 +190,34 @@
         custom_view = utils._getViewFor( dummy, view='view2' )()
         unpermitted_view = utils._getViewFor( dummy, view='edit' )()
 
-        assert default_view == 'view'
-        assert custom_view == 'view2'
-        assert unpermitted_view != 'edit'
-        assert unpermitted_view == 'view'
+        self.failUnlessEqual(default_view, 'view')
+        self.failUnlessEqual(custom_view, 'view2')
+        self.failIf(unpermitted_view == 'edit')
+        self.failUnlessEqual(unpermitted_view, 'view')
+
+    def test_AddingOtherTypeInfos(self):
+        addTypeFactory(DummyTypeInfo)
+        tool = self.root.portal_types
+        type_type = DummyTypeInfo.meta_type
+
+        fmt = [ mt['name'] for mt in tool.filtered_meta_types() ]
+        self.failUnless(DummyTypeInfo.meta_type in fmt,
+                        "Subfactory meta type not registered")
+
+        atif = tool.manage_addTypeInfoForm(self.root.REQUEST,
+                                           type_type=type_type)
+        self.failUnless(atif.find(type_type) > -1,
+                        "'%s' not found in type info form" % type_type)
+
+        tool.manage_addTypeInformation(id='foo_default', type_type=None)
+        fd = tool.foo_default
+        self.failUnless(isinstance(fd, FactoryTypeInformation))
+        self.failIf(isinstance(fd, DummyTypeInfo))
+
+        tool.manage_addTypeInformation(id='foo_sub', type_type=type_type)
+        fs = tool.foo_sub
+        self.failUnless(isinstance(fs, DummyTypeInfo), fs.__class__)
+        
 
 class TypeInfoTests( unittest.TestCase ):
     
@@ -540,13 +572,14 @@
         majyk_dust = folder._getOb( 'majyk_dust' )
         self.assertEqual( majyk_dust.id, 'majyk_dust' )
 
+
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest( unittest.makeSuite( TypesToolTests ) )
     suite.addTest( unittest.makeSuite( FTIDataTests ) )
     suite.addTest( unittest.makeSuite( STIDataTests ) )
     suite.addTest( unittest.makeSuite( FTIConstructionTests ) )
-    suite.addTest( unittest.makeSuite( FTIConstructionTests_w_Roles ) )
     return suite
 
 def run():