Exemple #1
0
    def testGetInstance(self):
        """ControllerTest: getInstance() with different keys"""
        self.assertNotEqual(self.KEY1, self.KEY2)

        controller1 = Controller.getInstance(self.KEY1)
        controller2 = Controller.getInstance(self.KEY2)

        self.assertNotEqual(controller1, controller2)
Exemple #2
0
    def removeCore(cls, key):
        """
        Remove a Core.

        Remove the Model, View, Controller and Facade instances for the given
        key.

        @param key: of the Core to remove
        """
        if cls.instanceMap.get(key):
            from puremvc.core import Controller, Model, View

            Model.removeModel(key)
            View.removeView(key)
            Controller.removeController(key)

            cls.instanceMap.pop(key)
    def removeCore(cls, key):
        """
        Remove a Core.

        Remove the Model, View, Controller and Facade instances for the given
        key.

        @param key: of the Core to remove
        """
        if cls.instanceMap.get(key):
            from puremvc.core import Controller, Model, View

            Model.removeModel(key)
            View.removeView(key)
            Controller.removeController(key)

            cls.instanceMap.pop(key)
Exemple #4
0
    def testRegisterAndExecuteCommand(self):
        """ControllerTest: Test registerCommand() and executeCommand()"""
        controller = Controller.getInstance(self.KEY1)

        controller.registerCommand('ControllerTest', TestDoubleCommand)

        vo = TestVO(12)
        note = Notification('ControllerTest', vo)

        controller.executeCommand(note)

        self.assertEqual(True, vo.result == 24)
Exemple #5
0
    def testHasCommand(self):
        """ControllerTest: Test hasCommand()"""
        # Create controllers
        controller1 = Controller.getInstance(self.KEY1)
        controller2 = Controller.getInstance(self.KEY2)

        # Register commands
        controller1.registerCommand('incrementCommand', TestIncrementCommand)
        controller2.registerCommand('doubleCommand', TestDoubleCommand)

        self.assertEqual(True, controller1.hasCommand('incrementCommand'))
        self.assertEqual(False, controller2.hasCommand('incrementCommand'))

        self.assertEqual(False, controller1.hasCommand('doubleCommand'))
        self.assertEqual(True, controller2.hasCommand('doubleCommand'))

        # Remove commands
        controller1.removeCommand('incrementCommand')
        controller2.removeCommand('doubleCommand')

        self.assertEqual(False, controller1.hasCommand('incrementCommand'))
        self.assertEqual(False, controller2.hasCommand('doubleCommand'))
Exemple #6
0
    def initializeController(self):
        """
        Initialize the C{Controller}.

        Called by the C{initializeFacade} method.
        Override this method in your subclass of C{Facade}
        if one or both of the following are true:

        You wish to initialize a different C{IController}.
        You have C{Commands} to register with the C{Controller} at startup.

        If you don't want to initialize a different C{IController},
        call C{super.initializeController()} at the beginning of your method, then register C{Proxy}s.

        Note: This method is <i>rarely<i> overridden; in practice you are more
        likely to use a C{Command} to create and register C{Proxy}s
        with the C{Model}, since C{Proxy}s with mutable data will likely
        need to send C{INotification}s and thus will likely want to fetch a reference to
        the C{Facade} during their construction.
        """
        if self.controller is None:
            from puremvc.core import Controller

            self.controller = Controller.getInstance(self.multitonKey)
    def initializeController(self):
        """
        Initialize the C{Controller}.

        Called by the C{initializeFacade} method.
        Override this method in your subclass of C{Facade}
        if one or both of the following are true:

        You wish to initialize a different C{IController}.
        You have C{Commands} to register with the C{Controller} at startup.

        If you don't want to initialize a different C{IController},
        call C{super.initializeController()} at the beginning of your method, then register C{Proxy}s.

        Note: This method is <i>rarely<i> overridden; in practice you are more
        likely to use a C{Command} to create and register C{Proxy}s
        with the C{Model}, since C{Proxy}s with mutable data will likely
        need to send C{INotification}s and thus will likely want to fetch a reference to
        the C{Facade} during their construction.
        """
        if self.controller is None:
            from puremvc.core import Controller

            self.controller = Controller.getInstance(self.multitonKey)
Exemple #8
0
    def testIsIController(self):
        """ControllerTest: Test instance implements IController"""
        controller = Controller.getInstance(self.KEY1)

        self.assertEqual(True, isinstance(controller, IController))
Exemple #9
0
    def testNotNone(self):
        """ControllerTest: Test instance not null"""
        controller = Controller.getInstance(self.KEY1)

        self.assertNotEqual(None, controller)
Exemple #10
0
    def testErrorSameKey(self):
        """ControllerTest: raise error if create controller with same key"""
        controller1 = Controller(self.KEY1)

        self.assertRaises(MultitonError, Controller, self.KEY1)
Exemple #11
0
    def testGetSameInstance(self):
        """ControllerTest: getInstance() with same key"""
        controller1 = Controller.getInstance(self.KEY1)
        controller2 = Controller.getInstance(self.KEY1)

        self.assertEqual(controller1, controller2)