def setUp(self): Registry.create() self.registry = Registry() self.setup_application() # Mock cursor busy/normal methods. self.app.set_busy_cursor = MagicMock() self.app.set_normal_cursor = MagicMock() self.app.args = [] Registry().register('application', self.app) # Mock classes and methods used by mainwindow. with patch('openlp.core.ui.mainwindow.SettingsForm') as mocked_settings_form, \ patch('openlp.core.ui.mainwindow.ImageManager') as mocked_image_manager, \ patch('openlp.core.ui.mainwindow.LiveController') as mocked_live_controller, \ patch('openlp.core.ui.mainwindow.PreviewController') as mocked_preview_controller, \ patch('openlp.core.ui.mainwindow.OpenLPDockWidget') as mocked_dock_widget, \ patch('openlp.core.ui.mainwindow.QtWidgets.QToolBox') as mocked_q_tool_box_class, \ patch('openlp.core.ui.mainwindow.QtWidgets.QMainWindow.addDockWidget') as mocked_add_dock_method, \ patch('openlp.core.ui.mainwindow.ThemeManager') as mocked_theme_manager, \ patch('openlp.core.ui.mainwindow.Renderer') as mocked_renderer: self.mocked_settings_form = mocked_settings_form self.mocked_image_manager = mocked_image_manager self.mocked_live_controller = mocked_live_controller self.mocked_preview_controller = mocked_preview_controller self.mocked_dock_widget = mocked_dock_widget self.mocked_q_tool_box_class = mocked_q_tool_box_class self.mocked_add_dock_method = mocked_add_dock_method self.mocked_theme_manager = mocked_theme_manager self.mocked_renderer = mocked_renderer self.main_window = MainWindow()
def setUp(self): """ Set up the objects we need for all of the tests """ Registry.create() self.registry = Registry() self.setup_application() # Mock cursor busy/normal methods. self.app.set_busy_cursor = MagicMock() self.app.set_normal_cursor = MagicMock() self.app.process_events = MagicMock() self.app.args = [] Registry().register('application', self.app) Registry().set_flag('no_web_server', True) self.add_toolbar_action_patcher = patch( 'openlp.core.ui.mainwindow.create_action') self.mocked_add_toolbar_action = self.add_toolbar_action_patcher.start( ) self.mocked_add_toolbar_action.side_effect = self._create_mock_action self.renderer_patcher = patch('openlp.core.display.render.Renderer') self.mocked_renderer = self.renderer_patcher.start() mocked_desktop = MagicMock() mocked_desktop.screenCount.return_value = 1 mocked_desktop.screenGeometry.return_value = QtCore.QRect( 0, 0, 1024, 768) mocked_desktop.primaryScreen.return_value = 1 ScreenList.create(mocked_desktop) State().load_settings() self.main_window = MainWindow()
def setUp(self): self.sample_theme_data = { 'file_name': 'BlueBurst.otz', 'sha256': 'sha_256_hash', 'thumbnail': 'BlueBurst.png', 'title': 'Blue Burst' } Registry.create() self.registry = Registry() mocked_app = MagicMock() mocked_app.worker_threads = {} Registry().register('application', mocked_app) self.setup_application() move_to_thread_patcher = patch( 'openlp.core.ui.firsttimeform.DownloadWorker.moveToThread') self.addCleanup(move_to_thread_patcher.stop) move_to_thread_patcher.start() set_icon_patcher = patch( 'openlp.core.ui.firsttimeform.ThemeListWidgetItem.setIcon') self.addCleanup(set_icon_patcher.stop) self.mocked_set_icon = set_icon_patcher.start() q_thread_patcher = patch('openlp.core.ui.firsttimeform.QtCore.QThread') self.addCleanup(q_thread_patcher.stop) q_thread_patcher.start()
def setUp(self): """ Setup for tests """ self.tmp_path = Path(mkdtemp()) db_path = RESOURCE_PATH / 'bibles' / 'web-bible-2.4.6-proxy-meta-v1.sqlite' db_tmp_path = self.tmp_path / 'web-bible-2.4.6-proxy-meta-v1.sqlite' shutil.copyfile(db_path, db_tmp_path) self.db_url = 'sqlite:///' + str(db_tmp_path) self.mocked_settings_instance = MagicMock() self.mocked_settings = MagicMock() self.mocked_settings.return_value = self.mocked_settings_instance self.build_settings() Registry().create() Registry().register('service_list', MagicMock()) Registry().register('settings', self.mocked_settings) patched_message_box = patch( 'openlp.plugins.bibles.lib.upgrade.QtWidgets.QMessageBox') mocked_message_box = patched_message_box.start() self.addCleanup(patched_message_box.stop) self.mocked_no_button = MagicMock() self.mocked_http_button = MagicMock() self.mocked_both_button = MagicMock() self.mocked_https_button = MagicMock() self.mocked_message_box_instance = MagicMock( **{ 'addButton.side_effect': [ self.mocked_no_button, self.mocked_http_button, self.mocked_both_button, self.mocked_https_button ] }) mocked_message_box.return_value = self.mocked_message_box_instance
def setUp(self): """ Set up the environment for testing bible queries with 1 Timothy 3 """ self.setup_application() self.build_settings() Registry.create() Registry().register('service_list', MagicMock()) Registry().register('application', MagicMock()) bible_settings = { 'bibles/proxy name': '', 'bibles/db type': 'sqlite', 'bibles/book name language': LanguageSelection.Bible, 'bibles/verse separator': '', 'bibles/range separator': '', 'bibles/list separator': '', 'bibles/end separator': '', } Settings().extend_default_settings(bible_settings) with patch('openlp.core.common.applocation.Settings') as mocked_class, \ patch('openlp.core.common.applocation.AppLocation.get_section_data_path') as mocked_get_data_path, \ patch('openlp.core.common.applocation.AppLocation.get_files') as mocked_get_files: # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_files() mocked_settings = mocked_class.return_value mocked_settings.contains.return_value = False mocked_get_files.return_value = ["tests.sqlite"] mocked_get_data_path.return_value = TEST_RESOURCES_PATH + "/bibles" self.manager = BibleManager(MagicMock())
def run(self, args): """ Run the OpenLP application. :param args: Some Args """ self.is_event_loop_active = False # On Windows, the args passed into the constructor are ignored. Not very handy, so set the ones we want to use. # On Linux and FreeBSD, in order to set the WM_CLASS property for X11, we pass "OpenLP" in as a command line # argument. This interferes with files being passed in as command line arguments, so we remove it from the list. if 'OpenLP' in args: args.remove('OpenLP') self.args.extend(args) # Decide how many screens we have and their size screens = ScreenList.create(self.desktop()) # First time checks in settings has_run_wizard = Settings().value('core/has run wizard') if not has_run_wizard: ftw = FirstTimeForm() ftw.initialize(screens) if ftw.exec() == QtWidgets.QDialog.Accepted: Settings().setValue('core/has run wizard', True) elif ftw.was_cancelled: QtCore.QCoreApplication.exit() sys.exit() # Correct stylesheet bugs application_stylesheet = get_application_stylesheet() if application_stylesheet: self.setStyleSheet(application_stylesheet) can_show_splash = Settings().value('core/show splash') if can_show_splash: self.splash = SplashScreen() self.splash.show() # make sure Qt really display the splash screen self.processEvents() # Check if OpenLP has been upgrade and if a backup of data should be created self.backup_on_upgrade(has_run_wizard, can_show_splash) # start the main app window self.main_window = MainWindow() Registry().execute('bootstrap_initialise') Registry().execute('bootstrap_post_set_up') Registry().initialise = False self.main_window.show() if can_show_splash: # now kill the splashscreen log.debug('Splashscreen closing') self.splash.close() log.debug('Splashscreen closed') # make sure Qt really display the splash screen self.processEvents() self.main_window.repaint() self.processEvents() if not has_run_wizard: self.main_window.first_time() if Settings().value('core/update check'): check_for_update(self.main_window) self.main_window.is_display_blank() self.main_window.app_startup() return self.exec()
def check_installed(self): """ Check the viewer is installed. :return: True if program to open PDF-files was found, otherwise False. """ log.debug('check_installed Pdf') self.mudrawbin = None self.mutoolbin = None self.gsbin = None self.also_supports = [] # Use the user defined program if given if Registry().get('settings').value( 'presentations/enable_pdf_program'): program_path = Registry().get('settings').value( 'presentations/pdf_program') program_type = self.process_check_binary(program_path) if program_type == 'gs': self.gsbin = program_path elif program_type == 'mudraw': self.mudrawbin = program_path elif program_type == 'mutool': self.mutoolbin = program_path elif PYMUPDF_AVAILABLE: self.also_supports = ['xps', 'oxps', 'epub', 'cbz', 'fb2'] return True else: # Fallback to autodetection application_path = AppLocation.get_directory(AppLocation.AppDir) if is_win(): # for windows we only accept mudraw.exe or mutool.exe in the base folder if (application_path / 'mudraw.exe').is_file(): self.mudrawbin = application_path / 'mudraw.exe' elif (application_path / 'mutool.exe').is_file(): self.mutoolbin = application_path / 'mutool.exe' else: # First try to find mudraw self.mudrawbin = which('mudraw') # if mudraw isn't installed, try mutool if not self.mudrawbin: self.mutoolbin = which('mutool') # Check we got a working mutool if not self.mutoolbin or self.process_check_binary( self.mutoolbin) != 'mutool': self.gsbin = which('gs') # Last option: check if mudraw or mutool is placed in OpenLP base folder if not self.mudrawbin and not self.mutoolbin and not self.gsbin: application_path = AppLocation.get_directory( AppLocation.AppDir) if (application_path / 'mudraw').is_file(): self.mudrawbin = application_path / 'mudraw' elif (application_path / 'mutool').is_file(): self.mutoolbin = application_path / 'mutool' if self.mudrawbin or self.mutoolbin: self.also_supports = ['xps', 'oxps', 'epub', 'cbz', 'fb2'] return True elif self.gsbin: return True return False
def mock_settings(registry): """A Mock Settings() instance""" # Create and register a mock settings object to work with mock_settings = MagicMock() Registry().register('settings', mock_settings) yield mock_settings Registry().remove('settings') del mock_settings
def setUp(self): """ Set up the Registry """ Registry.create() Registry().register('service_list', MagicMock()) Registry().register('application', MagicMock()) Registry().register('main_window', MagicMock())
def activateDnD(self): """ Activate DnD of widget """ self.setAcceptDrops(True) self.setDragDropMode(QtWidgets.QAbstractItemView.DragDrop) Registry().register_function(('%s_dnd' % self.mime_data_text), self.parent().load_file) Registry().register_function(('%s_dnd_internal' % self.mime_data_text), self.parent().dnd_move_internal)
def setUp(self): """ Create the UI """ Registry().create() Registry().register('service_list', MagicMock()) self.build_settings() self.password = '******'
def website_version(self): """ Download and save the website version and sha256 :return: None """ sha256, self.version = download_sha256() Registry().set_flag('website_sha256', sha256) Registry().set_flag('website_version', self.version)
def __init__(self, *args, **kwargs): super(SongImportTestHelper, self).__init__(*args, **kwargs) self.importer_module = __import__('openlp.plugins.songs.lib.importers.%s' % self.importer_module_name, fromlist=[self.importer_class_name]) self.importer_class = getattr(self.importer_module, self.importer_class_name) Registry.create() Registry().register('settings', MagicMock()) self.settings = Registry().get('settings')
def test_build_media_context_menu(self): """ Test the creation of a context menu from service item of type Command from Media. """ # GIVEN: A new service manager instance and a default service item. Registry().register('plugin_manager', MagicMock()) Registry().register('renderer', MagicMock()) service_manager = ServiceManager(None) item = MagicMock() item.parent.return_value = False item.data.return_value = 0 service_manager.service_manager_list = MagicMock() service_manager.service_manager_list.itemAt.return_value = item service_item = ServiceItem(None) service_item.add_capability(ItemCapabilities.CanAutoStartForLive) service_item.add_capability(ItemCapabilities.CanEditTitle) service_item.add_capability(ItemCapabilities.RequiresMedia) service_item.service_item_type = ServiceItemType.Command service_item.edit_id = 1 service_item._raw_frames.append(MagicMock()) service_manager.service_items.insert(1, {'service_item': service_item}) service_manager.edit_action = MagicMock() service_manager.rename_action = MagicMock() service_manager.create_custom_action = MagicMock() service_manager.maintain_action = MagicMock() service_manager.notes_action = MagicMock() service_manager.time_action = MagicMock() service_manager.auto_start_action = MagicMock() service_manager.auto_play_slides_menu = MagicMock() service_manager.auto_play_slides_once = MagicMock() service_manager.auto_play_slides_loop = MagicMock() service_manager.timed_slide_interval = MagicMock() service_manager.theme_menu = MagicMock() service_manager.menu = MagicMock() # WHEN I define a context menu service_manager.context_menu(1) # THEN the following calls should have occurred. assert service_manager.edit_action.setVisible.call_count == 1, 'Should have be called once' assert service_manager.rename_action.setVisible.call_count == 2, 'Should have be called twice' assert service_manager.create_custom_action.setVisible.call_count == 1, 'Should have be called once' assert service_manager.maintain_action.setVisible.call_count == 1, 'Should have be called once' assert service_manager.notes_action.setVisible.call_count == 1, 'Should have be called once' assert service_manager.time_action.setVisible.call_count == 1, 'Should have be called once' assert service_manager.auto_start_action.setVisible.call_count == 2, 'Should have be called twice' assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 1, \ 'Should have be called once' assert service_manager.auto_play_slides_once.setChecked.call_count == 0, 'Should not be called' assert service_manager.auto_play_slides_loop.setChecked.call_count == 0, 'Should not be called' assert service_manager.timed_slide_interval.setChecked.call_count == 0, 'Should not be called' assert service_manager.theme_menu.menuAction().setVisible.call_count == 1, \ 'Should have be called once' # THEN I change the length of the media and regenerate the menu. service_item.set_media_length(5) service_manager.context_menu(1) # THEN the following additional calls should have occurred. assert service_manager.time_action.setVisible.call_count == 3, 'Should have be called three times'
def _process_lines_mixed_content(self, element, newlines=True): """ Converts the xml text with mixed content to OpenLP representation. Chords and formatting tags are converted. :param element: The property object (lxml.etree.Element). :param newlines: The switch to enable/disable processing of line breaks <br/>. The <br/> is used since OpenLyrics 0.8. """ text = '' use_endtag = True # Skip <comment> elements - not yet supported. if element.tag == NSMAP.format(tag='comment'): if element.tail: # Append tail text at comment element. text += element.tail return text # Convert chords to ChordPro format which OpenLP uses internally elif element.tag == NSMAP.format(tag='chord'): if Registry().get('settings').value('songs/enable chords') and not \ Registry().get('settings').value('songs/disable chords import'): text += '[{chord}]'.format(chord=element.get('name')) if element.tail: # Append tail text at chord element. text += element.tail return text # Convert line breaks <br/> to \n. elif newlines and element.tag == NSMAP.format(tag='br'): text += '\n' if element.tail: text += element.tail return text elif newlines and element.tag == NSMAP.format( tag='p') and 'page-break-after' in str(element.attrib): text += '[--}{--]' return text # Start formatting tag. if element.tag == NSMAP.format(tag='tag'): text += '{{{name}}}'.format(name=element.get('name')) # Some formattings may have only start tag. # Handle this case if element has no children and contains no text. if not element and not element.text: use_endtag = False # Append text from element. if element.text: text += element.text # Process nested formatting tags. for child in element: # Use recursion since nested formatting tags are allowed. text += self._process_lines_mixed_content(child, newlines) # Append text from tail and add formatting end tag. if element.tag == NSMAP.format(tag='tag') and use_endtag: text += '{{/{name}}}'.format(name=element.get('name')) # Append text from tail. if element.tail: text += element.tail return text
def media_pause(request): """ Handles requests for pausing media :param request: The http request object. """ media = Registry().get('media_controller') live = Registry().get('live_controller') status = media.media_pause(live) return {'results': {'success': status}}
def setUp(self): """ Some set up for this test suite """ self.setup_application() self.app.setApplicationVersion('0.0') self.app.process_events = lambda: None Registry.create() Registry().register('application', self.app) Registry().register('settings', MagicMock())
def slideAnimationsEnded(self): """ Notify that the last animation from the main sequence of the current slide has ended. """ log.debug('LibreOffice SlideShowListener event: slideAnimationsEnded') if not Registry().get('main_window').isActiveWindow(): log.debug( 'main window is not in focus - should update slidecontroller') Registry().execute( 'slidecontroller_live_change', self.document.control.getCurrentSlideIndex() + 1)
def setUp(self): """ Create the UI """ self.setup_application() self.registry = Registry() Registry.create() State().load_settings() Registry().register('settings', Settings()) self.plugin = PlanningCenterPlugin() self.settings_form = SettingsForm()
def setUp(self): """ Set up the Registry """ self.build_settings() Settings().extend_default_settings(__default_settings__) Registry.create() mocked_renderer = MagicMock() mocked_renderer.format_slide.return_value = [VERSE] Registry().register('renderer', mocked_renderer) Registry().register('image_manager', MagicMock())
def setUp(self): """ Set up the components need for all tests. """ Registry.create() Registry().register('service_manager', MagicMock()) Registry().register('main_window', MagicMock()) with patch('openlp.plugins.presentations.lib.mediaitem.MediaManagerItem._setup'), \ patch('openlp.plugins.presentations.lib.mediaitem.PresentationMediaItem.setup_item'): self.media_item = PresentationMediaItem(None, MagicMock, MagicMock())
def application(self): """ Adds the openlp to the class dynamically. Windows needs to access the application in a dynamic manner. """ if is_win(): return Registry().get('application') else: if not hasattr(self, '_application') or not self._application: self._application = Registry().get('application') return self._application
def start_presentation(self): """ Starts a presentation from the beginning. """ log.debug('start_presentation') # SlideShowWindow measures its size/position by points, not pixels # https://technet.microsoft.com/en-us/library/dn528846.aspx try: dpi = win32ui.GetActiveWindow().GetDC().GetDeviceCaps(88) except win32ui.error: try: dpi = win32ui.GetForegroundWindow().GetDC().GetDeviceCaps( 88) except win32ui.error: dpi = 96 size = ScreenList().current.display_geometry ppt_window = None try: # Disable the presentation console self.presentation.SlideShowSettings.ShowPresenterView = 0 # Start the presentation ppt_window = self.presentation.SlideShowSettings.Run() except (AttributeError, pywintypes.com_error): log.exception('Caught exception while in start_presentation') trace_error_handler(log) self.show_error_msg() if ppt_window and not Registry().get('settings').value( 'presentations/powerpoint control window'): try: ppt_window.Top = size.y() * 72 / dpi ppt_window.Height = size.height() * 72 / dpi ppt_window.Left = size.x() * 72 / dpi ppt_window.Width = size.width() * 72 / dpi except AttributeError: log.exception('AttributeError while in start_presentation') # Find the presentation window and save the handle for later self.presentation_hwnd = None if ppt_window: log.debug('main display size: y={y:d}, height={height:d}, ' 'x={x:d}, width={width:d}'.format( y=size.y(), height=size.height(), x=size.x(), width=size.width())) try: win32gui.EnumWindows(self._window_enum_callback, size) except pywintypes.error: # When _window_enum_callback returns False to stop the enumeration (looping over open windows) # it causes an exception that is ignored here pass # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList()) > 1: Registry().get('main_window').activateWindow()
def __init__(self, parent=None): """ Initialise the http server, and start the http server """ super(HttpServer, self).__init__(parent) if not Registry().get_flag('no_web_server'): worker = HttpWorker() run_thread(worker, 'http_server') Registry().register_function('download_website', self.first_time) Registry().register_function('get_website_version', self.website_version) Registry().set_flag('website_version', '0.0')
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() self.main_window = QtWidgets.QMainWindow() Registry().register('main_window', self.main_window) Registry().register('theme_manager', MagicMock()) self.build_settings() Settings().extend_default_settings(__default_settings__) self.form = EditSongForm(MagicMock(), self.main_window, MagicMock())
def setUp(self): """ Set up the components need for all tests. """ Registry.create() Registry().register('service_list', MagicMock()) Registry().register('main_window', MagicMock()) with patch('openlp.plugins.songs.forms.editsongform.EditSongForm.__init__', return_value=None): self.edit_song_form = EditSongForm(None, MagicMock(), MagicMock()) self.setup_application() self.build_settings() QtCore.QLocale.setDefault(QtCore.QLocale('en_GB'))
def add_end_header_bar(self): self.toolbar.addSeparator() # Song Maintenance Button self.maintenance_action = self.toolbar.add_toolbar_action('maintenance_action', icon=UiIcons().database, triggers=self.on_song_maintenance_click) self.add_search_to_toolbar() # Signals and slots Registry().register_function('songs_load_list', self.on_song_list_load) Registry().register_function('songs_preview', self.on_preview_click) self.search_text_edit.cleared.connect(self.on_clear_text_button_click) self.search_text_edit.searchTypeChanged.connect(self.on_search_text_button_clicked)
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() Registry().register('application', MagicMock()) Registry().register('main_window', MagicMock(service_manager_settings_section='servicemanager')) self.service_manager = ServiceManager() self.add_toolbar_action_patcher = patch('openlp.core.ui.servicemanager.OpenLPToolbar.add_toolbar_action') self.mocked_add_toolbar_action = self.add_toolbar_action_patcher.start() self.mocked_add_toolbar_action.side_effect = self._create_mock_action
def setUp(self): """ Some pre-test setup required. """ self.setup_application() self.build_settings() self.temp_dir_path = Path(mkdtemp('openlp')) Settings().setValue('advanced/data path', self.temp_dir_path) Registry.create() Registry().register('service_list', MagicMock()) self.main_window = QtWidgets.QMainWindow() Registry().register('main_window', self.main_window)
def setUp(self): self.mocked_main_window = MagicMock() Registry.create() Registry().register('application', MagicMock()) Registry().register('service_list', MagicMock()) Registry().register('main_window', self.mocked_main_window) Registry().register('live_controller', MagicMock()) mocked_plugin = MagicMock() with patch('openlp.plugins.images.lib.mediaitem.MediaManagerItem._setup'), \ patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.setup_item'): self.media_item = ImageMediaItem(None, mocked_plugin) self.media_item.settings_section = 'images'