def __init__(self): super(BiblePlugin, self).__init__('bibles', __default_settings__, BibleMediaItem, BiblesTab) self.weight = -9 self.icon_path = ':/plugins/plugin_bibles.png' self.icon = build_icon(self.icon_path) self.manager = BibleManager(self)
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 __init__(self): super(BiblePlugin, self).__init__('bibles', __default_settings__, BibleMediaItem, BiblesTab) self.weight = -9 self.icon_path = UiIcons().bible self.icon = UiIcons().bible self.manager = BibleManager(self) register_endpoint(bibles_endpoint) register_endpoint(api_bibles_endpoint)
def setUp(self): """ Set up the environment for testing bible queries with 1 Timothy 3 """ 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.get_section_data_path') as mocked_get_section_data_path, \ patch('openlp.core.common.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_section_data_path.return_value = TEST_RESOURCES_PATH + "/bibles" self.manager = BibleManager(MagicMock())
def initialise(self): log.info(u'bibles Initialising') if self.manager is None: self.manager = BibleManager(self) Plugin.initialise(self) self.importBibleItem.setVisible(True) action_list = ActionList.get_instance() action_list.add_action(self.importBibleItem, UiStrings().Import) # Do not add the action to the list yet. #action_list.add_action(self.exportBibleItem, UiStrings().Export) # Set to invisible until we can export bibles self.exportBibleItem.setVisible(False) self.toolsUpgradeItem.setVisible(bool(self.manager.old_bible_databases))
class BiblePlugin(Plugin): log.info(u'Bible Plugin loaded') def __init__(self): Plugin.__init__(self, u'bibles', __default_settings__, BibleMediaItem, BiblesTab) self.weight = -9 self.iconPath = u':/plugins/plugin_bibles.png' self.icon = build_icon(self.iconPath) self.manager = None def initialise(self): log.info(u'bibles Initialising') if self.manager is None: self.manager = BibleManager(self) Plugin.initialise(self) self.importBibleItem.setVisible(True) action_list = ActionList.get_instance() action_list.add_action(self.importBibleItem, UiStrings().Import) # Do not add the action to the list yet. #action_list.add_action(self.exportBibleItem, UiStrings().Export) # Set to invisible until we can export bibles self.exportBibleItem.setVisible(False) self.toolsUpgradeItem.setVisible(bool(self.manager.old_bible_databases)) def finalise(self): """ Tidy up on exit """ log.info(u'Plugin Finalise') self.manager.finalise() Plugin.finalise(self) action_list = ActionList.get_instance() action_list.remove_action(self.importBibleItem, UiStrings().Import) self.importBibleItem.setVisible(False) #action_list.remove_action(self.exportBibleItem, UiStrings().Export) self.exportBibleItem.setVisible(False) def app_startup(self): """ Perform tasks on application startup """ Plugin.app_startup(self) if self.manager.old_bible_databases: if QtGui.QMessageBox.information(self.main_window, translate('OpenLP', 'Information'), translate('OpenLP', 'Bible format has changed.\nYou have to upgrade your existing Bibles.\n' 'Should OpenLP upgrade now?'), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) == \ QtGui.QMessageBox.Yes: self.onToolsUpgradeItemTriggered() def addImportMenuItem(self, import_menu): self.importBibleItem = create_action(import_menu, u'importBibleItem', text=translate('BiblesPlugin', '&Bible'), visible=False, triggers=self.onBibleImportClick) import_menu.addAction(self.importBibleItem) def addExportMenuItem(self, export_menu): self.exportBibleItem = create_action(export_menu, u'exportBibleItem', text=translate('BiblesPlugin', '&Bible'), visible=False) export_menu.addAction(self.exportBibleItem) def addToolsMenuItem(self, tools_menu): """ Give the bible plugin the opportunity to add items to the **Tools** menu. ``tools_menu`` The actual **Tools** menu item, so that your actions can use it as their parent. """ log.debug(u'add tools menu') self.toolsUpgradeItem = create_action(tools_menu, u'toolsUpgradeItem', text=translate('BiblesPlugin', '&Upgrade older Bibles'), statustip=translate('BiblesPlugin', 'Upgrade the Bible databases to the latest format.'), visible=False, triggers=self.onToolsUpgradeItemTriggered) tools_menu.addAction(self.toolsUpgradeItem) def onToolsUpgradeItemTriggered(self): """ Upgrade older bible databases. """ if not hasattr(self, u'upgrade_wizard'): self.upgrade_wizard = BibleUpgradeForm(self.main_window, self.manager, self) # If the import was not cancelled then reload. if self.upgrade_wizard.exec_(): self.mediaItem.reloadBibles() def onBibleImportClick(self): if self.mediaItem: self.mediaItem.onImportClick() def about(self): about_text = translate('BiblesPlugin', '<strong>Bible Plugin</strong>' '<br />The Bible plugin provides the ability to display Bible ' 'verses from different sources during the service.') return about_text def usesTheme(self, theme): """ Called to find out if the bible plugin is currently using a theme. Returns ``True`` if the theme is being used, otherwise returns ``False``. """ return unicode(self.settingsTab.bible_theme) == theme def renameTheme(self, oldTheme, newTheme): """ Rename the theme the bible plugin is using making the plugin use the new name. ``oldTheme`` The name of the theme the plugin should stop using. Unused for this particular plugin. ``newTheme`` The new name the plugin should now use. """ self.settingsTab.bible_theme = newTheme self.settingsTab.save() def setPluginTextStrings(self): """ Called to define all translatable texts of the plugin """ ## Name PluginList ## self.textStrings[StringContent.Name] = { u'singular': translate('BiblesPlugin', 'Bible', 'name singular'), u'plural': translate('BiblesPlugin', 'Bibles', 'name plural') } ## Name for MediaDockManager, SettingsManager ## self.textStrings[StringContent.VisibleName] = { u'title': translate('BiblesPlugin', 'Bibles', 'container title') } # Middle Header Bar tooltips = { u'load': u'', u'import': translate('BiblesPlugin', 'Import a Bible.'), u'new': translate('BiblesPlugin', 'Add a new Bible.'), u'edit': translate('BiblesPlugin', 'Edit the selected Bible.'), u'delete': translate('BiblesPlugin', 'Delete the selected Bible.'), u'preview': translate('BiblesPlugin', 'Preview the selected Bible.'), u'live': translate('BiblesPlugin', 'Send the selected Bible live.'), u'service': translate('BiblesPlugin', 'Add the selected Bible to the service.') } self.setPluginUiTextStrings(tooltips)
class TestBibleManager(TestCase, TestMixin): def setUp(self): """ Set up the environment for testing bible queries with 1 Timothy 3 """ 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.get_section_data_path') as mocked_get_section_data_path, \ patch('openlp.core.common.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_section_data_path.return_value = TEST_RESOURCES_PATH + "/bibles" self.manager = BibleManager(MagicMock()) def tearDown(self): """ Delete all the C++ objects at the end so that we don't have a segfault """ del self.manager self.destroy_settings() def test_get_books(self): """ Test the get_books method """ # GIVEN given a bible in the bible manager # WHEN asking for the books of the bible books = self.manager.get_books('tests') # THEN a list of books should be returned self.assertEqual(66, len(books), 'There should be 66 books in the bible') def test_get_book_by_id(self): """ Test the get_book_by_id method """ # GIVEN given a bible in the bible manager # WHEN asking for the book of the bible book = self.manager.get_book_by_id('tests', 54) # THEN a book should be returned self.assertEqual('1 Timothy', book.name, '1 Timothy should have been returned from the bible') def test_get_chapter_count(self): """ Test the get_chapter_count method """ # GIVEN given a bible in the bible manager # WHEN asking for the chapters in a book of the bible book = self.manager.get_book_by_id('tests', 54) chapter = self.manager.get_chapter_count('tests', book) # THEN the chapter count should be returned self.assertEqual(6, chapter, '1 Timothy should have 6 chapters returned from the bible') def test_get_verse_count_by_book_ref_id(self): """ Test the get_verse_count_by_book_ref_id method """ # GIVEN given a bible in the bible manager # WHEN asking for the number of verses in a book of the bible verses = self.manager.get_verse_count_by_book_ref_id('tests', 54, 3) # THEN the chapter count should be returned self.assertEqual(16, verses, '1 Timothy v3 should have 16 verses returned from the bible')
class BiblePlugin(Plugin): """ The Bible plugin provides a plugin for managing and displaying Bibles. """ log.info('Bible Plugin loaded') def __init__(self): super(BiblePlugin, self).__init__('bibles', __default_settings__, BibleMediaItem, BiblesTab) self.weight = -9 self.icon_path = ':/plugins/plugin_bibles.png' self.icon = build_icon(self.icon_path) self.manager = BibleManager(self) def initialise(self): """ Initialise the Bible plugin. """ log.info('bibles Initialising') super(BiblePlugin, self).initialise() self.import_bible_item.setVisible(True) action_list = ActionList.get_instance() action_list.add_action(self.import_bible_item, UiStrings().Import) # Set to invisible until we can export bibles self.export_bible_item.setVisible(False) self.tools_upgrade_item.setVisible( bool(self.manager.old_bible_databases)) def finalise(self): """ Tidy up on exit """ log.info('Plugin Finalise') self.manager.finalise() Plugin.finalise(self) action_list = ActionList.get_instance() action_list.remove_action(self.import_bible_item, UiStrings().Import) self.import_bible_item.setVisible(False) self.export_bible_item.setVisible(False) def app_startup(self): """ Perform tasks on application startup """ super(BiblePlugin, self).app_startup() if self.manager.old_bible_databases: if QtWidgets.QMessageBox.information( self.main_window, translate('OpenLP', 'Information'), translate('OpenLP', 'Bible format has changed.\nYou have to upgrade your ' 'existing Bibles.\nShould OpenLP upgrade now?'), QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)) == \ QtWidgets.QMessageBox.Yes: self.on_tools_upgrade_item_triggered() def add_import_menu_item(self, import_menu): """ Add an import menu item :param import_menu: The menu to insert the menu item into. """ self.import_bible_item = create_action( import_menu, 'importBibleItem', text=translate('BiblesPlugin', '&Bible'), visible=False, triggers=self.on_bible_import_click) import_menu.addAction(self.import_bible_item) def add_export_menu_item(self, export_menu): """ Add an export menu item :param export_menu: The menu to insert the menu item into. """ self.export_bible_item = create_action(export_menu, 'exportBibleItem', text=translate( 'BiblesPlugin', '&Bible'), visible=False) export_menu.addAction(self.export_bible_item) def add_tools_menu_item(self, tools_menu): """ Give the bible plugin the opportunity to add items to the **Tools** menu. :param tools_menu: The actual **Tools** menu item, so that your actions can use it as their parent. """ log.debug('add tools menu') self.tools_upgrade_item = create_action( tools_menu, 'toolsUpgradeItem', text=translate('BiblesPlugin', '&Upgrade older Bibles'), statustip=translate( 'BiblesPlugin', 'Upgrade the Bible databases to the latest format.'), visible=False, triggers=self.on_tools_upgrade_item_triggered) tools_menu.addAction(self.tools_upgrade_item) def on_tools_upgrade_item_triggered(self): """ Upgrade older bible databases. """ if not hasattr(self, 'upgrade_wizard'): self.upgrade_wizard = BibleUpgradeForm(self.main_window, self.manager, self) # If the import was not cancelled then reload. if self.upgrade_wizard.exec(): self.media_item.reload_bibles() def on_bible_import_click(self): """ Show the Bible Import wizard """ if self.media_item: self.media_item.on_import_click() @staticmethod def about(): """ Return the about text for the plugin manager """ about_text = translate( 'BiblesPlugin', '<strong>Bible Plugin</strong>' '<br />The Bible plugin provides the ability to display Bible ' 'verses from different sources during the service.') return about_text def uses_theme(self, theme): """ Called to find out if the bible plugin is currently using a theme. Returns ``1`` if the theme is being used, otherwise returns ``0``. :param theme: The theme """ if str(self.settings_tab.bible_theme) == theme: return 1 return 0 def rename_theme(self, old_theme, new_theme): """ Rename the theme the bible plugin is using making the plugin use the new name. :param old_theme: The name of the theme the plugin should stop using. Unused for this particular plugin. :param new_theme: The new name the plugin should now use. """ self.settings_tab.bible_theme = new_theme self.settings_tab.save() def set_plugin_text_strings(self): """ Called to define all translatable texts of the plugin """ # Name PluginList self.text_strings[StringContent.Name] = { 'singular': translate('BiblesPlugin', 'Bible', 'name singular'), 'plural': translate('BiblesPlugin', 'Bibles', 'name plural') } # Name for MediaDockManager, SettingsManager self.text_strings[StringContent.VisibleName] = { 'title': translate('BiblesPlugin', 'Bibles', 'container title') } # Middle Header Bar tooltips = { 'load': '', 'import': translate('BiblesPlugin', 'Import a Bible.'), 'new': translate('BiblesPlugin', 'Add a new Bible.'), 'edit': translate('BiblesPlugin', 'Edit the selected Bible.'), 'delete': translate('BiblesPlugin', 'Delete the selected Bible.'), 'preview': translate('BiblesPlugin', 'Preview the selected Bible.'), 'live': translate('BiblesPlugin', 'Send the selected Bible live.'), 'service': translate('BiblesPlugin', 'Add the selected Bible to the service.') } self.set_plugin_ui_text_strings(tooltips)
class BiblePlugin(Plugin): """ The Bible plugin provides a plugin for managing and displaying Bibles. """ log.info('Bible Plugin loaded') def __init__(self): super(BiblePlugin, self).__init__('bibles', __default_settings__, BibleMediaItem, BiblesTab) self.weight = -9 self.icon_path = ':/plugins/plugin_bibles.png' self.icon = build_icon(self.icon_path) self.manager = BibleManager(self) def initialise(self): """ Initialise the Bible plugin. """ log.info('bibles Initialising') super(BiblePlugin, self).initialise() self.import_bible_item.setVisible(True) action_list = ActionList.get_instance() action_list.add_action(self.import_bible_item, UiStrings().Import) # Set to invisible until we can export bibles self.export_bible_item.setVisible(False) def finalise(self): """ Tidy up on exit """ log.info('Plugin Finalise') self.manager.finalise() Plugin.finalise(self) action_list = ActionList.get_instance() action_list.remove_action(self.import_bible_item, UiStrings().Import) self.import_bible_item.setVisible(False) self.export_bible_item.setVisible(False) def add_import_menu_item(self, import_menu): """ Add an import menu item :param import_menu: The menu to insert the menu item into. """ self.import_bible_item = create_action(import_menu, 'importBibleItem', text=translate('BiblesPlugin', '&Bible'), visible=False, triggers=self.on_bible_import_click) import_menu.addAction(self.import_bible_item) def add_export_menu_item(self, export_menu): """ Add an export menu item :param export_menu: The menu to insert the menu item into. """ self.export_bible_item = create_action(export_menu, 'exportBibleItem', text=translate('BiblesPlugin', '&Bible'), visible=False) export_menu.addAction(self.export_bible_item) def on_bible_import_click(self): """ Show the Bible Import wizard """ if self.media_item: self.media_item.on_import_click() @staticmethod def about(): """ Return the about text for the plugin manager """ about_text = translate('BiblesPlugin', '<strong>Bible Plugin</strong>' '<br />The Bible plugin provides the ability to display Bible ' 'verses from different sources during the service.') return about_text def uses_theme(self, theme): """ Called to find out if the bible plugin is currently using a theme. :param theme: The theme :return: 1 if the theme is being used, otherwise returns 0 """ if str(self.settings_tab.bible_theme) == theme: return 1 return 0 def rename_theme(self, old_theme, new_theme): """ Rename the theme the bible plugin is using, making the plugin use the new name. :param old_theme: The name of the theme the plugin should stop using. Unused for this particular plugin. :param new_theme: The new name the plugin should now use. :return: None """ self.settings_tab.bible_theme = new_theme self.settings_tab.save() def set_plugin_text_strings(self): """ Called to define all translatable texts of the plugin """ # Name PluginList self.text_strings[StringContent.Name] = { 'singular': translate('BiblesPlugin', 'Bible', 'name singular'), 'plural': translate('BiblesPlugin', 'Bibles', 'name plural') } # Name for MediaDockManager, SettingsManager self.text_strings[StringContent.VisibleName] = { 'title': translate('BiblesPlugin', 'Bibles', 'container title') } # Middle Header Bar tooltips = { 'load': '', 'import': translate('BiblesPlugin', 'Import a Bible.'), 'new': translate('BiblesPlugin', 'Add a new Bible.'), 'edit': translate('BiblesPlugin', 'Edit the selected Bible.'), 'delete': translate('BiblesPlugin', 'Delete the selected Bible.'), 'preview': translate('BiblesPlugin', 'Preview the selected Bible.'), 'live': translate('BiblesPlugin', 'Send the selected Bible live.'), 'service': translate('BiblesPlugin', 'Add the selected Bible to the service.') } self.set_plugin_ui_text_strings(tooltips)
class TestBibleManager(TestCase, TestMixin): 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 tearDown(self): """ Delete all the C++ objects at the end so that we don't have a segfault """ del self.manager self.destroy_settings() def test_get_books(self): """ Test the get_books method """ # GIVEN given a bible in the bible manager # WHEN asking for the books of the bible books = self.manager.get_books('tests') # THEN a list of books should be returned assert 66 == len(books), 'There should be 66 books in the bible' def test_get_book_by_id(self): """ Test the get_book_by_id method """ # GIVEN given a bible in the bible manager # WHEN asking for the book of the bible book = self.manager.get_book_by_id('tests', 54) # THEN a book should be returned assert '1 Timothy' == book.name, '1 Timothy should have been returned from the bible' def test_get_chapter_count(self): """ Test the get_chapter_count method """ # GIVEN given a bible in the bible manager # WHEN asking for the chapters in a book of the bible book = self.manager.get_book_by_id('tests', 54) chapter = self.manager.get_chapter_count('tests', book) # THEN the chapter count should be returned assert 6 == chapter, '1 Timothy should have 6 chapters returned from the bible' def test_get_verse_count_by_book_ref_id(self): """ Test the get_verse_count_by_book_ref_id method """ # GIVEN given a bible in the bible manager # WHEN asking for the number of verses in a book of the bible verses = self.manager.get_verse_count_by_book_ref_id('tests', 54, 3) # THEN the chapter count should be returned assert 16 == verses, '1 Timothy v3 should have 16 verses returned from the bible'