[CMF-checkins] CVS: CMF/CMFCore/tests - test_FSPageTemplate.py:1.3

Tres Seaver tseaver@zope.com
Mon, 11 Mar 2002 08:05:45 -0500


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

Modified Files:
	test_FSPageTemplate.py 
Log Message:
 - Merge fix for Tracker #477.

=== CMF/CMFCore/tests/test_FSPageTemplate.py 1.2 => 1.3 ===
 import Zope
-from unittest import TestCase, TestSuite, makeSuite, main
-from Products.CMFCore.FSPageTemplate import FSPageTemplate
-from test_DirectoryView import skin_path_name
-from os.path import join
-from Testing.makerequest import makerequest
-from Products.PageTemplates.TALES import Undefined
 
-class FSPageTemplateTests( TestCase ):
+from Products.CMFCore.tests.base.testcase import RequestTest, SecurityTest
+
+class FSPTMaker:
+
+    def _makeOne( self, id, filename ):
+
+        from Products.CMFCore.FSPageTemplate import FSPageTemplate
+        from Products.CMFCore.tests.test_DirectoryView import skin_path_name
+        from os.path import join
+
+        return FSPageTemplate( id, join( skin_path_name, filename ) )
+
+class FSPageTemplateTests( RequestTest, FSPTMaker ):
 
     def test_Call( self ):
-        """
-        Test calling works
-        """
-        root = makerequest(Zope.app())
-        script = FSPageTemplate('testPT', join(skin_path_name,'testPT.pt'))
-        script = script.__of__(root)
+
+        script = self._makeOne( 'testPT', 'testPT.pt' )
+        script = script.__of__(self.root)
         self.assertEqual(script(),'foo\n')
 
     def test_BadCall( self ):
-        """
-        Test calling a bad template gives an Undefined exception
-        """
-        root = makerequest(Zope.app())
-        script = FSPageTemplate('testPT', join(skin_path_name,'testPTbad.pt'))
-        script = script.__of__(root)
+
+        from Products.PageTemplates.TALES import Undefined
+        script = self._makeOne( 'testPTbad', 'testPTbad.pt' )
+        script = script.__of__(self.root)
         self.assertRaises(Undefined,script)
 
+class FSPageTemplateCustomizationTests( SecurityTest, FSPTMaker ):
+
+    def setUp( self ):
+
+        from OFS.Folder import Folder
+
+        SecurityTest.setUp( self )
+
+        self.root._setObject( 'portal_skins', Folder( 'portal_skins' ) )
+        self.skins = self.root.portal_skins
+
+        self.skins._setObject( 'custom', Folder( 'custom' ) )
+        self.custom = self.skins.custom
+
+        self.skins._setObject( 'fsdir', Folder( 'fsdir' ) )
+        self.fsdir = self.skins.fsdir
+
+        self.fsdir._setObject( 'testPT'
+                             , self._makeOne( 'testPT', 'testPT.pt' ) )
+
+        self.fsPT = self.fsdir.testPT
+
+    def test_customize( self ):
+
+        self.fsPT.manage_doCustomize( folder_path='custom' )
+
+        self.assertEqual( len( self.custom.objectIds() ), 1 )
+        self.failUnless( 'testPT' in self.custom.objectIds() )
+
+    def test_dontExpandOnCreation( self ):
+
+        self.fsPT.manage_doCustomize( folder_path='custom' )
+
+        customized = self.custom.testPT
+        self.failIf( customized.expand )
+
+
 def test_suite():
-    return TestSuite((
-        makeSuite(FSPageTemplateTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(FSPageTemplateTests),
+        unittest.makeSuite(FSPageTemplateCustomizationTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')