Exemplo n.º 1
0
    def test_subscribe(self, root, db_session):

        from kotti.events import ObjectEvent
        from kotti.events import clear
        from kotti.events import listeners
        from kotti.events import objectevent_listeners
        from kotti.events import subscribe
        from kotti.resources import Document

        def handler(event):
            pass

        dec = subscribe()
        dec.venusian = DummyVenusian()
        decorated = dec(handler)
        dec.register(None, None, handler)
        assert dec.evttype is object
        assert dec.objtype is None
        assert decorated == handler
        assert (handler, dec.register, 'kotti') in dec.venusian.attached
        assert handler in listeners[object]
        assert handler not in objectevent_listeners[object]

        clear()

        dec = subscribe(ObjectEvent)
        dec.venusian = DummyVenusian()
        decorated = dec(handler)
        dec.register(None, None, handler)
        assert dec.evttype is ObjectEvent
        assert dec.objtype is None
        assert decorated == handler
        assert (handler, dec.register, 'kotti') in dec.venusian.attached
        assert handler not in listeners[ObjectEvent]
        assert handler in objectevent_listeners[(ObjectEvent, None)]

        clear()

        dec = subscribe(ObjectEvent, Document)
        dec.venusian = DummyVenusian()
        decorated = dec(handler)
        dec.register(None, None, handler)
        assert dec.evttype is ObjectEvent
        assert dec.objtype is Document
        assert decorated == handler
        assert (handler, dec.register, 'kotti') in dec.venusian.attached
        assert handler not in listeners[ObjectEvent]
        assert handler in objectevent_listeners[(ObjectEvent, Document)]
Exemplo n.º 2
0
    def test_subscribe(self, root, db_session):

        from kotti.events import ObjectEvent
        from kotti.events import clear
        from kotti.events import listeners
        from kotti.events import objectevent_listeners
        from kotti.events import subscribe
        from kotti.resources import Document

        def handler(event):
            pass

        dec = subscribe()
        dec.venusian = DummyVenusian()
        decorated = dec(handler)
        dec.register(None, None, handler)
        assert dec.evttype is object
        assert dec.objtype is None
        assert decorated == handler
        assert (handler, dec.register, 'kotti') in dec.venusian.attached
        assert handler in listeners[object]
        assert handler not in objectevent_listeners[object]

        clear()

        dec = subscribe(ObjectEvent)
        dec.venusian = DummyVenusian()
        decorated = dec(handler)
        dec.register(None, None, handler)
        assert dec.evttype is ObjectEvent
        assert dec.objtype is None
        assert decorated == handler
        assert (handler, dec.register, 'kotti') in dec.venusian.attached
        assert handler not in listeners[ObjectEvent]
        assert handler in objectevent_listeners[(ObjectEvent, None)]

        clear()

        dec = subscribe(ObjectEvent, Document)
        dec.venusian = DummyVenusian()
        decorated = dec(handler)
        dec.register(None, None, handler)
        assert dec.evttype is ObjectEvent
        assert dec.objtype is Document
        assert decorated == handler
        assert (handler, dec.register, 'kotti') in dec.venusian.attached
        assert handler not in listeners[ObjectEvent]
        assert handler in objectevent_listeners[(ObjectEvent, Document)]