Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions
CMFDefault.tests.test_File.CachingTests Class Reference
Inheritance diagram for CMFDefault.tests.test_File.CachingTests:
Inheritance graph
[legend]
Collaboration diagram for CMFDefault.tests.test_File.CachingTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def tearDown
def test_index_html_with_304_from_cpm
def test_index_html_200_with_cpm
def test_caching

Private Member Functions

def _getTargetClass
def _makeOne
def _extractFile
def _setupCachingPolicyManager

Detailed Description

Definition at line 86 of file test_File.py.


Member Function Documentation

Definition at line 96 of file test_File.py.

00096 
00097     def _extractFile( self ):
00098 
00099         f = open( TEST_SWF, 'rb' )
00100         try:
00101             data = f.read()
00102         finally:
00103             f.close()
00104 
00105         return TEST_SWF, data

Here is the caller graph for this function:

Definition at line 88 of file test_File.py.

00088 
00089     def _getTargetClass(self):
00090         from Products.CMFDefault.File import File
00091 
00092         return File

def CMFDefault.tests.test_File.CachingTests._makeOne (   self,
  args,
  kw 
) [private]

Definition at line 93 of file test_File.py.

00093 
00094     def _makeOne(self, *args, **kw):
00095         return self._getTargetClass()(*args, **kw)

Here is the call graph for this function:

def CMFDefault.tests.test_File.CachingTests._setupCachingPolicyManager (   self,
  cpm_object 
) [private]

Definition at line 106 of file test_File.py.

00106 
00107     def _setupCachingPolicyManager(self, cpm_object):
00108         self.root.caching_policy_manager = cpm_object

Here is the caller graph for this function:

Definition at line 109 of file test_File.py.

00109 
00110     def tearDown(self):
00111         cleanUp()
00112         RequestTest.tearDown(self)

Here is the call graph for this function:

Definition at line 158 of file test_File.py.

00158 
00159     def test_caching( self ):
00160         self._setupCachingPolicyManager(DummyCachingManager())
00161         original_len = len(self.RESPONSE.headers)
00162         file = self._makeOne('test_file', 'test_file.swf')
00163         file = file.__of__(self.root)
00164         file.index_html(self.REQUEST, self.RESPONSE)
00165         headers = self.RESPONSE.headers
00166         self.failUnless(len(headers) >= original_len + 3)
00167         self.failUnless('foo' in headers.keys())
00168         self.failUnless('bar' in headers.keys())
00169         self.assertEqual(headers['test_path'], '/test_file')
00170 

Definition at line 134 of file test_File.py.

00134 
00135     def test_index_html_200_with_cpm( self ):
00136         # should behave the same as without cpm installed
00137         self._setupCachingPolicyManager(DummyCachingManager())
00138         path, ref = self._extractFile()
00139 
00140         from webdav.common import rfc1123_date
00141 
00142         file = self._makeOne( 'test_file', 'test_file.swf', file=ref )
00143         file = file.__of__( self.root )
00144 
00145         mod_time = file.modified().timeTime()
00146 
00147         data = file.index_html( self.REQUEST, self.RESPONSE )
00148 
00149         self.assertEqual( len( data ), len( ref ) )
00150         self.assertEqual( data, ref )
00151         # ICK!  'HTTPResponse.getHeader' doesn't case-flatten the key!
00152         self.assertEqual( self.RESPONSE.getHeader( 'Content-Length'.lower() )
00153                         , str(len(ref)) )
00154         self.assertEqual( self.RESPONSE.getHeader( 'Content-Type'.lower() )
00155                         , 'application/octet-stream' )
00156         self.assertEqual( self.RESPONSE.getHeader( 'Last-Modified'.lower() )
00157                         , rfc1123_date( mod_time ) )

Definition at line 113 of file test_File.py.

00113 
00114     def test_index_html_with_304_from_cpm( self ):
00115         self._setupCachingPolicyManager(DummyCachingManagerWithPolicy())
00116         path, ref = self._extractFile()
00117 
00118         from webdav.common import rfc1123_date
00119         from Products.CMFCore.tests.base.dummy import FAKE_ETAG
00120 
00121         file = self._makeOne( 'test_file', 'test_file.swf', file=ref )
00122         file = file.__of__( self.root )
00123 
00124         mod_time = file.modified().timeTime()
00125 
00126         self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
00127                             ] = '%s;' % rfc1123_date( mod_time )
00128         self.REQUEST.environ[ 'IF_NONE_MATCH'
00129                             ] = '%s;' % FAKE_ETAG
00130 
00131         data = file.index_html( self.REQUEST, self.RESPONSE )
00132         self.assertEqual( len(data), 0 )
00133         self.assertEqual( self.RESPONSE.getStatus(), 304 )


The documentation for this class was generated from the following file: