Ejemplo n.º 1
0
    def testConstructor(self):
        """NotificationTest: Test Constructor"""
        note = Notification('TestNote', 5, 'TestNoteType')

        self.assertEqual(True, note.getName() == 'TestNote')
        self.assertEqual(True, note.getBody() == 5)
        self.assertEqual(True, note.getType() == 'TestNoteType')
    def testConstructor(self):
        """NotificationTest: Test Constructor"""
        note = Notification('TestNote', 5, 'TestNoteType')

        self.assertEqual(True, note.getName() == 'TestNote')
        self.assertEqual(True, note.getBody() == 5)
        self.assertEqual(True, note.getType() == 'TestNoteType')
Ejemplo n.º 3
0
    def testBodyAccessors(self):
        """NotificationTest: Test Body Accessors"""

        note = Notification(None)
        note.setBody(5)

        self.assertEqual(True, note.getBody() == 5)
    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.getInstance(self.KEY1)

        view.registerMediator(ViewTestMediator5(self))

        # Try to register another instance of that mediator
        # (uses the same NAME constant).
        view.registerMediator(ViewTestMediator5(self))

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

        view.removeMediator(ViewTestMediator5.NAME)

        self.assertEqual(view.retrieveMediator(ViewTestMediator5.NAME), None)

        self.counter = 0
        view.notifyObservers(Notification(self.NOTE5))
        self.assertEqual(0, self.counter)
    def testBodyAccessors(self):
        """NotificationTest: Test Body Accessors"""

        note = Notification(None)
        note.setBody(5)

        self.assertEqual(True, note.getBody() == 5)
Ejemplo n.º 6
0
    def testObserverConstructor(self):
        """ObserverTest: Test Observer Constructor"""

        obsrvr = Observer(self.__observerTestMethod, self)

        note = Notification('ObserverTestNote', 5)
        obsrvr.notifyObserver(note)

        self.assertEqual(True, self.__observerTestVar == 5)
    def testRemoveSelf(self):
        view = View.getInstance(self.KEY1)

        view.registerMediator(ViewTestMediator2(self))
        view.registerMediator(ViewTestMediator3(self))

        self.assertTrue(self.NOTE5 in view.observerMap)
        view.notifyObservers(Notification(self.NOTE5))
        self.assertFalse(self.NOTE5 in view.observerMap)
Ejemplo n.º 8
0
    def testSimpleCommandExecute(self):
        """CommandTest: Test SimpleCommand execute()"""

        vo = SimpleCommandTestVO(5)
        note = Notification('SimpleCommandTestNote', vo)
        command = SimpleCommandTestCommand()
        command.execute(note)

        self.assertEqual(True, vo.result == 10)
Ejemplo n.º 9
0
    def testMacroCommandExecute(self):
        """CommandTest: Test MacroCommand execute()"""

        vo = MacroCommandTestVO(5)
        note = Notification('MacroCommandTest', vo)
        command = MacroCommandTestCommand()
        command.execute(note)

        self.assertEqual(True, vo.result1 == 10)
        self.assertEqual(True, vo.result2 == 25)
Ejemplo n.º 10
0
    def testReprAttribute(self):
        """ObserverTest: test __repr__()"""
        obj1 = object()
        obj2 = object()

        self.assertEqual(
            repr(Notification('ObserverTestNote',
                              None)), "Notification Name: ObserverTestNote" +
            "\nBody:None" + "\nType:None")
        self.assertEqual(
            repr(Notification('ObserverTestNote', 1, 2)),
            "Notification Name: ObserverTestNote" + "\nBody:1" + "\nType:2")
        self.assertEqual(
            repr(Notification('ObserverTestNote', "aaa",
                              "bbb")), "Notification Name: ObserverTestNote" +
            "\nBody:" + repr("aaa") + "\nType:" + repr("bbb"))
        self.assertEqual(
            repr(Notification('ObserverTestNote', obj1,
                              obj2)), "Notification Name: ObserverTestNote" +
            "\nBody:" + repr(obj1) + "\nType:" + repr(obj2))
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
    def testObserverAccessors(self):
        """ObserverTest: Test Observer Accessors"""

        obsrvr = Observer(None, None)
        obsrvr.setNotifyContext(self)

        obsrvr.setNotifyMethod(self.__observerTestMethod)

        note = Notification('ObserverTestNote', 10)
        obsrvr.notifyObserver(note)

        self.assertEqual(True, self.__observerTestVar == 10)
    def testRemoveOneOfTwoMediatorsAndSubsequentNotify(self):
        """ViewTest: Test removing one of two Mediators and subsequent notify()
        """

        view = View.getInstance(self.KEY1)

        view.registerMediator(ViewTestMediator2(self))

        view.registerMediator(ViewTestMediator3(self))

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

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

        view.notifyObservers(Notification(self.NOTE3))
        self.assertEqual(True, self.lastNotification == self.NOTE3)

        view.removeMediator(ViewTestMediator2.NAME)

        self.assertEqual(view.retrieveMediator(ViewTestMediator2.NAME), None)

        self.lastNotification = None

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

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

        view.notifyObservers(Notification(self.NOTE3))
        self.assertEqual(True, self.lastNotification == self.NOTE3)
 def __init__(self, anme, body):
     Notification.__init__(self, ViewTestNote.NAME, body)
Ejemplo n.º 15
0
    def testNameAccessors(self):
        """NotificationTest: Test Name Accessors"""

        note = Notification('TestNote')

        self.assertEqual(True, note.getName() == 'TestNote')
    def testNameAccessors(self):
        """NotificationTest: Test Name Accessors"""

        note = Notification('TestNote')

        self.assertEqual(True, note.getName() == 'TestNote')