[Zope-CVS] CVS: Products/Ape/lib/apelib/tests -
testzope2fs.py:1.6.2.2 zope2testbase.py:1.7.2.1
Shane Hathaway
shane at zope.com
Wed Feb 25 22:09:26 EST 2004
Update of /cvs-repository/Products/Ape/lib/apelib/tests
In directory cvs.zope.org:/tmp/cvs-serv4850/lib/apelib/tests
Modified Files:
Tag: ape-fs-oid-branch
testzope2fs.py zope2testbase.py
Log Message:
Fixed bugs. All automated tests pass with the new filesystem OID code.
With this working, the _setOb patch became unnecessary. The TmpStore
monkey patch is also obsolete. Only one patch remains, and it's not
much of a problem. Yay!
=== Products/Ape/lib/apelib/tests/testzope2fs.py 1.6.2.1 => 1.6.2.2 ===
--- Products/Ape/lib/apelib/tests/testzope2fs.py:1.6.2.1 Wed Feb 25 11:03:29 2004
+++ Products/Ape/lib/apelib/tests/testzope2fs.py Wed Feb 25 22:08:56 2004
@@ -68,7 +68,7 @@
resource = StaticResource(self.conf)
storage = ApeStorage(resource, conns)
self.storage = storage
- db = ApeDB(storage, resource)
+ db = ApeDB(storage, resource, cache_size=0)
self.db = db
c = self.db.open()
try:
@@ -79,13 +79,18 @@
finally:
c.close()
get_transaction().begin()
- self.conn.afs.clearCache()
+ self.clearCaches()
def tearDown(self):
get_transaction().abort()
self.db.close()
rmtree(self.path)
+ def clearCaches(self):
+ """Clears caches after a filesystem write.
+ """
+ self.conn.afs.clearCache()
+
def testClassificationPreservation(self):
# Ensure that classification doesn't get forgotten.
conn = self.db.open()
@@ -113,10 +118,10 @@
conn.close()
- def testMismatchedIdDetection(self):
- # FSAutoID should detect when the OID and ID don't match.
- # Normally, the only time they don't match is when an object
- # has been moved.
+ def testIgnoreMismatchedId(self):
+ # Verify that FSAutoID doesn't care if the ID of an item
+ # doesn't match what the folder thinks the item's ID should
+ # be.
conn = self.db.open()
try:
app = conn.root()['Application']
@@ -127,13 +132,13 @@
ob = app.Holidays
ob._setId('HolidayCalendar')
- self.assertRaises(ValueError, get_transaction().commit)
+ get_transaction().commit()
finally:
conn.close()
- def testReuseId(self):
- # Verifies that ApeConnection doesn't trip over reusing an OID that's
+ def testReusePath(self):
+ # Verifies that ApeConnection doesn't trip over reuse of a path that's
# no longer in use.
conn = self.db.open()
try:
@@ -164,7 +169,7 @@
app._setObject(template.id, template, set_owner=0)
get_transaction().commit()
- dir = self.conn.getPath('/')
+ dir = self.conn.basepath
names = os.listdir(dir)
self.assert_('template.html' in names, names)
self.assert_('template' not in names, names)
@@ -196,7 +201,7 @@
self.assert_(not hasattr(f, 'script%d.py' % n))
# white box test: verify the scripts were actually stored
# with .py extensions.
- dir = self.conn.getPath('/folder')
+ dir = os.path.join(self.conn.basepath, 'folder')
names = os.listdir(dir)
for n in range(3):
self.assert_(('script%d.py' % n) in names, names)
@@ -230,7 +235,7 @@
self.assert_(not hasattr(f, 'script%d' % n))
# white box test: verify the scripts were actually stored
# with .py extensions.
- dir = self.conn.getPath('/folder')
+ dir = os.path.join(self.conn.basepath, 'folder')
names = os.listdir(dir)
for n in range(3):
self.assert_(('script%d.py' % n) in names, names)
@@ -240,9 +245,11 @@
conn.close()
- def testNameExtensionConflictDetection(self):
- # Verifies that conflicting names resulting from automatic extensions
- # don't go unnoticed.
+ def testAutoRenameOnExtensionConflict(self):
+ # When you create a Python Script called "script0", Ape adds a
+ # .py extension. If, in a second transaction, you add
+ # "script0.py", Ape must rename the current "script0.py" to
+ # "script0" to make room for the new "script0.py".
conn = self.db.open()
try:
app = conn.root()['Application']
@@ -256,16 +263,24 @@
f._setObject(script.id, script, set_owner=0)
get_transaction().commit()
- dir = self.conn.getPath('/folder')
+ dir = os.path.join(self.conn.basepath, '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.
+ # script0.py already exists, so Ape should automatically rename.
script = PythonScript('script0.py')
script.write('##title=test script\nreturn "Hello, world!"')
f._setObject(script.id, script, set_owner=0)
- self.assertRaises(OIDConflictError, get_transaction().commit)
+ get_transaction().commit()
+
+ # Did it write them correctly?
+ text = open(os.path.join(dir, 'script0')).read()
+ self.assert_(text.find('OK') > 0, text)
+ self.assert_(text.find('Hello, world!') < 0, text)
+ text = open(os.path.join(dir, 'script0.py')).read()
+ self.assert_(text.find('OK') < 0, text)
+ self.assert_(text.find('Hello, world!') > 0, text)
finally:
conn.close()
@@ -290,7 +305,7 @@
f._setObject(script.id, script, set_owner=0)
get_transaction().commit()
- dir = self.conn.getPath('/folder')
+ dir = os.path.join(self.conn.basepath, 'folder')
names = os.listdir(dir)
self.assert_(('script0.py') in names, names)
self.assert_(('script0') in names, names)
@@ -364,7 +379,7 @@
f._setObject(script.id, script, set_owner=0)
get_transaction().commit()
- dir = self.conn.getPath('/folder')
+ dir = os.path.join(self.conn.basepath, 'folder')
names = os.listdir(dir)
self.assert_(('script0.py') in names, names)
self.assert_(('script0.dtml') in names, names)
@@ -435,7 +450,7 @@
finally:
conn2.close()
- dir = self.conn.getPath('/')
+ dir = self.conn.basepath
names = os.listdir(dir)
self.assert_(('image.png') in names, names)
self.assert_(('image') not in names, names)
@@ -458,7 +473,7 @@
content_type='application/octet-stream')
get_transaction().commit()
- dir = self.conn.getPath('/')
+ dir = self.conn.basepath
names = os.listdir(dir)
self.assert_(('hello.txt') in names, names)
self.assert_(('world.dat') in names, names)
@@ -472,10 +487,11 @@
# Verify Zope chooses the right object type for
# a new object.
# White box test.
- dir = self.conn.getPath('/')
+ dir = self.conn.basepath
f = open(os.path.join(dir, 'test.py'), 'wt')
f.write('return "Ok!"')
f.close()
+ self.clearCaches()
conn = self.db.open()
try:
app = conn.root()['Application']
@@ -490,7 +506,7 @@
# 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.getPath('/')
+ dir = self.conn.basepath
f = open(os.path.join(dir, 'test.py'), 'wt')
f.write('return "Ok!"')
f.close()
@@ -499,6 +515,7 @@
+ 'properties'), 'wt')
f.write('[object_names]\ntest\n')
f.close()
+ self.clearCaches()
conn = self.db.open()
try:
app = conn.root()['Application']
@@ -513,10 +530,11 @@
# Verify Zope uses a File object for unrecognized files on
# the filesystem. White box test.
data = 'data goes here'
- dir = self.conn.getPath('/')
+ dir = self.conn.basepath
f = open(os.path.join(dir, 'test'), 'wt')
f.write(data)
f.close()
+ self.clearCaches()
conn = self.db.open()
try:
app = conn.root()['Application']
@@ -530,8 +548,9 @@
def testDefaultPropertySchema(self):
# Verify Zope uses the default property schema when no properties
# are set.
- dir = self.conn.getPath('/')
+ dir = self.conn.basepath
os.mkdir(os.path.join(dir, 'test'))
+ self.clearCaches()
conn = self.db.open()
try:
app = conn.root()['Application']
@@ -566,7 +585,7 @@
conn2.close()
# Verify the stowaway is in the properties file.
- dir = self.conn.getPath('/')
+ dir = self.conn.basepath
p = os.path.join(
dir, self.conn.afs.annotation_prefix + 'properties')
f = open(p, 'rt')
@@ -597,7 +616,7 @@
def testGuessFileContentType(self):
# Verify that file content type guessing happens.
data = '<html><body>Cool stuff</body></html>'
- dir = self.conn.getPath('/')
+ dir = self.conn.basepath
f = open(os.path.join(dir, 'testobj'), 'wt')
f.write(data)
f.close()
=== Products/Ape/lib/apelib/tests/zope2testbase.py 1.7 => 1.7.2.1 ===
--- Products/Ape/lib/apelib/tests/zope2testbase.py:1.7 Tue Feb 17 00:25:12 2004
+++ Products/Ape/lib/apelib/tests/zope2testbase.py Wed Feb 25 22:08:56 2004
@@ -33,7 +33,6 @@
from Products.ZSQLMethods.SQL import manage_addZSQLMethod
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
-from apelib.zope2.setup.patches import applySetObPatch
from apelib.core.interfaces import OIDConflictError
@@ -377,8 +376,6 @@
def testRename(self):
- applySetObPatch() # Required for this test to work with Zope2FS
-
conn = self.db.open()
try:
app = conn.root()['Application']
More information about the Zope-CVS
mailing list