[Zope-CVS] CVS: Products/Ape/apelib/tests - testzope2fs.py:1.2 zope2testbase.py:1.6

Shane Hathaway shane@zope.com
Sat, 29 Mar 2003 22:11:56 -0500


Update of /cvs-repository/Products/Ape/apelib/tests
In directory cvs.zope.org:/tmp/cvs-serv14802/apelib/tests

Modified Files:
	testzope2fs.py zope2testbase.py 
Log Message:
Improved handling of the content_type attribute of OFS.File and OFS.Image
objects.  The content_type will now be preserved once set.


=== Products/Ape/apelib/tests/testzope2fs.py 1.1.1.1 => 1.2 ===
--- Products/Ape/apelib/tests/testzope2fs.py:1.1.1.1	Sat Mar 15 18:44:41 2003
+++ Products/Ape/apelib/tests/testzope2fs.py	Sat Mar 29 22:11:25 2003
@@ -578,6 +578,23 @@
             conn.close()
 
 
+    def testGuessFileContentType(self):
+        # Verify that file content type guessing happens.
+        data = '<html><body>Cool stuff</body></html>'
+        dir = self.conn._expandPath('/')
+        f = open(os.path.join(dir, 'testobj'), 'wt')
+        f.write(data)
+        f.close()
+
+        conn = self.db.open()
+        try:
+            app = conn.root()['Application']
+            self.assert_(hasattr(app, 'testobj'))
+            self.assertEqual(app.testobj.content_type, 'text/html')
+        finally:
+            conn.close()
+
+
 
 class Zope2FSUnderscoreTests (Zope2FSTests):
     


=== Products/Ape/apelib/tests/zope2testbase.py 1.5 => 1.6 ===
--- Products/Ape/apelib/tests/zope2testbase.py:1.5	Sat Mar 29 21:15:13 2003
+++ Products/Ape/apelib/tests/zope2testbase.py	Sat Mar 29 22:11:25 2003
@@ -375,6 +375,34 @@
             conn.close()
 
 
+    def testFilePreservesContentType(self):
+        # Verify that a file's content_type is preserved.
+        # Note that there is some contention between content_type
+        # guessing and the content_type property.
+        data = (
+            '\n'
+            'This is not just text\n'
+            'In a frivolous file test\n'
+            'But a wise practice.\n'
+            )
+        ct = 'text/x-haiku'
+        conn = self.db.open()
+        try:
+            app = conn.root()['Application']
+            manage_addFile(app, 'file', StringIO(data))
+            app.file.content_type = ct
+            get_transaction().commit()
+
+            conn2 = self.db.open()
+            try:
+                app = conn2.root()['Application']
+                self.assertEqual(app.file.content_type, ct)
+            finally:
+                conn2.close()
+        finally:
+            conn.close()
+
+
     def testPageTemplate(self):
         text = '<span tal:content="string:Hello">example</span>'
         expected = '<span>Hello</span>'