[Zope3-checkins] SVN: Zope3/trunk/ IObjectCopiedEvent now also carries the original from which the

Florent Guillaume fg at nuxeo.com
Fri Nov 25 08:32:29 EST 2005


Log message for revision 40367:
  IObjectCopiedEvent now also carries the original from which the
  copy was made (http://www.zope.org/Collectors/Zope3-dev/478)
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/app/container/tests/test_objectcopier.py
  U   Zope3/trunk/src/zope/app/copypastemove/__init__.py
  U   Zope3/trunk/src/zope/app/event/interfaces.py
  U   Zope3/trunk/src/zope/app/event/objectevent.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2005-11-25 13:21:13 UTC (rev 40366)
+++ Zope3/trunk/doc/CHANGES.txt	2005-11-25 13:32:29 UTC (rev 40367)
@@ -10,6 +10,9 @@
 
     New features
 
+      - IObjectCopiedEvent now also carries the original from which the
+        copy was made (http://www.zope.org/Collectors/Zope3-dev/478)
+
       - Implemented the password managers proposal. Main idea beside the
         proposal is a standard way to implement password encoders/checkers, see
         zope.app.authentication.interfaces.IPasswordManager for details.

Modified: Zope3/trunk/src/zope/app/container/tests/test_objectcopier.py
===================================================================
--- Zope3/trunk/src/zope/app/container/tests/test_objectcopier.py	2005-11-25 13:21:13 UTC (rev 40366)
+++ Zope3/trunk/src/zope/app/container/tests/test_objectcopier.py	2005-11-25 13:32:29 UTC (rev 40367)
@@ -16,16 +16,68 @@
 $Id$
 """
 from unittest import TestCase, TestSuite, main, makeSuite
+from zope.testing import doctest
 
+from zope.app.event.tests.placelesssetup import getEvents
+from zope.app.event.tests.placelesssetup import clearEvents
 from zope.app.component.testing import PlacefulSetup
 from zope.app.copypastemove import ObjectCopier
 from zope.app.copypastemove.interfaces import IObjectCopier
 from zope.app.testing import ztapi
+from zope.app.testing import setup
 from zope.app.traversing.api import traverse
+from zope.app.folder import Folder
 
 class File(object):
     pass
 
+def test_copy_events():
+    """
+    Prepare the setup::
+
+      >>> root = setup.placefulSetUp(site=True)
+      >>> ztapi.provideAdapter(None, IObjectCopier, ObjectCopier)
+
+    Prepare some objects::
+
+      >>> folder = Folder()
+      >>> root[u'foo'] = File()
+      >>> root[u'folder'] = folder
+      >>> list(folder.keys())
+      []
+      >>> foo = traverse(root, 'foo') # wrap in ContainedProxy
+
+    Now make a copy::
+
+      >>> clearEvents()
+      >>> copier = IObjectCopier(foo)
+      >>> copier.copyTo(folder, u'bar')
+      u'bar'
+
+    Check that the copy has been done::
+
+      >>> list(folder.keys())
+      [u'bar']
+
+    Check what events have been sent::
+
+      >>> events = getEvents()
+      >>> [event.__class__.__name__ for event in events]
+      ['ObjectCopiedEvent', 'ObjectAddedEvent', 'ObjectModifiedEvent']
+
+    Check that the ObjectCopiedEvent includes the correct data::
+
+      >>> events[0].object is folder[u'bar']
+      True
+      >>> events[0].original is root[u'foo']
+      True
+
+    Finally, tear down::
+
+      >>> setup.placefulTearDown()
+    """
+
+
 class ObjectCopierTest(PlacefulSetup, TestCase):
 
     def setUp(self):
@@ -152,6 +204,7 @@
 def test_suite():
     return TestSuite((
         makeSuite(ObjectCopierTest),
+        doctest.DocTestSuite(),
         ))
 
 if __name__=='__main__':

Modified: Zope3/trunk/src/zope/app/copypastemove/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/copypastemove/__init__.py	2005-11-25 13:21:13 UTC (rev 40366)
+++ Zope3/trunk/src/zope/app/copypastemove/__init__.py	2005-11-25 13:32:29 UTC (rev 40367)
@@ -407,7 +407,7 @@
 
         copy = locationCopy(obj)
         copy.__parent__ = copy.__name__ = None
-        notify(ObjectCopiedEvent(copy))
+        notify(ObjectCopiedEvent(copy, obj))
 
         target[new_name] = copy
         return new_name
@@ -699,7 +699,7 @@
 
     When we notify that our root object has been copied:
 
-      >>> notify(ObjectCopiedEvent(c))
+      >>> notify(ObjectCopiedEvent(c, L('')))
 
     we see that our handler has seen all of the subobjects:
 

Modified: Zope3/trunk/src/zope/app/event/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/event/interfaces.py	2005-11-25 13:21:13 UTC (rev 40366)
+++ Zope3/trunk/src/zope/app/event/interfaces.py	2005-11-25 13:32:29 UTC (rev 40367)
@@ -39,7 +39,9 @@
 class IObjectCopiedEvent(IObjectCreatedEvent):
     """An object has been copied"""
 
+    original = Attribute("The original from which the copy was made")
 
+
 class IObjectModifiedEvent(IObjectEvent):
     """An object has been modified"""
 

Modified: Zope3/trunk/src/zope/app/event/objectevent.py
===================================================================
--- Zope3/trunk/src/zope/app/event/objectevent.py	2005-11-25 13:21:13 UTC (rev 40366)
+++ Zope3/trunk/src/zope/app/event/objectevent.py	2005-11-25 13:32:29 UTC (rev 40367)
@@ -175,7 +175,18 @@
 
     implements(IObjectCopiedEvent)
 
+    def __init__(self, object, original=None):
+        super(ObjectCopiedEvent, self).__init__(object)
+        self.original = original
+        # BBB goes away in 3.3
+        if original is None:
+            warnings.warn(
+                "%s with no original is deprecated and will no-longer "
+                "be supported starting in Zope 3.3."
+                % self.__class__.__name__,
+                DeprecationWarning, stacklevel=2)
 
+
 def objectEventNotify(event):
     """Event subscriber to dispatch ObjectEvents to interested adapters."""
     adapters = subscribers((event.object, event), None)



More information about the Zope3-Checkins mailing list