Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions
CMFCore.tests.test_FSFile.FSFileTests Class Reference
Inheritance diagram for CMFCore.tests.test_FSFile.FSFileTests:
Inheritance graph
[legend]
Collaboration diagram for CMFCore.tests.test_FSFile.FSFileTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def setUp
def tearDown
def test_ctor
def test_str
def test_index_html
def test_index_html_with_304
def test_index_html_without_304
def test_index_html_with_304_from_cpm
def test_index_html_200_with_cpm
def test_caching
def test_forced_content_type
def test_utf8charset_detection

Private Member Functions

def _makeOne
def _extractFile

Detailed Description

Definition at line 29 of file test_FSFile.py.


Member Function Documentation

def CMFCore.tests.test_FSFile.FSFileTests._extractFile (   self,
  filename 
) [private]

Definition at line 51 of file test_FSFile.py.

00051 
00052     def _extractFile( self, filename ):
00053 
00054         path = path_join(self.skin_path_name, filename)
00055         f = open( path, 'rb' )
00056         try:
00057             data = f.read()
00058         finally:
00059             f.close()
00060 
00061         return path, data

Here is the caller graph for this function:

def CMFCore.tests.test_FSFile.FSFileTests._makeOne (   self,
  id,
  filename 
) [private]

Definition at line 39 of file test_FSFile.py.

00039 
00040     def _makeOne( self, id, filename ):
00041 
00042         from Products.CMFCore.FSFile import FSFile
00043         from Products.CMFCore.FSMetadata import FSMetadata
00044 
00045         full_path = path_join(self.skin_path_name, filename)
00046         metadata = FSMetadata(full_path)
00047         metadata.read()
00048         fsfile_ob = FSFile(id, full_path, properties=metadata.getProperties())
00049 
00050         return fsfile_ob

Definition at line 31 of file test_FSFile.py.

00031 
00032     def setUp(self):
00033         FSDVTest.setUp(self)
00034         RequestTest.setUp(self)

Definition at line 35 of file test_FSFile.py.

00035 
00036     def tearDown(self):
00037         RequestTest.tearDown(self)
00038         FSDVTest.tearDown(self)

Definition at line 192 of file test_FSFile.py.

00192 
00193     def test_caching( self ):
00194         self.root.caching_policy_manager = DummyCachingManager()
00195         original_len = len(self.RESPONSE.headers)
00196         file = self._makeOne('test_file', 'test_file.swf')
00197         file = file.__of__(self.root)
00198         file.index_html(self.REQUEST, self.RESPONSE)
00199         headers = self.RESPONSE.headers
00200         self.failUnless(len(headers) >= original_len + 3)
00201         self.failUnless('foo' in headers.keys())
00202         self.failUnless('bar' in headers.keys())
00203         self.assertEqual(headers['test_path'], '/test_file')

Here is the call graph for this function:

Definition at line 62 of file test_FSFile.py.

00062 
00063     def test_ctor( self ):
00064 
00065         path, ref = self._extractFile('test_file.swf')
00066 
00067         file = self._makeOne( 'test_file', 'test_file.swf' )
00068         file = file.__of__( self.root )
00069 
00070         self.assertEqual( file.get_size(), len( ref ) )
00071         self.assertEqual( file._readFile(0), ref )

Here is the call graph for this function:

Definition at line 204 of file test_FSFile.py.

00204 
00205     def test_forced_content_type( self ):
00206 
00207         path, ref = self._extractFile('test_file_two.swf')
00208 
00209         import os
00210         from webdav.common import rfc1123_date
00211 
00212         mod_time = os.stat( path )[ 8 ]
00213 
00214         file = self._makeOne( 'test_file', 'test_file_two.swf' )
00215         file = file.__of__( self.root )
00216 
00217         data = file.index_html( self.REQUEST, self.RESPONSE )
00218 
00219         self.assertEqual( len( data ), len( ref ) )
00220         self.assertEqual( data, ref )
00221         # ICK!  'HTTPResponse.getHeader' doesn't case-flatten the key!
00222         self.assertEqual( self.RESPONSE.getHeader( 'Content-Length'.lower() )
00223                         , str(len(ref)) )
00224         self.assertEqual( self.RESPONSE.getHeader( 'Content-Type'.lower() )
00225                         , 'application/x-shockwave-flash' )
00226         self.assertEqual( self.RESPONSE.getHeader( 'Last-Modified'.lower() )
00227                         , rfc1123_date( mod_time ) )

Here is the call graph for this function:

Definition at line 78 of file test_FSFile.py.

00078 
00079     def test_index_html( self ):
00080 
00081         path, ref = self._extractFile('test_file.swf')
00082 
00083         import os
00084         from webdav.common import rfc1123_date
00085 
00086         mod_time = os.stat( path )[ 8 ]
00087 
00088         file = self._makeOne( 'test_file', 'test_file.swf' )
00089         file = file.__of__( self.root )
00090 
00091         data = file.index_html( self.REQUEST, self.RESPONSE )
00092 
00093         self.assertEqual( len( data ), len( ref ) )
00094         self.assertEqual( data, ref )
00095         # ICK!  'HTTPResponse.getHeader' doesn't case-flatten the key!
00096         self.assertEqual( self.RESPONSE.getHeader( 'Content-Length'.lower() )
00097                         , str(len(ref)) )
00098         self.assertEqual( self.RESPONSE.getHeader( 'Content-Type'.lower() )
00099                         , 'application/octet-stream' )
00100         self.assertEqual( self.RESPONSE.getHeader( 'Last-Modified'.lower() )
00101                         , rfc1123_date( mod_time ) )

