Beispiel #1
0
    def setUp(self):
        """Sets up the fixture, for example, opens a network connection.
        This method is called before a test is executed.

        """

        self._event = Event()
        self._dispatcher = EventDispatcher()
 def testDispatch(self):
     self.dispatcher.addListener('pre.foo', [self.listener, 'preFoo']);
     self.dispatcher.addListener('post.foo', [self.listener, 'postFoo']);
     self.dispatcher.dispatch(self.preFoo);
     self.assertTrue(self.listener.preFooInvoked);
     self.assertFalse(self.listener.postFooInvoked);
     self.assertTrue(isinstance(self.dispatcher.dispatch('noevent'), Event));
     self.assertTrue(isinstance(self.dispatcher.dispatch(self.preFoo), Event));
     event = Event();
     ret = self.dispatcher.dispatch(self.preFoo, event);
     self.assertEqual('pre.foo', event.getName());
     self.assertTrue(event is ret);
 def testDispatch(self):
     self.dispatcher.addListener('pre.foo', [self.listener, 'preFoo'])
     self.dispatcher.addListener('post.foo', [self.listener, 'postFoo'])
     self.dispatcher.dispatch(self.preFoo)
     self.assertTrue(self.listener.preFooInvoked)
     self.assertFalse(self.listener.postFooInvoked)
     self.assertTrue(isinstance(self.dispatcher.dispatch('noevent'), Event))
     self.assertTrue(
         isinstance(self.dispatcher.dispatch(self.preFoo), Event))
     event = Event()
     ret = self.dispatcher.dispatch(self.preFoo, event)
     self.assertEqual('pre.foo', event.getName())
     self.assertTrue(event is ret)
Beispiel #4
0
    def testRemoveAfterDispatch(self):

        event = Event();

        service = Service();

        container = Container();
        container.set('service.listener', service);

        dispatcher = ContainerAwareEventDispatcher(container);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent']);

        dispatcher.dispatch('onEvent', Event());
        dispatcher.removeListener('onEvent', [container.get('service.listener'), 'onEvent']);
        self.assertFalse(dispatcher.hasListeners('onEvent'));
Beispiel #5
0
    def testReEnteringAScope(self):

        event = Event();

        service1 = Service();

        scope = Scope('scope');
        container = Container();
        container.addScope(scope);
        container.enterScope('scope');

        container.set('service.listener', service1, 'scope');

        dispatcher = ContainerAwareEventDispatcher(container);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent']);
        dispatcher.dispatch('onEvent', event);

        service2 = Service();

        container.enterScope('scope');
        container.set('service.listener', service2, 'scope');

        dispatcher.dispatch('onEvent', event);

        container.leaveScope('scope');

        dispatcher.dispatch('onEvent');
Beispiel #6
0
    def setUp(self):
        """Sets up the fixture, for example, opens a network connection.
        This method is called before a test is executed.

        """

        self._event = Event();
        self._dispatcher = EventDispatcher();
Beispiel #7
0
    def __init__(self, kernel, request, requestType):
        assert isinstance(request, Request);
        assert isinstance(kernel, ConsoleKernelInterface);

        Event.__init__(self);

        # The kernel in which this event was thrown
        # @var ConsoleKernelInterface
        self.__kernel = None;

        # The request the kernel is currently processing
        # @var Request
        self.__request = None;

        # The request type the kernel is currently processing.  One of
        # HttpKernelInterface.MASTER_REQUEST and HttpKernelInterface.SUB_REQUEST
        # @var integer
        self.__requestType = None;

        self.__kernel = kernel;
        self.__request = request;
        self.__requestType = requestType;
Beispiel #8
0
    def testAddASubscriberService(self):

        event = Event();

        service = SubscriberService();

        container = Container();
        container.set('service.subscriber', service);

        dispatcher = ContainerAwareEventDispatcher(container);
        dispatcher.addSubscriberService('service.subscriber', ReflectionClass(SubscriberService).getName());

        dispatcher.dispatch('onEvent', event);
Beispiel #9
0
    def __init__(self, kernel, request, requestType):
        assert isinstance(request, Request)
        assert isinstance(kernel, ConsoleKernelInterface)

        Event.__init__(self)

        # The kernel in which this event was thrown
        # @var ConsoleKernelInterface
        self.__kernel = None

        # The request the kernel is currently processing
        # @var Request
        self.__request = None

        # The request type the kernel is currently processing.  One of
        # HttpKernelInterface.MASTER_REQUEST and HttpKernelInterface.SUB_REQUEST
        # @var integer
        self.__requestType = None

        self.__kernel = kernel
        self.__request = request
        self.__requestType = requestType
