Back to index

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

List of all members.

Public Member Functions

def tearDown
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

Private Member Functions

def _extractFile
def _getTargetClass
def _makeOne
def _setupCachingPolicyManager

Detailed Description

Definition at line 190 of file test_Image.py.


Member Function Documentation

Definition at line 192 of file test_Image.py.

00192 
00193     def _extractFile( self ):
00194 
00195         f = open( TEST_JPG, 'rb' )
00196         try:
00197             data = f.read()
00198         finally:
00199             f.close()
00200 
00201         return TEST_JPG, data

Here is the caller graph for this function:

Definition at line 202 of file test_Image.py.

00202 
00203     def _getTargetClass(self):
00204         from Products.CMFDefault.Image import Image
00205 
00206         return Image

def CMFDefault.tests.test_Image.TestCaching._makeOne (   self,
  args,
  kw 
) [private]

Definition at line 207 of file test_Image.py.

00207 
00208     def _makeOne(self, *args, **kw):
00209         return self._getTargetClass()(*args, **kw)

Here is the call graph for this function:

def CMFDefault.tests.test_Image.TestCaching._setupCachingPolicyManager (   self,
  cpm_object 
) [private]

Definition at line 210 of file test_Image.py.

00210 
00211     def _setupCachingPolicyManager(self, cpm_object):
00212         self.root.caching_policy_manager = cpm_object

Here is the caller graph for this function:

Definition at line 213 of file test_Image.py.

00213 
00214     def tearDown(self):
00215         cleanUp()
00216         RequestTest.tearDown(self)

Here is the call graph for this function:

Definition at line 238 of file test_Image.py.

00238 
00239     def test_caching( self ):
00240         self._setupCachingPolicyManager(DummyCachingManager())
00241         original_len = len(self.RESPONSE.headers)
00242         image = self._makeOne('test_image', 'test_image.jpg')
00243         image = image.__of__(self.root)
00244         image.index_html(self.REQUEST, self.RESPONSE)
00245         headers = self.RESPONSE.headers
00246         self.failUnless(len(headers) >= original_len + 3)
00247         self.failUnless('foo' in headers.keys())
00248         self.failUnless('bar' in headers.keys())
00249         self.assertEqual(headers['test_path'], '/test_image')

Definition at line 250 of file test_Image.py.

00250 
00251     def test_index_html_200_with_cpm( self ):
00252         self._setupCachingPolicyManager(DummyCachingManagerWithPolicy())
00253         path, ref = self._extractFile()
00254 
00255         from webdav.common import rfc1123_date
00256 
00257         file = self._makeOne( 'test_file', 'test_image.jpg', file=ref )
00258         file = file.__of__( self.root )
00259 
00260         mod_time = file.modified()
00261 
00262         data = file.index_html( self.REQUEST, self.RESPONSE )
00263 
00264         # should behave the same as without cpm
00265         self.assertEqual( len( data ), len( ref ) )
00266         self.assertEqual( data, ref )
00267         # ICK!  'HTTPResponse.getHeader' doesn't case-flatten the key!
00268         self.assertEqual( self.RESPONSE.getHeader( 'Content-Length'.lower() )
00269                         , str(len(ref)) )
00270         self.assertEqual( self.RESPONSE.getHeader( 'Content-Type'.lower() )
00271                         , 'image/jpeg' )
00272         self.assertEqual( self.RESPONSE.getHeader( 'Last-Modified'.lower() )
00273                         , rfc1123_date( mod_time ) )

Definition at line 274 of file test_Image.py.

00274 
00275     def test_index_html_with_304_and_caching( self ):
00276 
00277         # See collector #355
00278         self._setupCachingPolicyManager(DummyCachingManager())
00279         original_len = len(self.RESPONSE.headers)
00280         path, ref = self._extractFile()
00281 
00282         from webdav.common import rfc1123_date
00283 
00284         self.root.image = self._makeOne( 'test_image', 'test_image.gif' )
00285         image = self.root.image
00286         transaction.savepoint(optimistic=True)
00287 
00288         mod_time = image.modified()
00289 
00290         self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
00291                             ] = '%s;' % rfc1123_date( mod_time+1 )
00292 
00293         data = image.index_html( self.REQUEST, self.RESPONSE )
00294 
00295         self.assertEqual( data, '' )
00296         self.assertEqual( self.RESPONSE.getStatus(), 304 )
00297 
00298         headers = self.RESPONSE.headers
00299         self.failUnless(len(headers) >= original_len + 3)
00300         self.failUnless('foo' in headers.keys())
00301         self.failUnless('bar' in headers.keys())
00302         self.assertEqual(headers['test_path'], '/test_image')
00303 

Definition at line 217 of file test_Image.py.

00217 
00218     def test_index_html_with_304_from_cpm( self ):
00219         self._setupCachingPolicyManager(DummyCachingManagerWithPolicy())
00220         path, ref = self._extractFile()
00221 
00222         from webdav.common import rfc1123_date
00223         from Products.CMFCore.tests.base.dummy import FAKE_ETAG
00224 
00225         self.root.file = self._makeOne('test_file', 'test_image.jpg', file=ref)
00226         file = self.root.file
00227 
00228         mod_time = file.modified()
00229 
00230         self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
00231                             ] = '%s;' % rfc1123_date( mod_time )
00232         self.REQUEST.environ[ 'IF_NONE_MATCH'
00233                             ] = '%s;' % FAKE_ETAG
00234 
00235         data = file.index_html( self.REQUEST, self.RESPONSE )
00236         self.assertEqual( len(data), 0 )
00237         self.assertEqual( self.RESPONSE.getStatus(), 304 )


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