[CMF-checkins] CVS: Products/CMFCore/tests - test_TypesTool.py:1.8
Tres Seaver
tseaver@zope.com
Fri, 4 Jan 2002 15:00:41 -0500
Update of /cvs-repository/Products/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv13507/CMFCore/tests
Modified Files:
test_TypesTool.py
Log Message:
- Extended TypesTool to permit registration of new TypeInformation
implementations (Tracker #409, thanks to Jeffrey Shell for the
work!)
=== Products/CMFCore/tests/test_TypesTool.py 1.7 => 1.8 ===
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 ):
@@ -539,6 +571,8 @@
ti.constructInstance( folder, 'dust' )
majyk_dust = folder._getOb( 'majyk_dust' )
self.assertEqual( majyk_dust.id, 'majyk_dust' )
+
+
def test_suite():
suite = unittest.TestSuite()