Back to index

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

List of all members.

Public Member Functions

def setUp
def tearDown
def test_ctor
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_caching
def test_index_html_200_with_cpm
def test_index_html_with_304_and_caching
def test_tag_with_acquired_clashing_attrs

Private Member Functions

def _makeOne
def _extractFile

Detailed Description

Definition at line 29 of file test_FSImage.py.


Member Function Documentation

Definition at line 45 of file test_FSImage.py.

00045 
00046     def _extractFile( self ):
00047 
00048         path = path_join(self.skin_path_name, 'test_image.gif')
00049         f = open( path, 'rb' )
00050         try:
00051             data = f.read()
00052         finally:
00053             f.close()
00054 
00055         return path, data

Here is the caller graph for this function:

def CMFCore.tests.test_FSImage.FSImageTests._makeOne (   self,
  id,
  filename 
) [private]

Definition at line 39 of file test_FSImage.py.

00039 
00040     def _makeOne( self, id, filename ):
00041 
00042         from Products.CMFCore.FSImage import FSImage
00043 
00044         return FSImage( id, path_join(self.skin_path_name, filename) )

Definition at line 31 of file test_FSImage.py.

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

Definition at line 35 of file test_FSImage.py.

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

Definition at line 155 of file test_FSImage.py.

00155 
00156     def test_caching( self ):
00157         self.root.caching_policy_manager = DummyCachingManager()
00158         original_len = len(self.RESPONSE.headers)
00159         image = self._makeOne('test_image', 'test_image.gif')
00160         image = image.__of__(self.root)
00161         image.index_html(self.REQUEST, self.RESPONSE)
00162         headers = self.RESPONSE.headers
00163         self.failUnless(len(headers) >= original_len + 3)
00164         self.failUnless('foo' in headers.keys())
00165         self.failUnless('bar' in headers.keys())
00166         self.assertEqual(headers['test_path'], '/test_image')

Here is the call graph for this function:

Definition at line 56 of file test_FSImage.py.

00056 
00057     def test_ctor( self ):
00058 
00059         path, ref = self._extractFile()
00060 
00061         image = self._makeOne( 'test_image', 'test_image.gif' )
00062         image = image.__of__( self.root )
00063 
00064         self.assertEqual( image.get_size(), len( ref ) )
00065         self.assertEqual( image._data, ref )

Here is the call graph for this function:

Definition at line 66 of file test_FSImage.py.

00066 
00067     def test_index_html( self ):
00068 
00069         path, ref = self._extractFile()
00070 
00071         import os
00072         from webdav.common import rfc1123_date
00073 
00074         mod_time = os.stat( path )[ 8 ]
00075 
00076         image = self._makeOne( 'test_image', 'test_image.gif' )
00077         image = image.__of__( self.root )
00078 
00079         data = image.index_html( self.REQUEST, self.RESPONSE )
00080 
00081         self.assertEqual( len( data ), len( ref ) )
00082         self.assertEqual( data, ref )
00083         # ICK!  'HTTPResponse.getHeader' doesn't case-flatten the key!
00084         self.assertEqual( self.RESPONSE.getHeader( 'Content-Length'.lower() )
00085                         , str(len(ref)) )
00086         self.assertEqual( self.RESPONSE.getHeader( 'Content-Type'.lower() )
00087                         , 'image/gif' )
00088         self.assertEqual( self.RESPONSE.getHeader( 'Last-Modified'.lower() )
00089                         , rfc1123_date( mod_time ) )

Here is the call graph for this function:

Definition at line 167 of file test_FSImage.py.

00167 
00168     def test_index_html_200_with_cpm( self ):
00169         self.root.caching_policy_manager = DummyCachingManagerWithPolicy()
00170         path, ref = self._extractFile()
00171 
00172         import os
00173         from webdav.common import rfc1123_date
00174         
00175         file = self._makeOne( 'test_file', 'test_image.gif' )
00176         file = file.__of__( self.root )
00177 
00178         mod_time = os.stat( path )[ 8 ]
00179 
00180         data = file.index_html( self.REQUEST, self.RESPONSE )
00181 
00182         # should behave the same as without cpm
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                         , 'image/gif' )
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 90 of file test_FSImage.py.

