Skip to content

Commit

Permalink
Merge pull request #2 from icemac/master
Browse files Browse the repository at this point in the history
moved function tried to notify the wrong event
  • Loading branch information
Michael Howitz committed Aug 27, 2013
2 parents ccbe1a1 + c5bbbf8 commit 6634b4b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CHANGES
implementation of ``ObjectEvent`` is now in ``zope.interface``.
Retained the dependency for the tests.

- ...
- Fixed: ``.moved`` tried to notify the wrong event.


4.0.2 (2013-03-08)
Expand Down
2 changes: 1 addition & 1 deletion src/zope/lifecycleevent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__(self, object, oldParent, oldName, newParent, newName):


def moved(object, oldParent, oldName, newParent, newName):
notify(ObjectCreatedEvent(object, oldParent, oldName, newParent, newName))
notify(ObjectMovedEvent(object, oldParent, oldName, newParent, newName))


@implementer(IObjectAddedEvent)
Expand Down
34 changes: 34 additions & 0 deletions src/zope/lifecycleevent/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,39 @@ def test_verifyObject(self):
verifyObject(IObjectRemovedEvent, self._makeOne(ob, parent, 'new_name'))


class DummySubscriber:

event = None

def __call__(self, event):
self.event = event


class TestMoved(unittest.TestCase):
"""Testing .moved()."""

def setUp(self):
from zope.event import subscribers
self._old_subscribers = subscribers[:]
subscribers[:] = [DummySubscriber()]

def tearDown(self):
from zope.event import subscribers
subscribers[:] = self._old_subscribers

def test_it(self):
from zope.lifecycleevent import moved, ObjectMovedEvent
from zope.event import subscribers
moved('object', 'oldParent', 'oldName', 'newParent', 'newName')
event = subscribers[0].event
self.assertTrue(isinstance(event, ObjectMovedEvent))
self.assertEqual(event.object, 'object')
self.assertEqual(event.oldParent, 'oldParent')
self.assertEqual(event.oldName, 'oldName')
self.assertEqual(event.newParent, 'newParent')
self.assertEqual(event.newName, 'newName')


class Context:
pass

Expand All @@ -276,6 +309,7 @@ def test_suite():
unittest.makeSuite(TestObjectMovedEvent),
unittest.makeSuite(TestObjectAddedEvent),
unittest.makeSuite(TestObjectRemovedEvent),
unittest.makeSuite(TestMoved),
doctest.DocFileSuite('README.txt',
tearDown=zope.component.testing.tearDown),
))
Expand Down

0 comments on commit 6634b4b

Please sign in to comment.