Commit 0dc86d01 authored by Stefan H. Holek's avatar Stefan H. Holek

Merged trunk r74108:74109 into 2.10 branch.

Repair (and simplify) tests in response to
http://www.zope.org/Collectors/Zope/2308.
parent 5b304f82
...@@ -15,15 +15,7 @@ from OFS.Folder import Folder ...@@ -15,15 +15,7 @@ from OFS.Folder import Folder
from zope import interface from zope import interface
from zope import component from zope import component
from zope.app.container.interfaces import IObjectAddedEvent from zope.component.interfaces import IObjectEvent
from zope.app.container.interfaces import IObjectMovedEvent
from zope.app.container.interfaces import IObjectRemovedEvent
from zope.app.container.interfaces import IContainerModifiedEvent
from zope.lifecycleevent.interfaces import IObjectCopiedEvent
from OFS.interfaces import IObjectWillBeAddedEvent
from OFS.interfaces import IObjectWillBeMovedEvent
from OFS.interfaces import IObjectWillBeRemovedEvent
from OFS.interfaces import IObjectClonedEvent
from zope.testing import cleanup from zope.testing import cleanup
from Products.Five import zcml from Products.Five import zcml
...@@ -35,7 +27,7 @@ class EventLogger(object): ...@@ -35,7 +27,7 @@ class EventLogger(object):
def reset(self): def reset(self):
self._called = [] self._called = []
def trace(self, ob, event): def trace(self, ob, event):
self._called.append((ob.getId(), event)) self._called.append((ob.getId(), event.__class__.__name__))
def called(self): def called(self):
return self._called return self._called
...@@ -62,57 +54,6 @@ class TestFolder(Folder): ...@@ -62,57 +54,6 @@ class TestFolder(Folder):
pass # Always allow pass # Always allow
def objectAddedEvent(ob, event):
eventlog.trace(ob, 'ObjectAddedEvent')
def objectCopiedEvent(ob, event):
eventlog.trace(ob, 'ObjectCopiedEvent')
def objectMovedEvent(ob, event):
if IObjectAddedEvent.providedBy(event):
return
if IObjectRemovedEvent.providedBy(event):
return
eventlog.trace(ob, 'ObjectMovedEvent')
def objectRemovedEvent(ob, event):
eventlog.trace(ob, 'ObjectRemovedEvent')
def containerModifiedEvent(ob, event):
eventlog.trace(ob, 'ContainerModifiedEvent')
def objectWillBeAddedEvent(ob, event):
eventlog.trace(ob, 'ObjectWillBeAddedEvent')
def objectWillBeMovedEvent(ob, event):
if IObjectWillBeAddedEvent.providedBy(event):
return
if IObjectWillBeRemovedEvent.providedBy(event):
return
eventlog.trace(ob, 'ObjectWillBeMovedEvent')
def objectWillBeRemovedEvent(ob, event):
eventlog.trace(ob, 'ObjectWillBeRemovedEvent')
def objectClonedEvent(ob, event):
eventlog.trace(ob, 'ObjectClonedEvent')
def setUpItemSubscribers(interface):
component.provideHandler(objectAddedEvent, (interface, IObjectAddedEvent))
component.provideHandler(objectCopiedEvent, (interface, IObjectCopiedEvent))
component.provideHandler(objectMovedEvent, (interface, IObjectMovedEvent))
component.provideHandler(objectRemovedEvent, (interface, IObjectRemovedEvent))
component.provideHandler(objectWillBeAddedEvent, (interface, IObjectWillBeAddedEvent))
component.provideHandler(objectWillBeMovedEvent, (interface, IObjectWillBeMovedEvent))
component.provideHandler(objectWillBeRemovedEvent, (interface, IObjectWillBeRemovedEvent))
component.provideHandler(objectClonedEvent, (interface, IObjectClonedEvent))
def setUpFolderSubscribers(interface):
setUpItemSubscribers(interface)
component.provideHandler(containerModifiedEvent, (interface, IContainerModifiedEvent))
class EventLayer: class EventLayer:
@classmethod @classmethod
...@@ -120,8 +61,8 @@ class EventLayer: ...@@ -120,8 +61,8 @@ class EventLayer:
cleanup.cleanUp() cleanup.cleanUp()
zcml._initialized = 0 zcml._initialized = 0
zcml.load_site() zcml.load_site()
setUpItemSubscribers(ITestItem) component.provideHandler(eventlog.trace, (ITestItem, IObjectEvent))
setUpFolderSubscribers(ITestFolder) component.provideHandler(eventlog.trace, (ITestFolder, IObjectEvent))
@classmethod @classmethod
def tearDown(cls): def tearDown(cls):
...@@ -271,19 +212,26 @@ class TestCopySupportSublocation(EventTest): ...@@ -271,19 +212,26 @@ class TestCopySupportSublocation(EventTest):
# Reset event log # Reset event log
eventlog.reset() eventlog.reset()
def assertEqual(self, first, second, msg=None):
# XXX: Compare sets as the order of event handlers cannot be
# relied on between objects.
if not set(first) == set(second):
raise self.failureException, \
(msg or '%r != %r' % (first, second))
def test_1_Clone(self): def test_1_Clone(self):
# Test clone # Test clone
self.subfolder.manage_clone(self.folder.myfolder, 'myfolder') self.subfolder.manage_clone(self.folder.myfolder, 'myfolder')
self.assertEqual(eventlog.called(), self.assertEqual(eventlog.called(),
[#('mydoc', 'ObjectCopiedEvent'), [('myfolder', 'ObjectCopiedEvent'),
('myfolder', 'ObjectCopiedEvent'), #('mydoc', 'ObjectCopiedEvent'),
('mydoc', 'ObjectWillBeAddedEvent'),
('myfolder', 'ObjectWillBeAddedEvent'), ('myfolder', 'ObjectWillBeAddedEvent'),
('mydoc', 'ObjectAddedEvent'), ('mydoc', 'ObjectWillBeAddedEvent'),
('myfolder', 'ObjectAddedEvent'), ('myfolder', 'ObjectAddedEvent'),
('mydoc', 'ObjectAddedEvent'),
('subfolder', 'ContainerModifiedEvent'), ('subfolder', 'ContainerModifiedEvent'),
('mydoc', 'ObjectClonedEvent'), ('myfolder', 'ObjectClonedEvent'),
('myfolder', 'ObjectClonedEvent')] ('mydoc', 'ObjectClonedEvent')]
) )
def test_2_CopyPaste(self): def test_2_CopyPaste(self):
...@@ -291,15 +239,15 @@ class TestCopySupportSublocation(EventTest): ...@@ -291,15 +239,15 @@ class TestCopySupportSublocation(EventTest):
cb = self.folder.manage_copyObjects(['myfolder']) cb = self.folder.manage_copyObjects(['myfolder'])
self.subfolder.manage_pasteObjects(cb) self.subfolder.manage_pasteObjects(cb)
self.assertEqual(eventlog.called(), self.assertEqual(eventlog.called(),
[#('mydoc', 'ObjectCopiedEvent'), [('myfolder', 'ObjectCopiedEvent'),
('myfolder', 'ObjectCopiedEvent'), #('mydoc', 'ObjectCopiedEvent'),
('mydoc', 'ObjectWillBeAddedEvent'),
('myfolder', 'ObjectWillBeAddedEvent'), ('myfolder', 'ObjectWillBeAddedEvent'),
('mydoc', 'ObjectAddedEvent'), ('mydoc', 'ObjectWillBeAddedEvent'),
('myfolder', 'ObjectAddedEvent'), ('myfolder', 'ObjectAddedEvent'),
('mydoc', 'ObjectAddedEvent'),
('subfolder', 'ContainerModifiedEvent'), ('subfolder', 'ContainerModifiedEvent'),
('mydoc', 'ObjectClonedEvent'), ('myfolder', 'ObjectClonedEvent'),
('myfolder', 'ObjectClonedEvent')] ('mydoc', 'ObjectClonedEvent')]
) )
def test_3_CutPaste(self): def test_3_CutPaste(self):
...@@ -307,10 +255,10 @@ class TestCopySupportSublocation(EventTest): ...@@ -307,10 +255,10 @@ class TestCopySupportSublocation(EventTest):
cb = self.folder.manage_cutObjects(['myfolder']) cb = self.folder.manage_cutObjects(['myfolder'])
self.subfolder.manage_pasteObjects(cb) self.subfolder.manage_pasteObjects(cb)
self.assertEqual(eventlog.called(), self.assertEqual(eventlog.called(),
[('mydoc', 'ObjectWillBeMovedEvent'), [('myfolder', 'ObjectWillBeMovedEvent'),
('myfolder', 'ObjectWillBeMovedEvent'), ('mydoc', 'ObjectWillBeMovedEvent'),
('mydoc', 'ObjectMovedEvent'),
('myfolder', 'ObjectMovedEvent'), ('myfolder', 'ObjectMovedEvent'),
('mydoc', 'ObjectMovedEvent'),
('folder', 'ContainerModifiedEvent'), ('folder', 'ContainerModifiedEvent'),
('subfolder', 'ContainerModifiedEvent')] ('subfolder', 'ContainerModifiedEvent')]
) )
...@@ -319,10 +267,10 @@ class TestCopySupportSublocation(EventTest): ...@@ -319,10 +267,10 @@ class TestCopySupportSublocation(EventTest):
# Test rename # Test rename
self.folder.manage_renameObject('myfolder', 'yourfolder') self.folder.manage_renameObject('myfolder', 'yourfolder')
self.assertEqual(eventlog.called(), self.assertEqual(eventlog.called(),
[('mydoc', 'ObjectWillBeMovedEvent'), [('myfolder', 'ObjectWillBeMovedEvent'),
('myfolder', 'ObjectWillBeMovedEvent'), ('mydoc', 'ObjectWillBeMovedEvent'),
('mydoc', 'ObjectMovedEvent'),
('yourfolder', 'ObjectMovedEvent'), ('yourfolder', 'ObjectMovedEvent'),
('mydoc', 'ObjectMovedEvent'),
('folder', 'ContainerModifiedEvent')] ('folder', 'ContainerModifiedEvent')]
) )
...@@ -333,15 +281,15 @@ class TestCopySupportSublocation(EventTest): ...@@ -333,15 +281,15 @@ class TestCopySupportSublocation(EventTest):
req.environ['HTTP_DESTINATION'] = '%s/subfolder/myfolder' % self.folder.absolute_url() req.environ['HTTP_DESTINATION'] = '%s/subfolder/myfolder' % self.folder.absolute_url()
self.folder.myfolder.COPY(req, req.RESPONSE) self.folder.myfolder.COPY(req, req.RESPONSE)
self.assertEqual(eventlog.called(), self.assertEqual(eventlog.called(),
[#('mydoc', 'ObjectCopiedEvent'), [('myfolder', 'ObjectCopiedEvent'),
('myfolder', 'ObjectCopiedEvent'), #('mydoc', 'ObjectCopiedEvent'),
('mydoc', 'ObjectWillBeAddedEvent'),
('myfolder', 'ObjectWillBeAddedEvent'), ('myfolder', 'ObjectWillBeAddedEvent'),
('mydoc', 'ObjectAddedEvent'), ('mydoc', 'ObjectWillBeAddedEvent'),
('myfolder', 'ObjectAddedEvent'), ('myfolder', 'ObjectAddedEvent'),
('mydoc', 'ObjectAddedEvent'),
('subfolder', 'ContainerModifiedEvent'), ('subfolder', 'ContainerModifiedEvent'),
('mydoc', 'ObjectClonedEvent'), ('myfolder', 'ObjectClonedEvent'),
('myfolder', 'ObjectClonedEvent')] ('mydoc', 'ObjectClonedEvent')]
) )
def test_6_MOVE(self): def test_6_MOVE(self):
...@@ -351,10 +299,10 @@ class TestCopySupportSublocation(EventTest): ...@@ -351,10 +299,10 @@ class TestCopySupportSublocation(EventTest):
req.environ['HTTP_DESTINATION'] = '%s/subfolder/myfolder' % self.folder.absolute_url() req.environ['HTTP_DESTINATION'] = '%s/subfolder/myfolder' % self.folder.absolute_url()
self.folder.myfolder.MOVE(req, req.RESPONSE) self.folder.myfolder.MOVE(req, req.RESPONSE)
self.assertEqual(eventlog.called(), self.assertEqual(eventlog.called(),
[('mydoc', 'ObjectWillBeMovedEvent'), [('myfolder', 'ObjectWillBeMovedEvent'),
('myfolder', 'ObjectWillBeMovedEvent'), ('mydoc', 'ObjectWillBeMovedEvent'),
('mydoc', 'ObjectMovedEvent'),
('myfolder', 'ObjectMovedEvent'), ('myfolder', 'ObjectMovedEvent'),
('mydoc', 'ObjectMovedEvent'),
('folder', 'ContainerModifiedEvent'), ('folder', 'ContainerModifiedEvent'),
('subfolder', 'ContainerModifiedEvent')] ('subfolder', 'ContainerModifiedEvent')]
) )
...@@ -365,10 +313,10 @@ class TestCopySupportSublocation(EventTest): ...@@ -365,10 +313,10 @@ class TestCopySupportSublocation(EventTest):
req['URL'] = '%s/myfolder' % self.folder.absolute_url() req['URL'] = '%s/myfolder' % self.folder.absolute_url()
self.folder.myfolder.DELETE(req, req.RESPONSE) self.folder.myfolder.DELETE(req, req.RESPONSE)
self.assertEqual(eventlog.called(), self.assertEqual(eventlog.called(),
[('mydoc', 'ObjectWillBeRemovedEvent'), [('myfolder', 'ObjectWillBeRemovedEvent'),
('myfolder', 'ObjectWillBeRemovedEvent'), ('mydoc', 'ObjectWillBeRemovedEvent'),
('mydoc', 'ObjectRemovedEvent'),
('myfolder', 'ObjectRemovedEvent'), ('myfolder', 'ObjectRemovedEvent'),
('mydoc', 'ObjectRemovedEvent'),
('folder', 'ContainerModifiedEvent')] ('folder', 'ContainerModifiedEvent')]
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment