Exemple #1
0
    def test_pop_success(self):
        from repoze.folder.interfaces import IObjectEvent
        from repoze.folder.interfaces import IObjectRemovedEvent
        from repoze.folder.interfaces import IObjectWillBeRemovedEvent
        dummy = DummyModel()
        dummy.__parent__ = None
        dummy.__name__ = None
        events = []

        def listener(object, event):
            events.append(event)

        self._registerEventListener(listener, IObjectEvent)
        folder = self._makeOne({'a': dummy})
        result = folder.pop('a')
        self.assertEqual(result, dummy)
        self.assertEqual(folder._num_objects(), 0)
        self.assertEqual(len(events), 2)
        self.failUnless(IObjectWillBeRemovedEvent.providedBy(events[0]))
        self.failUnless(IObjectRemovedEvent.providedBy(events[1]))
        self.assertEqual(events[0].object, dummy)
        self.assertEqual(events[0].parent, folder)
        self.assertEqual(events[0].name, 'a')
        self.assertEqual(events[1].object, dummy)
        self.assertEqual(events[1].parent, folder)
        self.assertEqual(events[1].name, 'a')
        self.failIf(hasattr(dummy, '__parent__'))
        self.failIf(hasattr(dummy, '__name__'))
Exemple #2
0
    def test_remove_send_events(self):
        from repoze.folder.interfaces import IObjectEvent
        from repoze.folder.interfaces import IObjectRemovedEvent
        from repoze.folder.interfaces import IObjectWillBeRemovedEvent
        events = []

        def listener(object, event):
            events.append(event)

        self._registerEventListener(listener, IObjectEvent)
        dummy = DummyModel()
        dummy.__parent__ = None
        dummy.__name__ = None
        folder = self._makeOne({'a': dummy})
        self.assertEqual(folder._num_objects(), 1)
        folder.remove('a', send_events=True)
        self.assertEqual(folder._num_objects(), 0)
        self.assertEqual(len(events), 2)
        self.failUnless(IObjectWillBeRemovedEvent.providedBy(events[0]))
        self.failUnless(IObjectRemovedEvent.providedBy(events[1]))
        self.assertEqual(events[0].object, dummy)
        self.assertEqual(events[0].parent, folder)
        self.assertEqual(events[0].name, 'a')
        self.assertEqual(events[1].object, dummy)
        self.assertEqual(events[1].parent, folder)
        self.assertEqual(events[1].name, 'a')
        self.failIf(hasattr(dummy, '__parent__'))
        self.failIf(hasattr(dummy, '__name__'))
Exemple #3
0
 def test_pop_success(self):
     from repoze.folder.interfaces import IObjectEvent
     from repoze.folder.interfaces import IObjectRemovedEvent
     from repoze.folder.interfaces import IObjectWillBeRemovedEvent
     dummy = DummyModel()
     dummy.__parent__ = None
     dummy.__name__ = None
     events = []
     def listener(object, event):
         events.append(event)
     self._registerEventListener(listener, IObjectEvent)
     folder = self._makeOne({'a':dummy})
     result = folder.pop('a')
     self.assertEqual(result, dummy)
     self.assertEqual(folder._num_objects(), 0)
     self.assertEqual(len(events), 2)
     self.assertTrue(IObjectWillBeRemovedEvent.providedBy(events[0]))
     self.assertTrue(IObjectRemovedEvent.providedBy(events[1]))
     self.assertEqual(events[0].object, dummy)
     self.assertEqual(events[0].parent, folder)
     self.assertEqual(events[0].name, 'a')
     self.assertEqual(events[1].object, dummy)
     self.assertEqual(events[1].parent, folder)
     self.assertEqual(events[1].name, 'a')
     self.assertFalse(hasattr(dummy, '__parent__'))
     self.assertFalse(hasattr(dummy, '__name__'))
Exemple #4
0
    def test_remove_send_events(self):
        from repoze.folder.interfaces import IObjectEvent
        from repoze.folder.interfaces import IObjectRemovedEvent
        from repoze.folder.interfaces import IObjectWillBeRemovedEvent
        events = []

        def listener(object, event):
            events.append(event)

        self._registerEventListener(listener, IObjectEvent)
        dummy = DummyModel()
        dummy.__parent__ = None
        dummy.__name__ = None
        folder = self._makeOne({'a': dummy})
        self.assertEqual(folder._num_objects(), 1)
        folder.remove('a', send_events=True)
        self.assertEqual(folder._num_objects(), 0)
        self.assertEqual(len(events), 2)
        self.assertTrue(IObjectWillBeRemovedEvent.providedBy(events[0]))
        self.assertTrue(IObjectRemovedEvent.providedBy(events[1]))
        self.assertEqual(events[0].object, dummy)
        self.assertEqual(events[0].parent, folder)
        self.assertEqual(events[0].name, 'a')
        self.assertEqual(events[1].object, dummy)
        self.assertEqual(events[1].parent, folder)
        self.assertEqual(events[1].name, 'a')
        self.assertFalse(hasattr(dummy, '__parent__'))
        self.assertFalse(hasattr(dummy, '__name__'))