Back to index

plone3  3.1.7
test_FSPropertiesObject.py
Go to the documentation of this file.
00001 import unittest
00002 
00003 from Acquisition import aq_base
00004 
00005 from Products.CMFCore.tests.base.testcase import FSDVTest
00006 from Products.CMFCore.tests.base.testcase import SecurityTest
00007 
00008 
00009 class FSPOTests(SecurityTest, FSDVTest):
00010 
00011     def setUp( self ):
00012         FSDVTest.setUp(self)
00013         SecurityTest.setUp( self )
00014 
00015     def tearDown( self ):
00016         SecurityTest.tearDown( self )
00017         FSDVTest.tearDown(self)
00018 
00019     def _getTargetClass( self ):
00020         from Products.CMFCore.FSPropertiesObject import FSPropertiesObject
00021         return FSPropertiesObject
00022 
00023     def _makeOne( self, id, filename ):
00024         from os.path import join
00025         path = join(self.skin_path_name, filename)
00026         return self._getTargetClass()( id, path ) 
00027 
00028     def _makeContext( self, po_id, po_filename ):
00029         from OFS.Folder import Folder
00030 
00031         self.root._setObject( 'portal_skins', Folder( 'portal_skins' ) )
00032         skins = self.root.portal_skins
00033 
00034         skins._setObject( 'custom', Folder( 'custom' ) )
00035         custom = skins.custom
00036 
00037         skins._setObject( 'fsdir', Folder( 'fsdir' ) )
00038         fsdir = skins.fsdir
00039 
00040         fsdir._setObject( 'test_props', self._makeOne( po_id, po_filename ) )
00041         fspo = fsdir.test_props
00042 
00043         return custom, fsdir, fspo
00044 
00045     def test__readFile( self ):
00046         from DateTime.DateTime import DateTime
00047 
00048         custom, fsdir, fspo = self._makeContext( 'test_props'
00049                                                , 'test_props.props')
00050 
00051         self.assertEqual( fspo.getProperty( 'title' ), 'Test properties' )
00052         self.assertEqual( fspo.getProperty( 'value1' ), 'one' )
00053         self.assertEqual( fspo.getProperty( 'value2' ), 'two' )
00054         self.assertEqual( fspo.getProperty( 'an_int' ), 42 )
00055         self.assertEqual( fspo.getProperty( 'a_float' ), 3.1415926 )
00056         self.assertEqual( fspo.getProperty( 'a_boolean' ), False )
00057         self.assertEqual( fspo.getProperty( 'a_long' ), 40000000000 )
00058         self.assertEqual( fspo.getProperty( 'a_date' )
00059                         , DateTime( '01/01/2001' ) )
00060         self.assertEqual( fspo.getProperty( 'a_tokens' )
00061                         , [ 'peter', 'paul', 'mary' ] )
00062 
00063     def test__createZODBClone( self ):
00064 
00065         from OFS.Folder import Folder
00066 
00067         custom, fsdir, fspo = self._makeContext( 'test_props'
00068                                                , 'test_props.props')
00069 
00070         target = fspo._createZODBClone()
00071         self.failUnless( isinstance( target, Folder ) )
00072         for prop_id in fspo.propertyIds():
00073             self.assertEqual( target.getProperty( prop_id )
00074                             , fspo.getProperty( prop_id ) )
00075 
00076     def test_manage_doCustomize( self ):
00077         custom, fsdir, fspo = self._makeContext( 'test_props'
00078                                                , 'test_props.props')
00079 
00080         fspo.manage_doCustomize( folder_path='custom' )
00081 
00082         self.assertEqual( len( custom.objectIds() ), 1 )
00083         self.failUnless( 'test_props' in custom.objectIds() )  
00084 
00085     def test_manage_doCustomize_alternate_root( self ):
00086         from OFS.Folder import Folder
00087 
00088         custom, fsdir, fspo = self._makeContext( 'test_props'
00089                                                , 'test_props.props')
00090         self.root.other = Folder('other')
00091 
00092         fspo.manage_doCustomize( folder_path='other', root=self.root )
00093 
00094         self.failIf( 'test_props' in custom.objectIds() )  
00095         self.failUnless( 'test_props' in self.root.other.objectIds() )  
00096 
00097     def test_manage_doCustomize_fspath_as_dot( self ):
00098         custom, fsdir, fspo = self._makeContext( 'test_props'
00099                                                , 'test_props.props')
00100         fspo.manage_doCustomize( folder_path='.' )
00101 
00102         self.failIf( 'test_props' in custom.objectIds() )  
00103         self.failUnless( 'test_props' in self.root.portal_skins.objectIds() )  
00104 
00105     def test_manage_doCustomize_manual_clone( self ):
00106         from OFS.Folder import Folder
00107 
00108         custom, fsdir, fspo = self._makeContext( 'test_props'
00109                                                , 'test_props.props')
00110         clone = Folder('test_props')
00111         fspo.manage_doCustomize( folder_path='custom', obj=clone )
00112 
00113         self.failUnless( 'test_props' in custom.objectIds() )  
00114         self.failUnless( aq_base(custom._getOb('test_props')) is clone )  
00115 
00116 
00117 def test_suite():
00118     return unittest.TestSuite((
00119         unittest.makeSuite( FSPOTests ),
00120         ))
00121 
00122 if __name__ == '__main__':
00123     unittest.main(defaultTest='test_suite')