[Zope-CVS] CVS: Products/AdaptableStorage/tests - Zope2TestBase.py:1.4 testZope2FS.py:1.14

Shane Hathaway shane@zope.com
Fri, 10 Jan 2003 13:31:47 -0500


Update of /cvs-repository/Products/AdaptableStorage/tests
In directory cvs.zope.org:/tmp/cvs-serv2666/tests

Modified Files:
	Zope2TestBase.py testZope2FS.py 
Log Message:
Made move/rename work with objects from the filesystem.  It took some tricks,
but the tricks have unit tests, so it's not so bad. :-)

- Improved reporting of errors in failed attempts to move objects.

- Added a _setOb() patch that copies objects instead of moving or renaming
them, if that's the only thing that can be done.

- Refactored ZODB branch copying into a simple function, copyOf().

- Made FolderItems set a marker that indicates to _setOb() that it has to
copy rather than move.

Since SQL gateways use FolderItemsByKeychain instead of FolderItems, it has
always been possible to move/rename in a SQL database.  None of these
changes affect SQL operations.


=== Products/AdaptableStorage/tests/Zope2TestBase.py 1.3 => 1.4 ===
--- Products/AdaptableStorage/tests/Zope2TestBase.py:1.3	Thu Jan  9 09:34:07 2003
+++ Products/AdaptableStorage/tests/Zope2TestBase.py	Fri Jan 10 13:31:13 2003
@@ -24,6 +24,8 @@
 from OFS.SimpleItem import SimpleItem
 from AccessControl.User import User, UserFolder
 
+from Products.AdaptableStorage.patches import applySetObPatch
+
 
 class TestFolder(Folder):
 
@@ -263,5 +265,38 @@
             app._p_serial = '\0' * 8  # Pretend that it's new
             self.assertRaises(POSException.ConflictError,
                               get_transaction().commit)
+        finally:
+            conn.close()
+
+
+    def testRename(self):
+        applySetObPatch()  # Required for this test to work with Zope2FS
+
+        conn = self.db.open()
+        try:
+            app = conn.root()['Application']
+            f = Folder()
+            f.id = 'Holidays'
+            app._setObject(f.id, f, set_owner=0)
+            get_transaction().commit()
+
+            # Do what manage_rename does, without the security checks
+            ob = app.Holidays.aq_base
+            app._delObject('Holidays')
+            ob._setId('HolidayCalendar')
+            app._setObject(ob.id, ob, set_owner=0)
+            get_transaction().commit()
+
+            self.assert_(hasattr(app, 'HolidayCalendar'))
+            self.assert_(not hasattr(app, 'Holidays'))
+
+            conn2 = self.db.open()
+            try:
+                app = conn2.root()['Application']
+                self.assert_(hasattr(app, 'HolidayCalendar'))
+                self.assert_(not hasattr(app, 'Holidays'))
+            finally:
+                conn2.close()
+
         finally:
             conn.close()


=== Products/AdaptableStorage/tests/testZope2FS.py 1.13 => 1.14 ===
--- Products/AdaptableStorage/tests/testZope2FS.py:1.13	Tue Jan  7 00:07:40 2003
+++ Products/AdaptableStorage/tests/testZope2FS.py	Fri Jan 10 13:31:13 2003
@@ -47,8 +47,10 @@
         self.storage = storage
         db = ASDB(storage, resource)
         self.db = db
+        get_transaction().begin()
 
     def tearDown(self):
+        get_transaction().abort()
         self.db.close()
         rmtree(self.path)
 
@@ -79,6 +81,26 @@
                 self.assert_(text.find('meta_type=Folder') >= 0)
         finally:
             conn.close()
+
+
+    def testMismatchedIdDetection(self):
+        # FSAutoID should detect when the keychain and ID don't match.
+        # Normally, the only time they don't match is when an object
+        # has been moved.
+        conn = self.db.open()
+        try:
+            app = conn.root()['Application']
+            f = Folder()
+            f.id = 'Holidays'
+            app._setObject(f.id, f, set_owner=0)
+            get_transaction().commit()
+
+            ob = app.Holidays
+            ob._setId('HolidayCalendar')
+            self.assertRaises(ValueError, get_transaction().commit)
+        finally:
+            conn.close()
+
 
 
 class Zope2FSUnderscoreTests (Zope2FSTests):