예제 #1
0
def testRegisterRetrieveAndRemoveMediator():
    """FacadeTest: Test register_mediator() retrieve_mediator() and remove_mediator()"""
    fcde = Facade('test')
    fcde.register_mediator(Mediator(view_component=object()))
    ok_(fcde.retrieve_mediator('Mediator') is not None)

    removedMediator = fcde.remove_mediator('Mediator')
    eq_(removedMediator.get_mediator_name(), 'Mediator')
    ok_(fcde.retrieve_mediator(Mediator.NAME) is None)
예제 #2
0
def test_macro_command_send_notification():
    class TestCommand(SimpleCommand):
        def execute(self, note):
            self.facade.send_notification('TEST_NOTIFICATION')

    class TestMacroCommand(MacroCommand):
        def initialize_macro_command(self):
            self.sub_commands.append(TestCommand)

    class TestMediator(Mediator):
        _test_var = None
        def list_notification_interests(self):
            return ['TEST_NOTIFICATION']

        def handle_notification(self, note):
            if note.get_name() == 'TEST_NOTIFICATION':
               self._test_var = 10


    facade = Facade('test_command_send_notification')
    facade.register_command('COMMAND', TestMacroCommand)
    facade.register_mediator(TestMediator())

    facade.send_notification('COMMAND')
    eq_(facade.retrieve_mediator('TestMediator')._test_var, 10)