[CMF-checkins] CVS: Products/CMFCore/tests - test_FSFile.py:1.8.14.1

Jens Vagelpohl jens at dataflake.org
Mon Sep 6 04:03:34 EDT 2004


Update of /cvs-repository/Products/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv30593/CMFCore/tests

Modified Files:
      Tag: CMF-1_5-branch
	test_FSFile.py 
Log Message:
- FSFile: Allow setting a content_type value using a .metadata file
  (http://www.zope.org/Collectors/CMF/281)


=== Products/CMFCore/tests/test_FSFile.py 1.8 => 1.8.14.1 ===
--- Products/CMFCore/tests/test_FSFile.py:1.8	Mon Apr 26 08:14:17 2004
+++ Products/CMFCore/tests/test_FSFile.py	Mon Sep  6 04:03:33 2004
@@ -23,12 +23,18 @@
     def _makeOne( self, id, filename ):
 
         from Products.CMFCore.FSFile import FSFile
+        from Products.CMFCore.FSMetadata import FSMetadata
 
-        return FSFile( id, path_join(self.skin_path_name, filename) )
+        full_path = path_join(self.skin_path_name, filename)
+        metadata = FSMetadata(full_path)
+        metadata.read()
+        fsfile_ob = FSFile(id, full_path, properties=metadata.getProperties())
 
-    def _extractFile( self ):
+        return fsfile_ob
 
-        path = path_join(self.skin_path_name, 'test_file.swf')
+    def _extractFile( self, filename ):
+
+        path = path_join(self.skin_path_name, filename)
         f = open( path, 'rb' )
         try:
             data = f.read()
@@ -39,7 +45,7 @@
 
     def test_ctor( self ):
 
-        path, ref = self._extractFile()
+        path, ref = self._extractFile('test_file.swf')
 
         file = self._makeOne( 'test_file', 'test_file.swf' )
         file = file.__of__( self.root )
@@ -48,14 +54,14 @@
         self.assertEqual( file._readFile(0), ref )
 
     def test_str( self ):
-        path, ref = self._extractFile()
+        path, ref = self._extractFile('test_file.swf')
         file = self._makeOne( 'test_file', 'test_file.swf' )
         file = file.__of__( self.root )
         self.assertEqual( len(str(file)), len( ref ) )
 
     def test_index_html( self ):
 
-        path, ref = self._extractFile()
+        path, ref = self._extractFile('test_file.swf')
 
         import os
         from webdav.common import rfc1123_date
@@ -79,7 +85,7 @@
 
     def test_index_html_with_304( self ):
 
-        path, ref = self._extractFile()
+        path, ref = self._extractFile('test_file.swf')
 
         import os
         from webdav.common import rfc1123_date
@@ -99,7 +105,7 @@
 
     def test_index_html_without_304( self ):
 
-        path, ref = self._extractFile()
+        path, ref = self._extractFile('test_file.swf')
 
         import os
         from webdav.common import rfc1123_date
@@ -116,6 +122,30 @@
 
         self.failUnless( data, '' )
         self.assertEqual( self.RESPONSE.getStatus(), 200 )
+
+    def test_forced_content_type( self ):
+
+        path, ref = self._extractFile('test_file_two.swf')
+
+        import os
+        from webdav.common import rfc1123_date
+
+        mod_time = os.stat( path )[ 8 ]
+
+        file = self._makeOne( 'test_file', 'test_file_two.swf' )
+        file = file.__of__( self.root )
+
+        data = file.index_html( self.REQUEST, self.RESPONSE )
+
+        self.assertEqual( len( data ), len( ref ) )
+        self.assertEqual( data, ref )
+        # ICK!  'HTTPResponse.getHeader' doesn't case-flatten the key!
+        self.assertEqual( self.RESPONSE.getHeader( 'Content-Length'.lower() )
+                        , str(len(ref)) )
+        self.assertEqual( self.RESPONSE.getHeader( 'Content-Type'.lower() )
+                        , 'application/x-shockwave-flash' )
+        self.assertEqual( self.RESPONSE.getHeader( 'Last-Modified'.lower() )
+                        , rfc1123_date( mod_time ) )
 
 
 def test_suite():



More information about the CMF-checkins mailing list