[Zope-CVS] CVS: Products/AdaptableStorage/tests - Zope2TestBase.py:1.4.2.6 testASStorage.py:1.4.2.6 testAll.py:1.3.2.4 testSerialization.py:1.7.2.4 testZope2FS.py:1.10.2.4
Christian Zagrodnick
cz@gocept.com
Thu, 6 Feb 2003 08:01:47 -0500
Update of /cvs-repository/Products/AdaptableStorage/tests
In directory cvs.zope.org:/tmp/cvs-serv14413/tests
Modified Files:
Tag: zagy-patches
Zope2TestBase.py testASStorage.py testAll.py
testSerialization.py testZope2FS.py
Log Message:
merging HEAD into zagy-patches branch
=== Products/AdaptableStorage/tests/Zope2TestBase.py 1.4.2.5 => 1.4.2.6 ===
=== Products/AdaptableStorage/tests/testASStorage.py 1.4.2.5 => 1.4.2.6 ===
=== Products/AdaptableStorage/tests/testAll.py 1.3.2.3 => 1.3.2.4 ===
=== Products/AdaptableStorage/tests/testSerialization.py 1.7.2.3 => 1.7.2.4 ===
=== Products/AdaptableStorage/tests/testZope2FS.py 1.10.2.3 => 1.10.2.4 ===
--- Products/AdaptableStorage/tests/testZope2FS.py:1.10.2.3 Tue Feb 4 12:29:50 2003
+++ Products/AdaptableStorage/tests/testZope2FS.py Thu Feb 6 08:01:16 2003
@@ -21,6 +21,8 @@
import unittest
from tempfile import mktemp
+from ZODB.POSException import ConflictError
+from Products.PythonScripts.PythonScript import PythonScript
from Products.AdaptableStorage.zodb.ASDB import ASDB
from Products.AdaptableStorage.zodb.ASStorage import ASStorage
from Products.AdaptableStorage.zodb.StaticResource import StaticResource
@@ -125,11 +127,252 @@
conn.close()
+ def testPreserveNamesWithoutExtensions(self):
+ # Verifies that FSConnection retains original object names,
+ # even though the files might be stored with extensions.
+ conn = self.db.open()
+ try:
+ app = conn.root()['Application']
+ f = Folder()
+ f.id = 'folder'
+ app._setObject(f.id, f, set_owner=0)
+ for n in range(3):
+ script = PythonScript('script%d' % n)
+ script.write('##title=test script\nreturn "OK"')
+ f._setObject(script.id, script, set_owner=0)
+ get_transaction().commit()
+
+ conn2 = self.db.open()
+ try:
+ app = conn2.root()['Application']
+ f = app.folder
+ for n in range(3):
+ self.assert_(hasattr(f, 'script%d' % n))
+ self.assert_(not hasattr(f, 'script%d.py' % n))
+ # white box test: verify the scripts were actually stored
+ # with .py extensions.
+ dir = self.conn.expandPath('/folder')
+ names = os.listdir(dir)
+ for n in range(3):
+ self.assert_(('script%d.py' % n) in names, names)
+ finally:
+ conn2.close()
+ finally:
+ conn.close()
+
+
+ def testPreserveNamesWithExtensions(self):
+ # Verifies that FSConnection retains original object names
+ # even though the object names already have extensions.
+ conn = self.db.open()
+ try:
+ app = conn.root()['Application']
+ f = Folder()
+ f.id = 'folder'
+ app._setObject(f.id, f, set_owner=0)
+ for n in range(3):
+ script = PythonScript('script%d.py' % n)
+ script.write('##title=test script\nreturn "OK"')
+ f._setObject(script.id, script, set_owner=0)
+ get_transaction().commit()
+
+ conn2 = self.db.open()
+ try:
+ app = conn2.root()['Application']
+ f = app.folder
+ for n in range(3):
+ self.assert_(hasattr(f, 'script%d.py' % n))
+ self.assert_(not hasattr(f, 'script%d' % n))
+ # white box test: verify the scripts were actually stored
+ # with .py extensions.
+ dir = self.conn.expandPath('/folder')
+ names = os.listdir(dir)
+ for n in range(3):
+ self.assert_(('script%d.py' % n) in names, names)
+ finally:
+ conn2.close()
+ finally:
+ conn.close()
+
+
+ def testNameExtensionConflictDetection(self):
+ # Verifies that conflicting names resulting from automatic extensions
+ # don't go unnoticed.
+ conn = self.db.open()
+ try:
+ app = conn.root()['Application']
+ f = Folder()
+ f.id = 'folder'
+ app._setObject(f.id, f, set_owner=0)
+
+ # Can't write to 'script0' then 'script0.py'.
+ script = PythonScript('script0')
+ script.write('##title=test script\nreturn "OK"')
+ f._setObject(script.id, script, set_owner=0)
+ get_transaction().commit()
+
+ dir = self.conn.expandPath('/folder')
+ names = os.listdir(dir)
+ self.assert_(('script0.py') in names, names)
+ self.assert_(('script0') not in names, names)
+
+ # script0.py already exists, so the transaction will fail.
+ script = PythonScript('script0.py')
+ script.write('##title=test script\nreturn "Hello, world!"')
+ f._setObject(script.id, script, set_owner=0)
+ self.assertRaises(ConflictError, get_transaction().commit)
+ finally:
+ conn.close()
+
+
+ def testNonConflictingNameExtensions1(self):
+ # Verifies that FSConnection can write to 'script0.py' then 'script0'
+ conn = self.db.open()
+ try:
+ app = conn.root()['Application']
+ f = Folder()
+ f.id = 'folder'
+ app._setObject(f.id, f, set_owner=0)
+
+ # It's OK to write to 'script0.py' then 'script0'.
+ script = PythonScript('script0.py')
+ script.write('##title=test script\nreturn "OK"')
+ f._setObject(script.id, script, set_owner=0)
+ get_transaction().commit()
+
+ script = PythonScript('script0')
+ script.write('##title=test script\nreturn "Hello, world!"')
+ f._setObject(script.id, script, set_owner=0)
+ get_transaction().commit()
+
+ dir = self.conn.expandPath('/folder')
+ names = os.listdir(dir)
+ self.assert_(('script0.py') in names, names)
+ self.assert_(('script0') in names, names)
+
+ conn2 = self.db.open()
+ try:
+ app = conn2.root()['Application']
+ f = app.folder
+ self.assertEqual(f['script0.py'](), 'OK')
+ self.assertEqual(f['script0'](), 'Hello, world!')
+ finally:
+ conn2.close()
+ finally:
+ conn.close()
+
+
+ def testNonConflictingNameExtensions2(self):
+ # Verifies that FSConnection can write to 'script0.py' and 'script0'
+ # at the same time
+ conn = self.db.open()
+ try:
+ app = conn.root()['Application']
+ f = Folder()
+ f.id = 'folder'
+ app._setObject(f.id, f, set_owner=0)
+
+ # It's OK to write to 'script0.py' then 'script0'.
+ script = PythonScript('script0.py')
+ script.write('##title=test script\nreturn "OK"')
+ f._setObject(script.id, script, set_owner=0)
+ script = PythonScript('script0')
+ script.write('##title=test script\nreturn "Hello, world!"')
+ f._setObject(script.id, script, set_owner=0)
+ get_transaction().commit()
+
+ conn2 = self.db.open()
+ try:
+ app = conn2.root()['Application']
+ f = app.folder
+ self.assertEqual(f['script0.py'](), 'OK')
+ self.assertEqual(f['script0'](), 'Hello, world!')
+ finally:
+ conn2.close()
+ finally:
+ conn.close()
+
+
+ def testNonConflictingNameExtensions3(self):
+ # Verifies that FSConnection can write to 'script0.py'
+ # then 'script0.dtml', then 'script0'.
+ # Then verifies that removal of items works correctly.
+ conn = self.db.open()
+ try:
+ app = conn.root()['Application']
+ f = Folder()
+ f.id = 'folder'
+ app._setObject(f.id, f, set_owner=0)
+
+ script = PythonScript('script0.py')
+ script.write('##title=test script\nreturn "OK"')
+ f._setObject(script.id, script, set_owner=0)
+ get_transaction().commit()
+
+ script = PythonScript('script0.dtml')
+ script.write('##title=test script\nreturn "No DTML here"')
+ f._setObject(script.id, script, set_owner=0)
+ get_transaction().commit()
+
+ script = PythonScript('script0')
+ script.write('##title=test script\nreturn "Hello, world!"')
+ f._setObject(script.id, script, set_owner=0)
+ get_transaction().commit()
+
+ dir = self.conn.expandPath('/folder')
+ names = os.listdir(dir)
+ self.assert_(('script0.py') in names, names)
+ self.assert_(('script0.dtml') in names, names)
+ self.assert_(('script0') in names, names)
+
+ conn2 = self.db.open()
+ try:
+ app2 = conn2.root()['Application']
+ f2 = app2.folder
+ self.assertEqual(f2['script0.py'](), 'OK')
+ self.assertEqual(f2['script0.dtml'](), 'No DTML here')
+ self.assertEqual(f2['script0'](), 'Hello, world!')
+ finally:
+ conn2.close()
+
+ f._delObject('script0.py')
+ get_transaction().commit()
+ names = os.listdir(dir)
+ self.assert_(('script0.py') not in names, names)
+ self.assert_(('script0.dtml') in names, names)
+ self.assert_(('script0') in names, names)
+
+ f._delObject('script0')
+ get_transaction().commit()
+ names = os.listdir(dir)
+ self.assert_(('script0.py') not in names, names)
+ self.assert_(('script0.dtml') in names, names)
+ self.assert_(('script0') not in names, names)
+
+ script = PythonScript('script0')
+ script.write('##title=test script\nreturn "Hello, world!"')
+ f._setObject(script.id, script, set_owner=0)
+ get_transaction().commit()
+ names = os.listdir(dir)
+ self.assert_(('script0.py') not in names, names)
+ self.assert_(('script0.dtml') in names, names)
+ self.assert_(('script0') in names, names)
+
+ f._delObject('script0.dtml')
+ get_transaction().commit()
+ names = os.listdir(dir)
+ 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()
+
+
class Zope2FSUnderscoreTests (Zope2FSTests):
def _createMapper(self, path):
- return createMapper(path, hidden_filename_prefix='_')
+ return createMapper(path, metadata_prefix='_')
if __name__ == '__main__':