def test_handling_closing_connection(self): slave = Slave() msg = Message() slave.layout = Mock(PresentationLayout) with patch.object(slave.layout, "reset_presentation") as mock: msg.set_field("command", Command.DROP_CONNECTION.value) slave.handle_message(msg) mock.assert_called_with()
def test_handling_show_next(self): slave = Slave(Mock(PresentationLayout)) slave.set_presentation(self.createPresentation()) msg = Message() msg.set_field(MessageKeys.type_key, "command") msg.set_field(MessageKeys.command_key, Command.SHOW_NEXT.value) response = slave.handle_message(msg) self.assertEqual(response.get_field(MessageKeys.response_key), Command.SHOW_NEXT.value)
def test_handling_ending_presentation(self): slave = Slave() slave.presentation.set_files(["suck", "on", "this"]) msg = Message() slave.layout = Mock(PresentationLayout) with patch.object(slave.layout, "reset_presentation") as mock: msg.set_field("command", Command.END_PRESENTATION.value) response = slave.handle_message(msg) self.assertEqual(response.get_field("responseTo"), Command.END_PRESENTATION.value) mock.assert_called_with()
def create_servicemode(self, layout, is_master): """ Creates a new service object and sets it in the self.servicemode layout: the layout to bind with self.servicemode """ if is_master: new_master = Master(layout) self.set_servicemode(new_master, True) empty_project = Project() # Uncomment to test # empty_project.create_test_presentation() new_master.setup_project(empty_project) new_master.load_project_to_gui() else: new_slave = Slave(layout) tcp_port = self.config.getint('tcp port') new_slave.set_master_connection(RemuTCP(new_slave, port=tcp_port)) self.set_servicemode(new_slave, False)
def test_handling_show_next_resetting_presentation(self): slave = Slave() slave.set_presentation(self.createPresentation()) slave.presentation.load() for i in range(0, len(slave.presentation.get_presentation_content())): slave.presentation.get_next() msg = Message() slave.layout = Mock(PresentationLayout) with patch.object(slave.layout, "reset_presentation") as mock: msg.set_field(MessageKeys.command_key, Command.SHOW_NEXT.value) response = slave.handle_message(msg) self.assertEqual(response.get_field(MessageKeys.response_key), Command.SHOW_NEXT.value) mock.assert_called_with()
def test_handling_empty_messages(self): slave = Slave() msg = Message() response = slave.handle_message(msg) self.assertEqual(response.get_field(MessageKeys.response_key), Command.INVALID_COMMAND.value)
def test_handling_invalid_commands(self): slave = Slave() msg = Message() msg.set_field(MessageKeys.command_key, "SHOWUSWHATYOU'VEGOT") response = slave.handle_message(msg) self.assertEqual(response.get_field(MessageKeys.response_key), Command.INVALID_COMMAND.value)
def test_init_with_layout(self): mock = Mock(PresentationLayout) slave = Slave(mock) self.assertEqual(slave.layout, mock)
def test_set_presentation(self): slave = Slave() slave.set_presentation(Presentation()) self.assertEqual(slave.presentation.__class__.__name__, "Presentation")
def setUp(self): self.slave = Slave() self.slave.presentation.set_source_folder(PathConstants.TEST_MEDIA_FOLDER)