[Zope3-checkins] CVS: Zope3/src/zope/app/fssync/tests - test_committer.py:1.24 test_fspickle.py:1.3

Fred L. Drake, Jr. fred at zope.com
Wed Jan 14 16:50:31 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/fssync/tests
In directory cvs.zope.org:/tmp/cvs-serv27321/tests

Modified Files:
	test_committer.py test_fspickle.py 
Log Message:
Changes in the Extra and Annotations directories of a zsync checkout
could not be committed because create_object() would use the temporary
container provided by a serialization adapter as a location to perform
adapter looks and other location-sensitive operations; a separate
context needs to be used to provide location information when
traversing objects in the Extra and Annotations directories since
those ephemeral containers provide no locations in the Zope site.

The context which should be used is the innermost object 'o' from
which the root is reachable via __parent__ references.  This is the
only way these objects can perform adapter looks or resolve persistent
references to objects in the tree.  They will (still) not be able to
resolve "parent" references because the extra and annotation values
for object 'o' have no parent.


=== Zope3/src/zope/app/fssync/tests/test_committer.py 1.23 => 1.24 ===
--- Zope3/src/zope/app/fssync/tests/test_committer.py:1.23	Wed Jan 14 13:33:32 2004
+++ Zope3/src/zope/app/fssync/tests/test_committer.py	Wed Jan 14 16:50:30 2004
@@ -24,7 +24,7 @@
 from zope.component.service import serviceManager
 from zope.app.tests import ztapi
 from zope.exceptions import NotFoundError
-from zope.interface import implements
+from zope.interface import implements, directlyProvides
 
 from zope.xmlpickle import loads, dumps
 from zope.fssync import fsutil
@@ -206,6 +206,30 @@
         c = Committer(syncer.getSerializer,
                       getAnnotations=syncer.getAnnotations)
         c.create_object(*args, **kw)
+
+    def test_create_object_extra(self):
+        class TestContainer:
+            # simulate AttrMapping
+            def __setitem__(self, name, value):
+                self.name = name
+                self.value = value
+        class TestRoot:
+            implements(IContainmentRoot, ITraverser)
+            def traverse(self, *args):
+                pass
+        fspath = tempfile.mktemp()
+        f = open(fspath, 'w')
+        f.write('<pickle> <string>text/plain</string> </pickle>')
+        f.close()
+        container = TestContainer()
+        name = "contentType"
+        root = TestRoot()
+        try:
+            self.create_object(container, name, {}, fspath, context=root)
+        finally:
+            os.remove(fspath)
+        self.assertEqual(container.name, name)
+        self.assertEqual(container.value, "text/plain")
 
     def test_create_object_factory_file(self):
         provideSynchronizer(dict, DictAdapter)


=== Zope3/src/zope/app/fssync/tests/test_fspickle.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/fssync/tests/test_fspickle.py:1.2	Sun Sep 21 13:32:11 2003
+++ Zope3/src/zope/app/fssync/tests/test_fspickle.py	Wed Jan 14 16:50:30 2004
@@ -17,11 +17,46 @@
 """
 import unittest
 
+from zope.app.interfaces.traversing import IContainmentRoot
+from zope.app.location import TLocation
+from zope.app.fssync import fspickle
+from zope.interface import directlyProvides
+
 from zope.testing.doctestunit import DocTestSuite
 
 
+class PersistentLoaderTestCase(unittest.TestCase):
+
+    def setUp(self):
+        root = TLocation()
+        directlyProvides(root, IContainmentRoot)
+        o1 = TLocation(); o1.__parent__ = root; o1.__name__ = 'o1'
+        o2 = TLocation(); o2.__parent__ = root; o2.__name__ = 'o2'
+        o3 = TLocation(); o3.__parent__ = o1; o3.__name__ = 'o3'
+        root.o1 = o1
+        root.o2 = o2
+        o1.foo = o2
+        o1.o3 = o3
+        self.root = root
+        self.o1 = o1
+        self.o2 = o2
+
+    def testPersistentLoader(self):
+        loader = fspickle.PersistentLoader(self.o1)
+        self.assert_(loader.load('/') is self.root)
+        self.assert_(loader.load('/o2') is self.o2)
+
+    def testParentPersistentLoader(self):
+        loader = fspickle.ParentPersistentLoader(self.o1, self.o1)
+        self.assert_(loader.load(fspickle.PARENT_MARKER) is self.o1)
+        self.assert_(loader.load('/') is self.root)
+        self.assert_(loader.load('/o2') is self.o2)
+
+
 def test_suite():
-    return DocTestSuite('zope.app.fssync.fspickle')
+    suite = unittest.makeSuite(PersistentLoaderTestCase)
+    suite.addTest(DocTestSuite('zope.app.fssync.fspickle'))
+    return suite
 
 if __name__ == '__main__':
     unittest.main()




More information about the Zope3-Checkins mailing list