def test_add_service_item_without_song_edit(): """ Test the add_service_item() method when song_edit is False """ # GIVEN: A slide controller and a new item to add mocked_item = MagicMock() mocked_process_item = MagicMock() slide_controller = SlideController(None) slide_controller._process_item = mocked_process_item slide_controller.song_edit = False slide_controller.selected_row = 2 # WHEN: The item is added to the service slide_controller.add_service_item(mocked_item) # THEN: The item is processed, the slide number is correct, and the song is not editable (or something) assert slide_controller.song_edit is False, 'song_edit should be False' mocked_process_item.assert_called_once_with(mocked_item, 0)
def test_update_preview_image(self, mocked_singleShot, mocked_image_manager): """ Test that the preview screen is updated with the correct preview for image service items """ # GIVEN: A mocked image service item, a mocked image_manager, a mocked Registry, # and a slide controller with many mocks. # Mocked Image Item mocked_img_item = MagicMock() mocked_img_item.get_rendered_frame.return_value = '' mocked_img_item.is_capable = MagicMock() mocked_img_item.is_capable.side_effect = [False, True] # Mock image_manager mocked_image_manager.get_image.return_value = QtGui.QImage() # Mock Registry Registry.create() mocked_main_window = MagicMock() Registry().register('main_window', mocked_main_window) # Mock SlideController slide_controller = SlideController(None) slide_controller.service_item = mocked_img_item slide_controller.is_live = False slide_controller.log_debug = MagicMock() slide_controller.selected_row = MagicMock() slide_controller.screens = MagicMock() slide_controller.screens.current = {'primary': ''} slide_controller.display = MagicMock() slide_controller.display.preview.return_value = QtGui.QImage() slide_controller.grab_maindisplay = MagicMock() slide_controller.slide_preview = MagicMock() slide_controller.slide_count = 0 # WHEN: update_preview is called slide_controller.update_preview() # THEN: setPixmap and display.preview should have been called assert 1 == slide_controller.slide_preview.setPixmap.call_count, 'setPixmap should be called' assert 1 == slide_controller.display.preview.call_count, 'display.preview() should be called' assert 0 == mocked_singleShot.call_count, 'Timer to grab_maindisplay should not be called' assert 0 == mocked_image_manager.get_image.call_count, 'image_manager should not be called'
def test_refresh_service_item_not_image_or_text(self): """ Test that the refresh_service_item() method does not refresh a service item if it's neither text or an image """ # GIVEN: A mock service item and a fresh slide controller mocked_service_item = MagicMock() mocked_service_item.is_text.return_value = False mocked_service_item.is_image.return_value = False mocked_process_item = MagicMock() slide_controller = SlideController(None) slide_controller.service_item = mocked_service_item slide_controller._process_item = mocked_process_item slide_controller.selected_row = 5 # WHEN: The refresh_service_item method() is called slide_controller.refresh_service_item() # THEN: The item should be re-processed mocked_service_item.is_text.assert_called_once_with() mocked_service_item.is_image.assert_called_once_with() assert 0 == mocked_service_item.render.call_count, 'The render() method should not have been called' assert 0 == mocked_process_item.call_count, 'The mocked_process_item() method should not have been called'
def test_refresh_service_item_image(self): """ Test that the refresh_service_item() method refreshes a image service item """ # GIVEN: A mock service item and a fresh slide controller mocked_service_item = MagicMock() mocked_service_item.is_text.return_value = False mocked_service_item.is_image.return_value = True mocked_process_item = MagicMock() slide_controller = SlideController(None) slide_controller.service_item = mocked_service_item slide_controller._process_item = mocked_process_item slide_controller.selected_row = 5 # WHEN: The refresh_service_item method() is called slide_controller.refresh_service_item() # THEN: The item should be re-processed mocked_service_item.is_text.assert_called_once_with() mocked_service_item.is_image.assert_called_once_with() mocked_service_item.render.assert_called_once_with() mocked_process_item.assert_called_once_with(mocked_service_item, 5)