Example #1
0
    def testMediatorReregistration(self):
        """
        Tests registering the same mediator twice.
        A subsequent notification should only illicit
        one response. Also, since reregistration
        was causing 2 observers to be created, ensure
        that after removal of the mediator there will
        be no further response.

        Added for the fix deployed in version 2.0.4
        """

        view = View('test')

        view.register_mediator(utils.view.ViewTestMediator5(self))

        # try to register another instance of that mediator (uses the same NAME constant).
        view.register_mediator(utils.view.ViewTestMediator5(self))

        self.counter = 0
        view.notify_observers(Notification(self.NOTE5))
        self.assertEqual(1, self.counter)

        view.remove_mediator(utils.view.ViewTestMediator5.NAME)

        self.assertEqual(True, view.retrieve_mediator(utils.view.ViewTestMediator5.NAME ) is None)

        self.counter=0
        view.notify_observers(Notification(self.NOTE5))
        self.assertEqual(0,  self.counter)
Example #2
0
    def testRemoveSelf(self):
        view = View('test')
        view.register_mediator(utils.view.ViewTestMediator2(self))
        view.register_mediator(utils.view.ViewTestMediator3(self))

        self.assertTrue(self.NOTE5 in view.observer_map)
        view.notify_observers(Notification(self.NOTE5))
        self.assertFalse(self.NOTE5 in view.observer_map)
Example #3
0
    def testRemoveMediatorAndSubsequentNotify(self):
        """ViewTest: Test remove_mediator() and subsequent nofity()"""

        view = View('test')

        view.register_mediator(utils.view.ViewTestMediator2(self))

        view.notify_observers(Notification(self.NOTE1))
        self.assertEqual(True, self.lastNotification == self.NOTE1)

        view.notify_observers(Notification(self.NOTE2))
        self.assertEqual(True, self.lastNotification == self.NOTE2)

        view.remove_mediator(utils.view.ViewTestMediator2.NAME)

        self.assertEqual(True, view.retrieve_mediator(utils.view.ViewTestMediator2.NAME) is None)

        self.lastNotification = None

        view.notify_observers(Notification(self.NOTE1))
        self.assertEqual(True, self.lastNotification != self.NOTE1)

        view.notify_observers(Notification(self.NOTE2))
        self.assertEqual(True, self.lastNotification != self.NOTE2)

        self.__cleanup()
Example #4
0
    def testRegisterAndNotifyObserver(self):
        """ViewTest: Test register_observer() and notify_observers()"""

        self.viewTestVar = 0
        def viewTestMethod(note):
            self.viewTestVar = note.get_body()

        view = View('test')
        obsvr = Observer(viewTestMethod, self)
        view.register_observer(utils.view.ViewTestNote.NAME, obsvr)

        note = utils.view.ViewTestNote.create(10)
        view.notify_observers(note)

        self.assertEqual(True, self.viewTestVar == 10)