[Zope-CVS] CVS: Products/AdaptableStorage/tests - testZope2FS.py:1.18
Shane Hathaway
shane@zope.com
Thu, 6 Feb 2003 12:55:27 -0500
Update of /cvs-repository/Products/AdaptableStorage/tests
In directory cvs.zope.org:/tmp/cvs-serv12047/tests
Modified Files:
testZope2FS.py
Log Message:
Gave images and files the correct automatic extension according to the
mimetypes module.
=== Products/AdaptableStorage/tests/testZope2FS.py 1.17 => 1.18 ===
--- Products/AdaptableStorage/tests/testZope2FS.py:1.17 Wed Feb 5 13:50:01 2003
+++ Products/AdaptableStorage/tests/testZope2FS.py Thu Feb 6 12:55:26 2003
@@ -17,12 +17,15 @@
"""
import os
+import sys
from shutil import rmtree
import unittest
from tempfile import mktemp
+from cStringIO import StringIO
from ZODB.POSException import ConflictError
from Products.PythonScripts.PythonScript import PythonScript
+from OFS.Image import manage_addImage
from Products.AdaptableStorage.zodb.ASDB import ASDB
from Products.AdaptableStorage.zodb.ASStorage import ASStorage
from Products.AdaptableStorage.zodb.StaticResource import StaticResource
@@ -31,6 +34,12 @@
from Zope2TestBase import Zope2TestBase, Folder
+try:
+ __file__
+except NameError:
+ __file__ = os.path.abspath(sys.argv[0])
+
+
class Zope2FSTests (unittest.TestCase, Zope2TestBase):
def _createMapper(self, path):
@@ -364,6 +373,36 @@
self.assert_(('script0.py') not in names, names)
self.assert_(('script0.dtml') not in names, names)
self.assert_(('script0') in names, names)
+ finally:
+ conn.close()
+
+
+ def testImageExtension(self):
+ # Verify that a new image is stored with the correct extension.
+ path = os.path.join(os.path.dirname(__file__), 'correct.png')
+ f = open(path, 'rb')
+ try:
+ data = f.read()
+ finally:
+ f.close()
+ conn = self.db.open()
+ try:
+ app = conn.root()['Application']
+ manage_addImage(app, 'image', StringIO(data))
+ get_transaction().commit()
+
+ self.assertEqual(app.image.data, data)
+ conn2 = self.db.open()
+ try:
+ app = conn2.root()['Application']
+ self.assertEqual(app.image.data, data)
+ finally:
+ conn2.close()
+
+ dir = self.conn.expandPath('/')
+ names = os.listdir(dir)
+ self.assert_(('image.png') in names, names)
+ self.assert_(('image') not in names, names)
finally:
conn.close()