[Zope-Checkins] SVN: Zope/branches/elro-parent-pointers/s copy objects using zope.copy (test failing until elro checks in his changes)
David Glick
davidglick at onenw.org
Mon Oct 31 23:08:40 UTC 2011
Log message for revision 123221:
copy objects using zope.copy (test failing until elro checks in his changes)
Changed:
U Zope/branches/elro-parent-pointers/setup.py
U Zope/branches/elro-parent-pointers/src/OFS/CopySupport.py
U Zope/branches/elro-parent-pointers/src/OFS/configure.zcml
U Zope/branches/elro-parent-pointers/src/OFS/tests/testCopySupport.py
-=-
Modified: Zope/branches/elro-parent-pointers/setup.py
===================================================================
--- Zope/branches/elro-parent-pointers/setup.py 2011-10-31 22:44:53 UTC (rev 123220)
+++ Zope/branches/elro-parent-pointers/setup.py 2011-10-31 23:08:40 UTC (rev 123221)
@@ -79,6 +79,7 @@
'zope.container',
'zope.contentprovider',
'zope.contenttype',
+ 'zope.copy',
'zope.deferredimport',
'zope.event',
'zope.exceptions',
Modified: Zope/branches/elro-parent-pointers/src/OFS/CopySupport.py
===================================================================
--- Zope/branches/elro-parent-pointers/src/OFS/CopySupport.py 2011-10-31 22:44:53 UTC (rev 123220)
+++ Zope/branches/elro-parent-pointers/src/OFS/CopySupport.py 2011-10-31 23:08:40 UTC (rev 123221)
@@ -18,7 +18,6 @@
from marshal import loads
import re
import sys
-import tempfile
from urllib import quote
from urllib import unquote
import warnings
@@ -47,6 +46,7 @@
from zope.lifecycleevent import ObjectCopiedEvent
from zope.lifecycleevent import ObjectMovedEvent
from zope.container.contained import notifyContainerModified
+from zope.copy import copy
from OFS.event import ObjectWillBeMovedEvent
from OFS.event import ObjectClonedEvent
@@ -582,11 +582,7 @@
`container`)
# Ask an object for a new copy of itself.
- f=tempfile.TemporaryFile()
- self._p_jar.exportFile(self._p_oid,f)
- f.seek(0)
- ob=container._p_jar.importFile(f)
- f.close()
+ ob = copy(aq_base(self))
return ob
def _postCopy(self, container, op=0):
Modified: Zope/branches/elro-parent-pointers/src/OFS/configure.zcml
===================================================================
--- Zope/branches/elro-parent-pointers/src/OFS/configure.zcml 2011-10-31 22:44:53 UTC (rev 123220)
+++ Zope/branches/elro-parent-pointers/src/OFS/configure.zcml 2011-10-31 23:08:40 UTC (rev 123221)
@@ -4,4 +4,6 @@
<include file="deprecated.zcml"/>
<include file="event.zcml"/>
+ <adapter factory="zope.location.pickling.LocationCopyHook" />
+
</configure>
Modified: Zope/branches/elro-parent-pointers/src/OFS/tests/testCopySupport.py
===================================================================
--- Zope/branches/elro-parent-pointers/src/OFS/tests/testCopySupport.py 2011-10-31 22:44:53 UTC (rev 123220)
+++ Zope/branches/elro-parent-pointers/src/OFS/tests/testCopySupport.py 2011-10-31 23:08:40 UTC (rev 123221)
@@ -12,6 +12,10 @@
from OFS.Folder import manage_addFolder
from OFS.Image import manage_addFile
from Testing.makerequest import makerequest
+from zope import component
+from zope.testing import cleanup
+from persistent import Persistent
+from zope.location import Location
ADD_IMAGES_AND_FILES = 'Add images and files'
@@ -62,6 +66,11 @@
s = DemoStorage()
return ZODB.DB( s ).open()
+
+class PersistentLocation(Persistent, Location):
+ pass
+
+
class CopySupportTestBase(unittest.TestCase):
def _initFolders(self):
@@ -102,10 +111,16 @@
del self.responseOut
del self.root
del self.connection
+ cleanup.cleanUp()
+
class TestCopySupport( CopySupportTestBase ):
def setUp( self ):
+ from zope.copy.interfaces import ICopyHook
+ from zope.location.interfaces import ILocation
+ from zope.location.pickling import LocationCopyHook
+ component.provideAdapter(LocationCopyHook, (ILocation,), ICopyHook)
folder1, folder2 = self._initFolders()
@@ -152,6 +167,7 @@
self.folder2.manage_pasteObjects( cookie )
self.assertTrue( 'file' in self.folder1.objectIds() )
self.assertTrue( 'file' in self.folder2.objectIds() )
+ self.assertTrue(self.folder2.file.__parent__ is self.folder2)
def testCut( self ):
self.assertTrue( 'file' in self.folder1.objectIds() )
@@ -169,7 +185,16 @@
self.folder2.manage_pasteObjects(cookie)
self.assertTrue('newfile' in self.folder1.objectIds())
self.assertTrue('newfile' in self.folder2.objectIds())
+
+ def testCopyExcludesNoncontainedObjects(self):
+ self.app.other_ob = other_ob = PersistentLocation()
+ self.app.other_ob.__parent__ = self.app
+ ob = self.folder1.file
+ ob.other_ob = self.app.other_ob
+ copied_ob = ob._getCopy(self.folder1)
+ self.assertTrue(copied_ob.other_ob is other_ob)
+
def testPasteSingleNotSameID( self ):
self.assertTrue( 'file' in self.folder1.objectIds() )
self.assertFalse( 'file' in self.folder2.objectIds() )
More information about the Zope-Checkins
mailing list