diff --git a/openlp.py b/openlp.py index 8a53fe965..5d507606d 100755 --- a/openlp.py +++ b/openlp.py @@ -36,10 +36,9 @@ if __name__ == '__main__': """ Instantiate and run the application. """ - # Mac OS X passes arguments like '-psn_XXXX' to gui application. - # This argument is process serial number. However, this causes - # conflict with other OpenLP arguments. Since we do not use this - # argument we can delete it to avoid any potential conflicts. + # Mac OS X passes arguments like '-psn_XXXX' to the application. This argument is actually a process serial number. + # However, this causes a conflict with other OpenLP arguments. Since we do not use this argument we can delete it + # to avoid any potential conflicts. if sys.platform.startswith('darwin'): sys.argv = [x for x in sys.argv if not x.startswith('-psn')] main() diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 32ef5c5a3..cb9105797 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -59,7 +59,7 @@ __all__ = ['OpenLP', 'main'] log = logging.getLogger() -NT_REPAIR_STYLESHEET = """ +WIN_REPAIR_STYLESHEET = """ QMainWindow::separator { border: none; @@ -127,7 +127,7 @@ class OpenLP(OpenLPMixin, QtGui.QApplication): 'QTableWidget, QListWidget, QTreeWidget {alternate-background-color: ' + base_color.name() + ';}\n' application_stylesheet += alternate_rows_repair_stylesheet if is_win(): - application_stylesheet += NT_REPAIR_STYLESHEET + application_stylesheet += WIN_REPAIR_STYLESHEET if application_stylesheet: self.setStyleSheet(application_stylesheet) show_splash = Settings().value('core/show splash') diff --git a/openlp/core/common/openlpmixin.py b/openlp/core/common/openlpmixin.py index 1c7fe7d5a..3e8a8926a 100644 --- a/openlp/core/common/openlpmixin.py +++ b/openlp/core/common/openlpmixin.py @@ -33,6 +33,7 @@ import logging import inspect from openlp.core.common import trace_error_handler + DO_NOT_TRACE_EVENTS = ['timerEvent', 'paintEvent', 'drag_enter_event', 'drop_event', 'on_controller_size_changed', 'preview_size_changed', 'resizeEvent'] @@ -41,11 +42,8 @@ class OpenLPMixin(object): """ Base Calling object for OpenLP classes. """ - def __init__(self, parent): - try: - super(OpenLPMixin, self).__init__(parent) - except TypeError: - super(OpenLPMixin, self).__init__() + def __init__(self, *args, **kwargs): + super(OpenLPMixin, self).__init__(*args, **kwargs) self.logger = logging.getLogger("%s.%s" % (self.__module__, self.__class__.__name__)) if self.logger.getEffectiveLevel() == logging.DEBUG: for name, m in inspect.getmembers(self, inspect.ismethod): diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index cbc35e28d..af4b263d3 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -33,7 +33,7 @@ import logging from PyQt4 import QtCore, QtGui -from openlp.core.common import Registry, UiStrings, translate +from openlp.core.common import Registry, UiStrings, translate, is_macosx from openlp.core.lib import build_icon from openlp.core.utils.actions import ActionList @@ -247,6 +247,8 @@ def create_action(parent, name, **kwargs): """ action = QtGui.QAction(parent) action.setObjectName(name) + if is_macosx(): + action.setIconVisibleInMenu(False) if kwargs.get('text'): action.setText(kwargs.pop('text')) if kwargs.get('icon'): diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index d7c16f0d3..8599c8d35 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -387,17 +387,21 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard, RegistryProperties): self.progress_bar.setValue(self.progress_bar.maximum()) if self.has_run_wizard: self.progress_label.setText(translate('OpenLP.FirstTimeWizard', - 'Download complete. Click the finish button to return to OpenLP.')) + 'Download complete. Click the %s button to return to OpenLP.') % + self.buttonText(QtGui.QWizard.FinishButton)) else: self.progress_label.setText(translate('OpenLP.FirstTimeWizard', - 'Download complete. Click the finish button to start OpenLP.')) + 'Download complete. Click the %s button to start OpenLP.') % + self.buttonText(QtGui.QWizard.FinishButton)) else: if self.has_run_wizard: self.progress_label.setText(translate('OpenLP.FirstTimeWizard', - 'Click the finish button to return to OpenLP.')) + 'Click the %s button to return to OpenLP.') % + self.buttonText(QtGui.QWizard.FinishButton)) else: self.progress_label.setText(translate('OpenLP.FirstTimeWizard', - 'Click the finish button to start OpenLP.')) + 'Click the %s button to start OpenLP.') % + self.buttonText(QtGui.QWizard.FinishButton)) self.finish_button.setVisible(True) self.finish_button.setEnabled(True) self.cancel_button.setVisible(False) diff --git a/openlp/core/ui/firsttimewizard.py b/openlp/core/ui/firsttimewizard.py index ff1675ff5..c5098eda6 100644 --- a/openlp/core/ui/firsttimewizard.py +++ b/openlp/core/ui/firsttimewizard.py @@ -31,9 +31,7 @@ The UI widgets for the first time wizard. """ from PyQt4 import QtCore, QtGui -import sys - -from openlp.core.common import translate +from openlp.core.common import translate, is_macosx from openlp.core.lib import build_icon from openlp.core.lib.ui import add_welcome_page @@ -64,9 +62,12 @@ class Ui_FirstTimeWizard(object): first_time_wizard.setWindowIcon(build_icon(u':/icon/openlp-logo.svg')) first_time_wizard.resize(550, 386) first_time_wizard.setModal(True) - first_time_wizard.setWizardStyle(QtGui.QWizard.ModernStyle) first_time_wizard.setOptions(QtGui.QWizard.IndependentPages | QtGui.QWizard.NoBackButtonOnStartPage | QtGui.QWizard.NoBackButtonOnLastPage | QtGui.QWizard.HaveCustomButton1) + if is_macosx(): + first_time_wizard.setPixmap(QtGui.QWizard.BackgroundPixmap, + QtGui.QPixmap(':/wizards/openlp-osx-wizard.png')) + first_time_wizard.resize(634, 386) self.finish_button = self.button(QtGui.QWizard.FinishButton) self.no_internet_finish_button = self.button(QtGui.QWizard.CustomButton1) self.cancel_button = self.button(QtGui.QWizard.CancelButton) @@ -212,7 +213,8 @@ class Ui_FirstTimeWizard(object): translate('OpenLP.FirstTimeWizard', 'Welcome to the First Time Wizard')) self.information_label.setText( translate('OpenLP.FirstTimeWizard', 'This wizard will help you to configure OpenLP for initial use. ' - 'Click the next button below to start.')) + 'Click the %s button below to start.') % + self.buttonText(QtGui.QWizard.NextButton)) self.plugin_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Activate required Plugins')) self.plugin_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Select the Plugins you wish to use. ')) self.songs_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Songs')) @@ -236,7 +238,7 @@ class Ui_FirstTimeWizard(object): 'wizard by selecting "Tools/Re-run First Time Wizard" from OpenLP.') self.cancelWizardText = translate('OpenLP.FirstTimeWizard', '\n\nTo cancel the First Time Wizard completely (and not start OpenLP), ' - 'click the Cancel button now.') + 'click the %s button now.') % self.buttonText(QtGui.QWizard.CancelButton) self.songs_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Sample Songs')) self.songs_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Select and download public domain songs.')) self.bibles_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Sample Bibles')) diff --git a/openlp/core/ui/formattingtagform.py b/openlp/core/ui/formattingtagform.py index 4f3d5d251..96e25c27d 100644 --- a/openlp/core/ui/formattingtagform.py +++ b/openlp/core/ui/formattingtagform.py @@ -60,6 +60,12 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog, FormattingTagCont """ super(FormattingTagForm, self).__init__(parent) self.setupUi(self) + self._setup() + + def _setup(self): + """ + Set up the class. This method is mocked out by the tests. + """ self.services = FormattingTagController() self.tag_table_widget.itemSelectionChanged.connect(self.on_row_selected) self.new_button.clicked.connect(self.on_new_clicked) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 1a6b688c7..77a903c5f 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -92,6 +92,8 @@ class Ui_MainWindow(object): main_window.setObjectName('MainWindow') main_window.setWindowIcon(build_icon(':/icon/openlp-logo.svg')) main_window.setDockNestingEnabled(True) + if is_macosx(): + main_window.setDocumentMode(True) # Set up the main container, which contains all the other form widgets. self.main_content = QtGui.QWidget(main_window) self.main_content.setObjectName('main_content') @@ -118,10 +120,12 @@ class Ui_MainWindow(object): self.recent_files_menu = QtGui.QMenu(self.file_menu) self.recent_files_menu.setObjectName('recentFilesMenu') self.file_import_menu = QtGui.QMenu(self.file_menu) - self.file_import_menu.setIcon(build_icon(u':/general/general_import.png')) + if not is_macosx(): + self.file_import_menu.setIcon(build_icon(u':/general/general_import.png')) self.file_import_menu.setObjectName('file_import_menu') self.file_export_menu = QtGui.QMenu(self.file_menu) - self.file_export_menu.setIcon(build_icon(u':/general/general_export.png')) + if not is_macosx(): + self.file_export_menu.setIcon(build_icon(u':/general/general_export.png')) self.file_export_menu.setObjectName('file_export_menu') # View Menu self.view_menu = QtGui.QMenu(self.menu_bar) diff --git a/openlp/core/ui/themewizard.py b/openlp/core/ui/themewizard.py index bda52c807..50200313f 100644 --- a/openlp/core/ui/themewizard.py +++ b/openlp/core/ui/themewizard.py @@ -31,7 +31,7 @@ The Create/Edit theme wizard """ from PyQt4 import QtCore, QtGui -from openlp.core.common import UiStrings, translate +from openlp.core.common import UiStrings, translate, is_macosx from openlp.core.lib import build_icon from openlp.core.lib.theme import HorizontalType, BackgroundType, BackgroundGradientType from openlp.core.lib.ui import add_welcome_page, create_valign_selection_widgets @@ -41,19 +41,21 @@ class Ui_ThemeWizard(object): """ The Create/Edit theme wizard """ - def setupUi(self, themeWizard): + def setupUi(self, theme_wizard): """ Set up the UI """ - themeWizard.setObjectName('OpenLP.ThemeWizard') - themeWizard.setWindowIcon(build_icon(u':/icon/openlp-logo.svg')) - themeWizard.setModal(True) - themeWizard.setWizardStyle(QtGui.QWizard.ModernStyle) - themeWizard.setOptions(QtGui.QWizard.IndependentPages | - QtGui.QWizard.NoBackButtonOnStartPage | QtGui.QWizard.HaveCustomButton1) + theme_wizard.setObjectName('OpenLP.ThemeWizard') + theme_wizard.setWindowIcon(build_icon(u':/icon/openlp-logo.svg')) + theme_wizard.setModal(True) + theme_wizard.setOptions(QtGui.QWizard.IndependentPages | + QtGui.QWizard.NoBackButtonOnStartPage | QtGui.QWizard.HaveCustomButton1) + if is_macosx(): + theme_wizard.setPixmap(QtGui.QWizard.BackgroundPixmap, QtGui.QPixmap(':/wizards/openlp-osx-wizard.png')) + theme_wizard.resize(646, 400) self.spacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum) # Welcome Page - add_welcome_page(themeWizard, ':/wizards/wizard_createtheme.bmp') + add_welcome_page(theme_wizard, ':/wizards/wizard_createtheme.bmp') # Background Page self.background_page = QtGui.QWizardPage() self.background_page.setObjectName('background_page') @@ -137,7 +139,7 @@ class Ui_ThemeWizard(object): self.transparent_layout.setObjectName('Transparent_layout') self.background_stack.addWidget(self.transparent_widget) self.background_layout.addLayout(self.background_stack) - themeWizard.addPage(self.background_page) + theme_wizard.addPage(self.background_page) # Main Area Page self.main_area_page = QtGui.QWizardPage() self.main_area_page.setObjectName('main_area_page') @@ -218,7 +220,7 @@ class Ui_ThemeWizard(object): self.shadow_size_spin_box.setObjectName('shadow_size_spin_box') self.shadow_layout.addWidget(self.shadow_size_spin_box) self.main_area_layout.addRow(self.shadow_check_box, self.shadow_layout) - themeWizard.addPage(self.main_area_page) + theme_wizard.addPage(self.main_area_page) # Footer Area Page self.footer_area_page = QtGui.QWizardPage() self.footer_area_page.setObjectName('footer_area_page') @@ -242,7 +244,7 @@ class Ui_ThemeWizard(object): self.footer_size_spin_box.setObjectName('FooterSizeSpinBox') self.footer_area_layout.addRow(self.footer_size_label, self.footer_size_spin_box) self.footer_area_layout.setItem(3, QtGui.QFormLayout.LabelRole, self.spacer) - themeWizard.addPage(self.footer_area_page) + theme_wizard.addPage(self.footer_area_page) # Alignment Page self.alignment_page = QtGui.QWizardPage() self.alignment_page.setObjectName('alignment_page') @@ -264,7 +266,7 @@ class Ui_ThemeWizard(object): self.transitions_check_box.setObjectName('transitions_check_box') self.alignment_layout.addRow(self.transitions_label, self.transitions_check_box) self.alignment_layout.setItem(3, QtGui.QFormLayout.LabelRole, self.spacer) - themeWizard.addPage(self.alignment_page) + theme_wizard.addPage(self.alignment_page) # Area Position Page self.area_position_page = QtGui.QWizardPage() self.area_position_page.setObjectName('area_position_page') @@ -334,7 +336,7 @@ class Ui_ThemeWizard(object): self.footer_height_spin_box.setObjectName('footer_height_spin_box') self.footer_position_layout.addRow(self.footer_height_label, self.footer_height_spin_box) self.area_position_layout.addWidget(self.footer_position_group_box) - themeWizard.addPage(self.area_position_page) + theme_wizard.addPage(self.area_position_page) # Preview Page self.preview_page = QtGui.QWizardPage() self.preview_page.setObjectName('preview_page') @@ -362,8 +364,8 @@ class Ui_ThemeWizard(object): self.preview_box_label.setObjectName('preview_box_label') self.preview_area_layout.addWidget(self.preview_box_label) self.preview_layout.addWidget(self.preview_area) - themeWizard.addPage(self.preview_page) - self.retranslateUi(themeWizard) + theme_wizard.addPage(self.preview_page) + self.retranslateUi(theme_wizard) QtCore.QObject.connect(self.background_combo_box, QtCore.SIGNAL('currentIndexChanged(int)'), self.background_stack, QtCore.SLOT('setCurrentIndex(int)')) QtCore.QObject.connect(self.outline_check_box, QtCore.SIGNAL('toggled(bool)'), self.outline_color_button, @@ -391,11 +393,11 @@ class Ui_ThemeWizard(object): QtCore.QObject.connect(self.footer_position_check_box, QtCore.SIGNAL('toggled(bool)'), self.footer_height_spin_box, QtCore.SLOT('setDisabled(bool)')) - def retranslateUi(self, themeWizard): + def retranslateUi(self, theme_wizard): """ Translate the UI on the fly """ - themeWizard.setWindowTitle(translate('OpenLP.ThemeWizard', 'Theme Wizard')) + theme_wizard.setWindowTitle(translate('OpenLP.ThemeWizard', 'Theme Wizard')) self.title_label.setText('%s' % translate('OpenLP.ThemeWizard', 'Welcome to the Theme Wizard')) self.information_label.setText( @@ -484,8 +486,8 @@ class Ui_ThemeWizard(object): self.footer_height_label.setText(translate('OpenLP.ThemeWizard', 'Height:')) self.footer_height_spin_box.setSuffix(translate('OpenLP.ThemeWizard', 'px')) self.footer_position_check_box.setText(translate('OpenLP.ThemeWizard', 'Use default location')) - themeWizard.setOption(QtGui.QWizard.HaveCustomButton1, False) - themeWizard.setButtonText(QtGui.QWizard.CustomButton1, translate('OpenLP.ThemeWizard', 'Layout Preview')) + theme_wizard.setOption(QtGui.QWizard.HaveCustomButton1, False) + theme_wizard.setButtonText(QtGui.QWizard.CustomButton1, translate('OpenLP.ThemeWizard', 'Layout Preview')) self.preview_page.setTitle(translate('OpenLP.ThemeWizard', 'Preview and Save')) self.preview_page.setSubTitle(translate('OpenLP.ThemeWizard', 'Preview the theme and save it.')) self.theme_name_label.setText(translate('OpenLP.ThemeWizard', 'Theme name:')) diff --git a/openlp/core/ui/wizard.py b/openlp/core/ui/wizard.py index 23bc0a9e1..7199d1742 100644 --- a/openlp/core/ui/wizard.py +++ b/openlp/core/ui/wizard.py @@ -34,7 +34,7 @@ import os from PyQt4 import QtGui -from openlp.core.common import Registry, RegistryProperties, Settings, UiStrings, translate +from openlp.core.common import Registry, RegistryProperties, Settings, UiStrings, translate, is_macosx from openlp.core.lib import build_icon from openlp.core.lib.ui import add_welcome_page @@ -121,9 +121,10 @@ class OpenLPWizard(QtGui.QWizard, RegistryProperties): """ self.setWindowIcon(build_icon(u':/icon/openlp-logo.svg')) self.setModal(True) - self.setWizardStyle(QtGui.QWizard.ModernStyle) self.setOptions(QtGui.QWizard.IndependentPages | QtGui.QWizard.NoBackButtonOnStartPage | QtGui.QWizard.NoBackButtonOnLastPage) + if is_macosx(): + self.setPixmap(QtGui.QWizard.BackgroundPixmap, QtGui.QPixmap(':/wizards/openlp-osx-wizard.png')) add_welcome_page(self, image) self.add_custom_pages() if self.with_progress_page: diff --git a/resources/images/openlp-2.qrc b/resources/images/openlp-2.qrc index d61166acc..0347cc3c7 100644 --- a/resources/images/openlp-2.qrc +++ b/resources/images/openlp-2.qrc @@ -99,6 +99,7 @@ export_load.png + openlp-osx-wizard.png wizard_exportsong.bmp wizard_importsong.bmp wizard_importbible.bmp @@ -151,10 +152,10 @@ messagebox_warning.png - network_server.png + network_server.png network_ssl.png - network_auth.png - + network_auth.png + song_usage_active.png song_usage_inactive.png diff --git a/resources/images/openlp-osx-wizard.png b/resources/images/openlp-osx-wizard.png new file mode 100644 index 000000000..79437b5ed Binary files /dev/null and b/resources/images/openlp-osx-wizard.png differ diff --git a/tests/functional/openlp_core_lib/test_theme.py b/tests/functional/openlp_core_lib/test_theme.py index bcdced35f..7b09135dc 100644 --- a/tests/functional/openlp_core_lib/test_theme.py +++ b/tests/functional/openlp_core_lib/test_theme.py @@ -51,7 +51,7 @@ class TestTheme(TestCase): """ pass - def test_new_theme(self): + def new_theme_test(self): """ Test the theme creation - basic test """ diff --git a/tests/functional/openlp_core_lib/test_ui.py b/tests/functional/openlp_core_lib/test_ui.py index 02f9ce4fa..7030c27f3 100644 --- a/tests/functional/openlp_core_lib/test_ui.py +++ b/tests/functional/openlp_core_lib/test_ui.py @@ -29,10 +29,14 @@ """ Package to test the openlp.core.lib.ui package. """ -from PyQt4 import QtGui +from PyQt4 import QtCore, QtGui from unittest import TestCase -from openlp.core.lib.ui import * +from openlp.core.common import UiStrings, translate +from openlp.core.lib.ui import add_welcome_page, create_button_box, create_horizontal_adjusting_combo_box, \ + create_button, create_action, create_valign_selection_widgets, find_and_set_in_combo_box, create_widget_action, \ + set_case_insensitive_completer +from tests.functional import MagicMock, patch class TestUi(TestCase): @@ -154,6 +158,43 @@ class TestUi(TestCase): self.assertEqual('my tooltip', action.toolTip()) self.assertEqual('my statustip', action.statusTip()) + def create_action_on_mac_osx_test(self): + """ + Test creating an action on OS X calls the correct method + """ + # GIVEN: A dialog and a mocked out is_macosx() method to always return True + with patch('openlp.core.lib.ui.is_macosx') as mocked_is_macosx, \ + patch('openlp.core.lib.ui.QtGui.QAction') as MockedQAction: + mocked_is_macosx.return_value = True + mocked_action = MagicMock() + MockedQAction.return_value = mocked_action + dialog = QtGui.QDialog() + + # WHEN: An action is created + create_action(dialog, 'my_action') + + # THEN: setIconVisibleInMenu should be called + mocked_action.setIconVisibleInMenu.assert_called_with(False) + + def create_action_not_on_mac_osx_test(self): + """ + Test creating an action on something other than OS X doesn't call the method + """ + # GIVEN: A dialog and a mocked out is_macosx() method to always return True + with patch('openlp.core.lib.ui.is_macosx') as mocked_is_macosx, \ + patch('openlp.core.lib.ui.QtGui.QAction') as MockedQAction: + mocked_is_macosx.return_value = False + mocked_action = MagicMock() + MockedQAction.return_value = mocked_action + dialog = QtGui.QDialog() + + # WHEN: An action is created + create_action(dialog, 'my_action') + + # THEN: setIconVisibleInMenu should not be called + self.assertEqual(0, mocked_action.setIconVisibleInMenu.call_count, + 'setIconVisibleInMenu should not have been called') + def create_checked_disabled_invisible_action_test(self): """ Test that an invisible, disabled, checked action is created correctly diff --git a/tests/functional/openlp_core_ui/test_firsttimeform.py b/tests/functional/openlp_core_ui/test_firsttimeform.py index 2e26c286a..35bd1675d 100644 --- a/tests/functional/openlp_core_ui/test_firsttimeform.py +++ b/tests/functional/openlp_core_ui/test_firsttimeform.py @@ -47,7 +47,7 @@ class TestFirstTimeForm(TestCase, TestMixin): Registry().register('application', self.app) self.first_time_form = FirstTimeForm(screens) - def test_access_to_config(self): + def access_to_config_test(self): """ Test if we can access the First Time Form's config file """ @@ -59,7 +59,7 @@ class TestFirstTimeForm(TestCase, TestMixin): self.assertTrue(self.first_time_form.web_access, 'First Time Wizard\'s web configuration file should be available') - def test_parsable_config(self): + def parsable_config_test(self): """ Test if the First Time Form's config file is parsable """ diff --git a/tests/functional/openlp_core_ui/test_formattingtagscontroller.py b/tests/functional/openlp_core_ui/test_formattingtagscontroller.py index 1d8512940..38cae0bf4 100644 --- a/tests/functional/openlp_core_ui/test_formattingtagscontroller.py +++ b/tests/functional/openlp_core_ui/test_formattingtagscontroller.py @@ -39,7 +39,7 @@ class TestFormattingTagController(TestCase): def setUp(self): self.services = FormattingTagController() - def test_strip(self): + def strip_test(self): """ Test that the _strip strips the correct chars """ @@ -52,7 +52,7 @@ class TestFormattingTagController(TestCase): # THEN: The tag should be returned with the wrappers removed. self.assertEqual(result, 'tag', 'FormattingTagForm._strip should return u\'tag\' when called with u\'{tag}\'') - def test_end_tag_changed_processes_correctly(self): + def end_tag_changed_processes_correctly_test(self): """ Test that the end html tags are generated correctly """ @@ -77,7 +77,7 @@ class TestFormattingTagController(TestCase): self.assertTrue(error == test['valid'], 'Function should not generate unexpected error messages : %s ' % error) - def test_start_tag_changed_processes_correctly(self): + def start_tag_changed_processes_correctly_test(self): """ Test that the end html tags are generated correctly """ @@ -100,7 +100,7 @@ class TestFormattingTagController(TestCase): self.assertTrue(error == test['valid'], 'Function should not generate unexpected error messages : %s ' % error) - def test_start_html_to_end_html(self): + def start_html_to_end_html_test(self): """ Test that the end html tags are generated correctly """ diff --git a/tests/functional/openlp_core_ui/test_formattingtagsform.py b/tests/functional/openlp_core_ui/test_formattingtagsform.py index e71a75651..736a306c3 100644 --- a/tests/functional/openlp_core_ui/test_formattingtagsform.py +++ b/tests/functional/openlp_core_ui/test_formattingtagsform.py @@ -29,17 +29,17 @@ """ Package to test the openlp.core.ui.formattingtagsform package. """ +from PyQt4 import QtGui from unittest import TestCase +from openlp.core.common import translate -from tests.functional import MagicMock, patch +from tests.functional import MagicMock, patch, call from openlp.core.ui.formattingtagform import FormattingTagForm # TODO: Tests Still TODO # __init__ # exec_ -# on_new_clicked -# on_delete_clicked # on_saved_clicked # _reloadTable @@ -47,30 +47,60 @@ from openlp.core.ui.formattingtagform import FormattingTagForm class TestFormattingTagForm(TestCase): def setUp(self): - self.init_patcher = patch('openlp.core.ui.formattingtagform.FormattingTagForm.__init__') - self.qdialog_patcher = patch('openlp.core.ui.formattingtagform.QtGui.QDialog') - self.ui_formatting_tag_dialog_patcher = patch('openlp.core.ui.formattingtagform.Ui_FormattingTagDialog') - self.mocked_init = self.init_patcher.start() - self.mocked_qdialog = self.qdialog_patcher.start() - self.mocked_ui_formatting_tag_dialog = self.ui_formatting_tag_dialog_patcher.start() - self.mocked_init.return_value = None + """ + Mock out stuff for all the tests + """ + self.setup_patcher = patch('openlp.core.ui.formattingtagform.FormattingTagForm._setup') + self.setup_patcher.start() def tearDown(self): - self.init_patcher.stop() - self.qdialog_patcher.stop() - self.ui_formatting_tag_dialog_patcher.stop() - - def test_on_text_edited(self): """ - Test that the appropriate actions are preformed when on_text_edited is called + Remove the mocks + """ + self.setup_patcher.stop() + + def on_row_selected_test(self): + """ + Test that the appropriate actions are preformed when on_row_selected is called + """ + # GIVEN: An instance of the Formatting Tag Form and a mocked delete_button + form = FormattingTagForm(None) + form.delete_button = MagicMock() + + # WHEN: on_row_selected is called + form.on_row_selected() + + # THEN: setEnabled and should have been called on delete_button + form.delete_button.setEnabled.assert_called_with(True) + + def on_new_clicked_test(self): + """ + Test that clicking the Add a new tag button does the right thing """ - # GIVEN: An instance of the Formatting Tag Form and a mocked save_push_button - form = FormattingTagForm() - form.save_button = MagicMock() + # GIVEN: A formatting tag form and a mocked out tag table widget + form = FormattingTagForm(None) + form.tag_table_widget = MagicMock() + row_count = 5 + form.tag_table_widget.rowCount.return_value = row_count - # WHEN: on_text_edited is called with an arbitrary value - # form.on_text_edited('text') + # WHEN: on_new_clicked is run (i.e. the Add new button was clicked) + with patch('openlp.core.ui.formattingtagform.QtGui.QTableWidgetItem') as MockedQTableWidgetItem: + mocked_table_widget = MagicMock() + MockedQTableWidgetItem.return_value = mocked_table_widget + form.on_new_clicked() - # THEN: setEnabled and setDefault should have been called on save_push_button - # form.save_button.setEnabled.assert_called_with(True) + # THEN: A new row should be added to the table + form.tag_table_widget.rowCount.assert_called_with() + form.tag_table_widget.insertRow.assert_called_with(row_count) + expected_set_item_calls = [ + call(row_count, 0, mocked_table_widget), + call(row_count, 1, mocked_table_widget), + call(row_count, 2, mocked_table_widget), + call(row_count, 3, mocked_table_widget) + ] + self.assertEqual(expected_set_item_calls, form.tag_table_widget.setItem.call_args_list, + 'setItem should have been called correctly') + form.tag_table_widget.resizeRowsToContents.assert_called_with() + form.tag_table_widget.scrollToBottom.assert_called_with() + form.tag_table_widget.selectRow.assert_called_with(row_count)