Back to index

plone3  3.1.7
test_FSDTMLMethod.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests for FSDTMLMethod module.
00014 
00015 $Id: test_FSDTMLMethod.py 37061 2005-06-15 14:17:41Z tseaver $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from os.path import join as path_join
00022 
00023 from Acquisition import aq_base
00024 from DateTime import DateTime
00025 from OFS.Folder import Folder
00026 from Products.StandardCacheManagers import RAMCacheManager
00027 from zope.app.component.hooks import setHooks
00028 
00029 from Products.CMFCore.FSDTMLMethod import FSDTMLMethod
00030 from Products.CMFCore.FSMetadata import FSMetadata
00031 from Products.CMFCore.tests.base.dummy import DummyCachingManager
00032 from Products.CMFCore.tests.base.dummy import DummyCachingManagerWithPolicy
00033 from Products.CMFCore.tests.base.testcase import FSDVTest
00034 from Products.CMFCore.tests.base.testcase import RequestTest
00035 from Products.CMFCore.tests.base.testcase import SecurityTest
00036 from Products.CMFCore.tests.base.dummy import DummyContent
00037 
00038 
00039 class FSDTMLMaker(FSDVTest):
00040 
00041     def _makeOne( self, id, filename ):
00042         path = path_join(self.skin_path_name, filename)
00043         metadata = FSMetadata(path)
00044         metadata.read()
00045         return FSDTMLMethod( id, path, properties=metadata.getProperties() )
00046 
00047 
00048 class FSDTMLMethodTests(RequestTest, FSDTMLMaker):
00049 
00050     def setUp(self):
00051         FSDTMLMaker.setUp(self)
00052         RequestTest.setUp(self)
00053         setHooks()
00054 
00055     def tearDown(self):
00056         RequestTest.tearDown(self)
00057         FSDTMLMaker.tearDown(self)
00058 
00059     def _setupCachingPolicyManager(self, cpm_object):
00060         self.root.caching_policy_manager = cpm_object
00061 
00062     def test_Call( self ):
00063         script = self._makeOne( 'testDTML', 'testDTML.dtml' )
00064         script = script.__of__(self.app)
00065         self.assertEqual(script(self.app, self.REQUEST), 'nohost\n')
00066 
00067     def test_caching( self ):
00068         #   Test HTTP caching headers.
00069         self._setupCachingPolicyManager(DummyCachingManager())
00070         original_len = len( self.RESPONSE.headers )
00071         script = self._makeOne('testDTML', 'testDTML.dtml')
00072         script = script.__of__(self.root)
00073         script(self.root, self.REQUEST, self.RESPONSE)
00074         self.failUnless( len( self.RESPONSE.headers ) >= original_len + 2 )
00075         self.failUnless( 'foo' in self.RESPONSE.headers.keys() )
00076         self.failUnless( 'bar' in self.RESPONSE.headers.keys() )
00077 
00078     def test_ownership( self ):
00079         script = self._makeOne( 'testDTML', 'testDTML.dtml' )
00080         script = script.__of__(self.root)
00081         # fsdtmlmethod has no owner
00082         owner_tuple = script.getOwnerTuple()
00083         self.assertEqual(owner_tuple, None)
00084 
00085         # and ownership is not acquired [CMF/450]
00086         self.root._owner= ('/foobar', 'baz')
00087         owner_tuple = script.getOwnerTuple()
00088         self.assertEqual(owner_tuple, None)
00089 
00090     def test_304_response_from_cpm( self ):
00091         # test that we get a 304 response from the cpm via this template
00092 
00093         from webdav.common import rfc1123_date
00094 
00095         mod_time = DateTime()
00096         self._setupCachingPolicyManager(DummyCachingManagerWithPolicy())
00097         content = DummyContent(id='content')
00098         content.modified_date = mod_time
00099         content = content.__of__(self.root)
00100         script = self._makeOne('testDTML', 'testDTML.dtml')
00101         script = script.__of__(content)
00102         self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
00103                             ] = '%s;' % rfc1123_date( mod_time+3600 )
00104         data = script(content, self.REQUEST, self.RESPONSE)
00105 
00106         self.assertEqual( data, '' )
00107         self.assertEqual( self.RESPONSE.getStatus(), 304 )
00108 
00109 class FSDTMLMethodCustomizationTests( SecurityTest, FSDTMLMaker ):
00110 
00111     def setUp( self ):
00112         FSDTMLMaker.setUp(self)
00113         SecurityTest.setUp( self )
00114 
00115         self.root._setObject( 'portal_skins', Folder( 'portal_skins' ) )
00116         self.skins = self.root.portal_skins
00117 
00118         self.skins._setObject( 'custom', Folder( 'custom' ) )
00119         self.custom = self.skins.custom
00120 
00121         self.skins._setObject( 'fsdir', Folder( 'fsdir' ) )
00122         self.fsdir = self.skins.fsdir
00123 
00124         self.fsdir._setObject( 'testDTML'
00125                              , self._makeOne( 'testDTML', 'testDTML.dtml' ) )
00126 
00127         self.fsDTML = self.fsdir.testDTML
00128 
00129     def test_customize( self ):
00130 
00131         self.fsDTML.manage_doCustomize( folder_path='custom' )
00132 
00133         self.assertEqual( len( self.custom.objectIds() ), 1 )
00134         self.failUnless( 'testDTML' in self.custom.objectIds() )
00135 
00136     def test_customize_alternate_root( self ):
00137 
00138         from OFS.Folder import Folder
00139 
00140         self.root.other = Folder('other')
00141 
00142         self.fsDTML.manage_doCustomize( folder_path='other', root=self.root )
00143 
00144         self.failIf( 'testDTML' in self.custom.objectIds() )
00145         self.failUnless( 'testDTML' in self.root.other.objectIds() )
00146 
00147     def test_customize_fspath_as_dot( self ):
00148 
00149         self.fsDTML.manage_doCustomize( folder_path='.' )
00150 
00151         self.failIf( 'testDTML' in self.custom.objectIds() )
00152         self.failUnless( 'testDTML' in self.skins.objectIds() )
00153 
00154     def test_customize_manual_clone( self ):
00155 
00156         from OFS.Folder import Folder
00157 
00158         clone = Folder('testDTML')
00159 
00160         self.fsDTML.manage_doCustomize( folder_path='custom', obj=clone )
00161 
00162         self.failUnless( 'testDTML' in self.custom.objectIds() )
00163         self.failUnless( aq_base(self.custom._getOb('testDTML')) is clone)
00164 
00165     def test_customize_caching(self):
00166         # Test to ensure that cache manager associations survive customizing
00167         cache_id = 'gofast'
00168         RAMCacheManager.manage_addRAMCacheManager( self.root
00169                                                  , cache_id
00170                                                  , REQUEST=None
00171                                                  )
00172         self.fsDTML.ZCacheable_setManagerId(cache_id, REQUEST=None)
00173 
00174         self.assertEqual(self.fsDTML.ZCacheable_getManagerId(), cache_id)
00175 
00176         self.fsDTML.manage_doCustomize(folder_path='custom')
00177         custom_pt = self.custom.testDTML
00178 
00179         self.assertEqual(custom_pt.ZCacheable_getManagerId(), cache_id)
00180 
00181     def tearDown(self):
00182         SecurityTest.tearDown(self)
00183         FSDTMLMaker.tearDown(self)
00184 
00185 
00186 def test_suite():
00187     return unittest.TestSuite((
00188         unittest.makeSuite(FSDTMLMethodTests),
00189         unittest.makeSuite(FSDTMLMethodCustomizationTests),
00190         ))
00191 
00192 if __name__ == '__main__':
00193     unittest.main(defaultTest='test_suite')