Back to index

plone3  3.1.7
test_FSZSQLMethod.py
Go to the documentation of this file.
00001 import unittest
00002 from Testing import ZopeTestCase
00003 ZopeTestCase.installProduct('ZSQLMethods', 1)
00004 
00005 from os.path import join
00006 
00007 from Acquisition import aq_base
00008 from OFS.Folder import Folder
00009 
00010 from Products.CMFCore.FSMetadata import FSMetadata
00011 from Products.CMFCore.FSZSQLMethod import FSZSQLMethod
00012 from Products.CMFCore.tests.base.testcase import FSDVTest
00013 from Products.CMFCore.tests.base.testcase import SecurityTest
00014 
00015 
00016 class FSZSQLMaker(FSDVTest):
00017 
00018     def _makeOne( self, id, filename ):
00019         path = join(self.skin_path_name, filename)
00020         metadata = FSMetadata(path)
00021         metadata.read()
00022         return FSZSQLMethod( id, path, properties=metadata.getProperties() )
00023 
00024 
00025 class FSZSQLMethodTests(FSDVTest):
00026 
00027     def setUp(self):
00028         FSDVTest.setUp(self)
00029         self._registerDirectory(self)
00030 
00031     def test_initialization(self):
00032         zsql = self.ob.fake_skin.testsql
00033         self.assertEqual(zsql.title, 'This is a title')
00034         self.assertEqual(zsql.connection_id, 'testconn')
00035         self.assertEqual(zsql.arguments_src, 'id')
00036         self.assertEqual(zsql.max_rows_, 1000)
00037         self.assertEqual(zsql.max_cache_, 100)
00038         self.assertEqual(zsql.cache_time_, 10)
00039         self.assertEqual(zsql.class_name_, 'MyRecord')
00040         self.assertEqual(zsql.class_file_, 'CMFCore.TestRecord')
00041         self.assertEqual(zsql.connection_hook, 'MyHook')
00042         self.failIf(zsql.allow_simple_one_argument_traversal is None)
00043 
00044 
00045 class FSZSQLMethodCustomizationTests(SecurityTest, FSZSQLMaker):
00046 
00047     def setUp( self ):
00048         FSZSQLMaker.setUp(self)
00049         SecurityTest.setUp( self )
00050 
00051         self.root._setObject( 'portal_skins', Folder( 'portal_skins' ) )
00052         self.skins = self.root.portal_skins
00053 
00054         self.skins._setObject( 'custom', Folder( 'custom' ) )
00055         self.custom = self.skins.custom
00056 
00057         self.skins._setObject( 'fsdir', Folder( 'fsdir' ) )
00058         self.fsdir = self.skins.fsdir
00059 
00060         self.fsdir._setObject( 'testsql'
00061                              , self._makeOne( 'testsql', 'testsql.zsql' ) )
00062 
00063         self.fsZSQL = self.fsdir.testsql
00064 
00065     def tearDown(self):
00066         SecurityTest.tearDown(self)
00067         FSZSQLMaker.tearDown(self)
00068 
00069     def test_customize( self ):
00070 
00071         self.fsZSQL.manage_doCustomize( folder_path='custom' )
00072 
00073         self.assertEqual( len( self.custom.objectIds() ), 1 )
00074         self.failUnless( 'testsql' in self.custom.objectIds() )   
00075 
00076     def test_customize_alternate_root( self ):
00077 
00078         from OFS.Folder import Folder
00079 
00080         self.root.other = Folder('other')
00081 
00082         self.fsZSQL.manage_doCustomize( folder_path='other', root=self.root )
00083 
00084         self.failIf( 'testsql' in self.custom.objectIds() )   
00085         self.failUnless( 'testsql' in self.root.other.objectIds() )   
00086 
00087     def test_customize_fspath_as_dot( self ):
00088 
00089         self.fsZSQL.manage_doCustomize( folder_path='.' )
00090 
00091         self.failIf( 'testsql' in self.custom.objectIds() )   
00092         self.failUnless( 'testsql' in self.skins.objectIds() )   
00093 
00094     def test_customize_manual_clone( self ):
00095 
00096         from OFS.Folder import Folder
00097 
00098         clone = Folder('testsql')
00099 
00100         self.fsZSQL.manage_doCustomize( folder_path='custom', obj=clone )
00101 
00102         self.failUnless( 'testsql' in self.custom.objectIds() )   
00103         self.failUnless( aq_base(self.custom._getOb('testsql')) is clone )   
00104 
00105     def test_customize_properties(self):
00106         # Make sure all properties are coming across
00107         self.fsZSQL.manage_doCustomize( folder_path='custom' )
00108         zsql = self.custom.testsql
00109 
00110         self.assertEqual(zsql.title, 'This is a title')
00111         self.assertEqual(zsql.connection_id, 'testconn')
00112         self.assertEqual(zsql.arguments_src, 'id')
00113         self.assertEqual(zsql.max_rows_, 1000)
00114         self.assertEqual(zsql.max_cache_, 100)
00115         self.assertEqual(zsql.cache_time_, 10)
00116         self.assertEqual(zsql.class_name_, 'MyRecord')
00117         self.assertEqual(zsql.class_file_, 'CMFCore.TestRecord')
00118         self.assertEqual(zsql.connection_hook, 'MyHook')
00119         self.failIf(zsql.allow_simple_one_argument_traversal is None)
00120 
00121 
00122 def test_suite():
00123     return unittest.TestSuite((
00124         unittest.makeSuite(FSZSQLMethodTests),
00125         unittest.makeSuite(FSZSQLMethodCustomizationTests),
00126         ))
00127 
00128 if __name__ == '__main__':
00129     unittest.main(defaultTest='test_suite')