Beispiel #10
0
    def testPreventDuplicateListenerService(self):

        event = Event();

        service = Service();

        container = Container();
        container.set('service.listener', service);

        dispatcher = ContainerAwareEventDispatcher(container);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent'], 5);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent'], 10);

        dispatcher.dispatch('onEvent', event);
Beispiel #11
0
    def testAddAListenerService(self):
        if self.__skip:
            return;

        event = Event();

        service = Service();

        container = Container();
        container.set('service.listener', service);

        dispatcher = ContainerAwareEventDispatcher(container);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent']);

        dispatcher.dispatch('onEvent', event);
Beispiel #12
0
    def testGetListenersOnLazyLoad(self):

        event = Event();

        service = Service();

        container = Container();
        container.set('service.listener', service);

        dispatcher = ContainerAwareEventDispatcher(container);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent']);

        listeners = dispatcher.getListeners();

        self.assertTrue('onEvent' in listeners);

        self.assertEqual(1, len(dispatcher.getListeners('onEvent')));
Beispiel #13
0
    def testHasListenersOnLazyLoad(self):

        event = Event();

        service = Service();

        container = Container();
        container.set('service.listener', service);

        dispatcher = ContainerAwareEventDispatcher(container);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent']);

        event.setDispatcher(dispatcher);
        event.setName('onEvent');

        self.assertTrue(dispatcher.hasListeners());

        if (dispatcher.hasListeners('onEvent')) :
            dispatcher.dispatch('onEvent');
Beispiel #14
0
class EventTest(unittest.TestCase):
    """Test class for Event.

    """

    def setUp(self):
        """Sets up the fixture, for example, opens a network connection.
        This method is called before a test is executed.

        """

        self._event = Event();
        self._dispatcher = EventDispatcher();


    def tearDown(self):
        """Tears down the fixture, for example, closes a network connection.
        This method is called after a test is executed.

        """

        self._event = None;
        self._eventDispatcher = None;


    def testIsPropagationStopped(self):

        self.assertFalse(self._event.isPropagationStopped());


    def testStopPropagationAndIsPropagationStopped(self):

        self._event.stopPropagation();
        self.assertTrue(self._event.isPropagationStopped());


    def testSetDispatcher(self):

        self._event.setDispatcher(self._dispatcher);
        self.assertEqual(self._dispatcher, self._event.getDispatcher());


    def testGetDispatcher(self):

        self.assertTrue(None is self._event.getDispatcher());


    def testGetName(self):

        self.assertTrue(None is self._event.getName());


    def testSetName(self):

        self._event.setName('foo');
        self.assertEqual('foo', self._event.getName());
Beispiel #15
0
class EventTest(unittest.TestCase):
    """Test class for Event.

    """
    def setUp(self):
        """Sets up the fixture, for example, opens a network connection.
        This method is called before a test is executed.

        """

        self._event = Event()
        self._dispatcher = EventDispatcher()

    def tearDown(self):
        """Tears down the fixture, for example, closes a network connection.
        This method is called after a test is executed.

        """

        self._event = None
        self._eventDispatcher = None

    def testIsPropagationStopped(self):

        self.assertFalse(self._event.isPropagationStopped())

    def testStopPropagationAndIsPropagationStopped(self):

        self._event.stopPropagation()
        self.assertTrue(self._event.isPropagationStopped())

    def testSetDispatcher(self):

        self._event.setDispatcher(self._dispatcher)
        self.assertEqual(self._dispatcher, self._event.getDispatcher())

    def testGetDispatcher(self):

        self.assertTrue(None is self._event.getDispatcher())

    def testGetName(self):

        self.assertTrue(None is self._event.getName())

    def testSetName(self):

        self._event.setName('foo')
        self.assertEqual('foo', self._event.getName())
Beispiel #16
0
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.

from __future__ import absolute_import

import unittest

from pymfony.component.event_dispatcher import EventDispatcherInterface
from pymfony.component.event_dispatcher import ImmutableEventDispatcher
from pymfony.component.event_dispatcher import Event
from pymfony.component.system.exception import BadMethodCallException
from pymfony.component.event_dispatcher import EventSubscriberInterface
"""
"""

EVENT = Event()


class ImmutableEventDispatcherTest(unittest.TestCase):
    """@author Bernhard Schussek <*****@*****.**>

    """
    def setUp(self):

        self._innerDispatcher = EventDispatcherInterfaceMock()
        self._dispatcher = ImmutableEventDispatcher(self._innerDispatcher)

    def testDispatchDelegates(self):

        self.assertEqual('result', self._dispatcher.dispatch('event', EVENT))