Here is the call graph for this function:

Definition at line 167 of file test_FSFile.py.

00167 
00168     def test_index_html_200_with_cpm( self ):
00169         # should behave the same as without cpm installed
00170         self.root.caching_policy_manager = DummyCachingManager()
00171         path, ref = self._extractFile('test_file.swf')
00172 
00173         import os
00174         from webdav.common import rfc1123_date
00175         
00176         file = self._makeOne( 'test_file', 'test_file.swf' )
00177         file = file.__of__( self.root )
00178 
00179         mod_time = os.stat( path )[ 8 ]
00180 
00181         data = file.index_html( self.REQUEST, self.RESPONSE )
00182 
00183         self.assertEqual( len( data ), len( ref ) )
00184         self.assertEqual( data, ref )
00185         # ICK!  'HTTPResponse.getHeader' doesn't case-flatten the key!
00186         self.assertEqual( self.RESPONSE.getHeader( 'Content-Length'.lower() )
00187                         , str(len(ref)) )
00188         self.assertEqual( self.RESPONSE.getHeader( 'Content-Type'.lower() )
00189                         , 'application/octet-stream' )
00190         self.assertEqual( self.RESPONSE.getHeader( 'Last-Modified'.lower() )
00191                         , rfc1123_date( mod_time ) )

Here is the call graph for this function:

Definition at line 102 of file test_FSFile.py.

00102 
00103     def test_index_html_with_304( self ):
00104 
00105         path, ref = self._extractFile('test_file.swf')
00106 
00107         import os
00108         from webdav.common import rfc1123_date
00109 
00110         mod_time = os.stat( path )[ 8 ]
00111 
00112         file = self._makeOne( 'test_file', 'test_file.swf' )
00113         file = file.__of__( self.root )
00114 
00115         self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
00116                             ] = '%s;' % rfc1123_date( mod_time+3600 )
00117 
00118         data = file.index_html( self.REQUEST, self.RESPONSE )
00119 
00120         self.assertEqual( data, '' )
00121         # test that we don't supply a content-length
00122         self.assertEqual( self.RESPONSE.getHeader('Content-Length'.lower()),
00123                                                None )
00124         self.assertEqual( self.RESPONSE.getStatus(), 304 )

Here is the call graph for this function:

Definition at line 145 of file test_FSFile.py.

00145 
00146     def test_index_html_with_304_from_cpm( self ):
00147         self.root.caching_policy_manager = DummyCachingManagerWithPolicy()
00148         path, ref = self._extractFile('test_file.swf')
00149 
00150         import os
00151         from webdav.common import rfc1123_date
00152         from base.dummy import FAKE_ETAG
00153         
00154         file = self._makeOne( 'test_file', 'test_file.swf' )
00155         file = file.__of__( self.root )
00156 
00157         mod_time = os.stat( path )[ 8 ]
00158 
00159         self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
00160                             ] = '%s;' % rfc1123_date( mod_time )
00161         self.REQUEST.environ[ 'IF_NONE_MATCH'
00162                             ] = '%s;' % FAKE_ETAG
00163 
00164         data = file.index_html( self.REQUEST, self.RESPONSE )
00165         self.assertEqual( len(data), 0 )
00166         self.assertEqual( self.RESPONSE.getStatus(), 304 )

Here is the call graph for this function:

Definition at line 125 of file test_FSFile.py.

00125 
00126     def test_index_html_without_304( self ):
00127 
00128         path, ref = self._extractFile('test_file.swf')
00129 
00130         import os
00131         from webdav.common import rfc1123_date
00132 
00133         mod_time = os.stat( path )[ 8 ]
00134 
00135         file = self._makeOne( 'test_file', 'test_file.swf' )
00136         file = file.__of__( self.root )
00137 
00138         self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
00139                             ] = '%s;' % rfc1123_date( mod_time-3600 )
00140 
00141         data = file.index_html( self.REQUEST, self.RESPONSE )
00142 
00143         self.failUnless( data, '' )
00144         self.assertEqual( self.RESPONSE.getStatus(), 200 )

Here is the call graph for this function:

Definition at line 72 of file test_FSFile.py.

00072 
00073     def test_str( self ):
00074         path, ref = self._extractFile('test_file.swf')
00075         file = self._makeOne( 'test_file', 'test_file.swf' )
00076         file = file.__of__( self.root )
00077         self.assertEqual( len(str(file)), len( ref ) )

Here is the call graph for this function:

Definition at line 228 of file test_FSFile.py.

00228 
00229     def test_utf8charset_detection( self ):
00230         file_name = 'testUtf8.js'
00231         file = self._makeOne(file_name, file_name)
00232         file = file.__of__(self.root)
00233         data = file.index_html(self.REQUEST, self.RESPONSE)
00234         self.assertEqual(self.RESPONSE.getHeader('content-type'),
00235                          'application/x-javascript; charset=utf-8')
00236 

Here is the call graph for this function:


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