00090 
00091     def test_index_html_with_304( self ):
00092 
00093         path, ref = self._extractFile()
00094 
00095         import os
00096         from webdav.common import rfc1123_date
00097 
00098         mod_time = os.stat( path )[ 8 ]
00099 
00100         image = self._makeOne( 'test_image', 'test_image.gif' )
00101         image = image.__of__( self.root )
00102 
00103         self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
00104                             ] = '%s;' % rfc1123_date( mod_time+3600 )
00105 
00106         data = image.index_html( self.REQUEST, self.RESPONSE )
00107 
00108         self.assertEqual( data, '' )
00109         # test that we don't supply a content-length
00110         self.assertEqual( self.RESPONSE.getHeader('Content-Length'.lower()),
00111                                                   None )
00112         self.assertEqual( self.RESPONSE.getStatus(), 304 )

Here is the call graph for this function:

Definition at line 192 of file test_FSImage.py.

00192 
00193     def test_index_html_with_304_and_caching( self ):
00194 
00195         # See collector #355
00196         self.root.caching_policy_manager = DummyCachingManager()
00197         original_len = len(self.RESPONSE.headers)
00198         path, ref = self._extractFile()
00199 
00200         import os
00201         from webdav.common import rfc1123_date
00202 
00203         mod_time = os.stat( path )[ 8 ]
00204 
00205         image = self._makeOne( 'test_image', 'test_image.gif' )
00206         image = image.__of__( self.root )
00207 
00208         self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
00209                             ] = '%s;' % rfc1123_date( mod_time+3600 )
00210 
00211         data = image.index_html( self.REQUEST, self.RESPONSE )
00212 
00213         self.assertEqual( data, '' )
00214         self.assertEqual( self.RESPONSE.getStatus(), 304 )
00215 
00216         headers = self.RESPONSE.headers
00217         self.failUnless(len(headers) >= original_len + 3)
00218         self.failUnless('foo' in headers.keys())
00219         self.failUnless('bar' in headers.keys())
00220         self.assertEqual(headers['test_path'], '/test_image')

Here is the call graph for this function:

Definition at line 133 of file test_FSImage.py.

00133 
00134     def test_index_html_with_304_from_cpm( self ):
00135         self.root.caching_policy_manager = DummyCachingManagerWithPolicy()
00136         path, ref = self._extractFile()
00137 
00138         import os
00139         from webdav.common import rfc1123_date
00140         from base.dummy import FAKE_ETAG
00141         
00142         file = self._makeOne( 'test_file', 'test_image.gif' )
00143         file = file.__of__( self.root )
00144 
00145         mod_time = os.stat( path )[ 8 ]
00146 
00147         self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
00148                             ] = '%s;' % rfc1123_date( mod_time )
00149         self.REQUEST.environ[ 'IF_NONE_MATCH'
00150                             ] = '%s;' % FAKE_ETAG
00151 
00152         data = file.index_html( self.REQUEST, self.RESPONSE )
00153         self.assertEqual( len(data), 0 )
00154         self.assertEqual( self.RESPONSE.getStatus(), 304 )

Here is the call graph for this function:

Definition at line 113 of file test_FSImage.py.

00113 
00114     def test_index_html_without_304( self ):
00115 
00116         path, ref = self._extractFile()
00117 
00118         import os
00119         from webdav.common import rfc1123_date
00120 
00121         mod_time = os.stat( path )[ 8 ]
00122 
00123         image = self._makeOne( 'test_image', 'test_image.gif' )
00124         image = image.__of__( self.root )
00125 
00126         self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
00127                             ] = '%s;' % rfc1123_date( mod_time-3600 )
00128 
00129         data = image.index_html( self.REQUEST, self.RESPONSE )
00130 
00131         self.failUnless( data, '' )
00132         self.assertEqual( self.RESPONSE.getStatus(), 200 )

Here is the call graph for this function:

Definition at line 221 of file test_FSImage.py.

00221 
00222     def test_tag_with_acquired_clashing_attrs(self):
00223         # See http://www.zope.org/Collectors/CMF/507
00224         class Clash:
00225             def __str__(self):
00226                 raise NotImplementedError
00227 
00228         self.root.alt = Clash()
00229         self.root.height = Clash()
00230         self.root.width = Clash()
00231 
00232         image = self._makeOne( 'test_image', 'test_image.gif' )
00233         image = image.__of__( self.root )
00234 
00235         tag = image.tag()
00236         self.failUnless('alt=""' in tag)
00237 

Here is the call graph for this function:


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