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

Tres Seaver tseaver@zope.com
Mon, 11 Mar 2002 07:58:21 -0500


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

Modified Files:
      Tag: tseaver-tracker_477-branch
	test_FSPageTemplate.py 
Log Message:


  - Suppressed auto-expansion of customized FSPageTemplates (Tracker #477).

  - Refactored FSPageTemplate tests:
  
    o pushed possible import failures down into tests;

    o added test for simple customization;

    o added test for Tracker #477.

  - XXX:  Should this policy change (suppressing auto-expansion) be
          configurable somehow?


=== CMF/CMFCore/tests/test_FSPageTemplate.py 1.2 => 1.2.6.1 ===
 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')