[Zope-CVS] CVS: Products/AdaptableStorage/tests - testZope2FS.py:1.21
Shane Hathaway
shane@zope.com
Mon, 10 Feb 2003 21:30:21 -0500
Update of /cvs-repository/Products/AdaptableStorage/tests
In directory cvs.zope.org:/tmp/cvs-serv19336/tests
Modified Files:
testZope2FS.py
Log Message:
- FSConnection provides a mechanism for stripping extensions in Zope,
but when this mechanism was employed, AdaptableStorage reverted to
loading the objects as simple files. Now it sees the extension
and the objects are loaded using the preferred class.
- Added docstrings to IFSConnection.
=== Products/AdaptableStorage/tests/testZope2FS.py 1.20 => 1.21 ===
--- Products/AdaptableStorage/tests/testZope2FS.py:1.20 Thu Feb 6 13:39:22 2003
+++ Products/AdaptableStorage/tests/testZope2FS.py Mon Feb 10 21:30:15 2003
@@ -25,8 +25,7 @@
from ZODB.POSException import ConflictError
from Products.PythonScripts.PythonScript import PythonScript
-from OFS.Image import manage_addImage
-from OFS.Image import manage_addFile
+from OFS.Image import File, manage_addImage, manage_addFile
from Products.AdaptableStorage.zodb.ASDB import ASDB
from Products.AdaptableStorage.zodb.ASStorage import ASStorage
from Products.AdaptableStorage.zodb.StaticResource import StaticResource
@@ -444,6 +443,64 @@
self.assert_(('hello.txt') in names, names)
self.assert_(('hello') not in names, names)
self.assert_(('binary_file') in names, names)
+ finally:
+ conn.close()
+
+
+ def testGuessTypeBasedOnExtension(self):
+ # Verify Zope chooses the right object type for
+ # a new object.
+ # White box test.
+ dir = self.conn.expandPath('/')
+ f = open(os.path.join(dir, 'test.py'), 'wt')
+ f.write('return "Ok!"')
+ f.close()
+ conn = self.db.open()
+ try:
+ app = conn.root()['Application']
+ self.assert_(hasattr(app, 'test.py'))
+ self.assert_(isinstance(app['test.py'], PythonScript))
+ self.assertEqual(app['test.py'](), 'Ok!')
+ finally:
+ conn.close()
+
+
+ def testGuessTypeWithChoppedExtension(self):
+ # Verify that even though the extension gets stripped off
+ # in Zope, Zope still sees the object as it should.
+ # White box test.
+ dir = self.conn.expandPath('/')
+ f = open(os.path.join(dir, 'test.py'), 'wt')
+ f.write('return "Ok!"')
+ f.close()
+ f = open(os.path.join(dir, self.conn.metadata_prefix
+ + 'properties'), 'wt')
+ f.write('[object_names]\ntest\n')
+ f.close()
+ conn = self.db.open()
+ try:
+ app = conn.root()['Application']
+ self.assert_(hasattr(app, 'test'))
+ self.assert_(isinstance(app.test, PythonScript))
+ self.assertEqual(app.test(), 'Ok!')
+ finally:
+ conn.close()
+
+
+ def testFallbackToFile(self):
+ # Verify Zope uses a File object for unrecognized stuff.
+ # White box test.
+ data = 'data goes here'
+ dir = self.conn.expandPath('/')
+ f = open(os.path.join(dir, 'test'), 'wt')
+ f.write(data)
+ f.close()
+ conn = self.db.open()
+ try:
+ app = conn.root()['Application']
+ self.assert_(hasattr(app, 'test'))
+ self.assert_(isinstance(app['test'], File))
+ self.assertEqual(str(app['test']), data)
finally:
conn.close()