From 551a10d311f463235b071011c527345ddf03a9e8 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 22 Oct 2014 22:43:05 +0200 Subject: [PATCH] Added and updated tests: - Refactored FirstTimeForm to use an initalise() method, in order to be more testable - Rewrote FTW tests to test initialise() - Refactored TestMixin get_application() to setup_application() since it doesn't actually return an application object - Refactored ListPreviewWidget to make it more testable - Wrote tests for ListPreviewWidget - Refactored FormattingTagsForm somewhat - Updated FormattingTagsForm tests Updated setup.py with some Python3 changes. --- openlp/core/__init__.py | 4 +- openlp/core/ui/firsttimeform.py | 93 ++++++++++--------- openlp/core/ui/firsttimewizard.py | 27 +++--- openlp/core/ui/listpreviewwidget.py | 35 +++++-- openlp/core/ui/mainwindow.py | 4 +- openlp/core/utils/__init__.py | 40 +++++--- resources/__init__.py | 34 ------- setup.py | 1 + .../openlp_core_common/test_settings.py | 2 +- .../openlp_core_lib/test_image_manager.py | 2 +- .../openlp_core_ui/test_firsttimeform.py | 70 ++++++++++---- .../openlp_core_ui/test_formattingtagsform.py | 2 - .../openlp_core_ui/test_mainwindow.py | 2 +- .../presentations/test_impresscontroller.py | 2 +- .../presentations/test_mediaitem.py | 2 +- .../presentations/test_pdfcontroller.py | 2 +- .../test_powerpointcontroller.py | 4 +- .../presentations/test_pptviewcontroller.py | 2 +- .../openlp_plugins/remotes/test_remotetab.py | 2 +- .../openlp_plugins/remotes/test_router.py | 2 +- .../openlp_plugins/songs/test_mediaitem.py | 2 +- tests/helpers/testmixin.py | 5 +- .../test_historycombobox.py | 2 +- .../openlp_core_lib/test_pluginmanager.py | 2 +- .../openlp_core_lib/test_searchedit.py | 2 +- .../openlp_core_ui/test_filerenamedialog.py | 2 +- .../openlp_core_ui/test_listpreviewwidget.py | 2 +- .../openlp_core_ui/test_mainwindow.py | 2 +- .../openlp_core_ui/test_servicemanager.py | 2 +- .../openlp_core_ui/test_servicenotedialog.py | 2 +- .../openlp_core_ui/test_settings_form.py | 2 +- .../openlp_core_ui/test_shortcutlistform.py | 2 +- .../openlp_core_ui/test_starttimedialog.py | 2 +- .../openlp_core_ui/test_thememanager.py | 2 +- .../openlp_core_utils/test_utils.py | 2 +- .../custom/forms/test_customform.py | 2 +- .../custom/forms/test_customslideform.py | 2 +- .../media/forms/test_mediaclipselectorform.py | 2 +- .../songs/forms/test_authorsform.py | 2 +- .../songs/forms/test_editsongform.py | 2 +- .../songs/forms/test_editverseform.py | 2 +- .../songs/forms/test_topicsform.py | 2 +- 42 files changed, 212 insertions(+), 167 deletions(-) delete mode 100644 resources/__init__.py diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index cb9105797..259c98f73 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -117,7 +117,9 @@ class OpenLP(OpenLPMixin, QtGui.QApplication): # First time checks in settings has_run_wizard = Settings().value('core/has run wizard') if not has_run_wizard: - if FirstTimeForm(screens).exec_() == QtGui.QDialog.Accepted: + ftw = FirstTimeForm() + ftw.initialize(screens) + if ftw.exec_() == QtGui.QDialog.Accepted: Settings().setValue('core/has run wizard', True) # Correct stylesheet bugs application_stylesheet = '' diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index 8599c8d35..ea31181d7 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -44,7 +44,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.common import Registry, RegistryProperties, AppLocation, Settings, check_directory_exists, translate from openlp.core.lib import PluginStatus, build_icon from openlp.core.utils import get_web_page -from .firsttimewizard import Ui_FirstTimeWizard, FirstTimePage +from .firsttimewizard import UiFirstTimeWizard, FirstTimePage log = logging.getLogger(__name__) @@ -75,18 +75,58 @@ class ThemeScreenshotThread(QtCore.QThread): item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable) -class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard, RegistryProperties): +class FirstTimeForm(QtGui.QWizard, UiFirstTimeWizard, RegistryProperties): """ This is the Theme Import Wizard, which allows easy creation and editing of OpenLP themes. """ log.info('ThemeWizardForm loaded') - def __init__(self, screens, parent=None): + def __init__(self, parent=None): """ Create and set up the first time wizard. """ super(FirstTimeForm, self).__init__(parent) - self.setupUi(self) + self.setup_ui(self) + + def nextId(self): + """ + Determine the next page in the Wizard to go to. + """ + self.application.process_events() + if self.currentId() == FirstTimePage.Plugins: + if not self.web_access: + return FirstTimePage.NoInternet + else: + return FirstTimePage.Songs + elif self.currentId() == FirstTimePage.Progress: + return -1 + elif self.currentId() == FirstTimePage.NoInternet: + return FirstTimePage.Progress + elif self.currentId() == FirstTimePage.Themes: + self.application.set_busy_cursor() + while not self.theme_screenshot_thread.isFinished(): + time.sleep(0.1) + self.application.process_events() + # Build the screenshot icons, as this can not be done in the thread. + self._build_theme_screenshots() + self.application.set_normal_cursor() + return FirstTimePage.Defaults + else: + return self.currentId() + 1 + + def exec_(self): + """ + Run the wizard. + """ + self.set_defaults() + return QtGui.QWizard.exec_(self) + + def initialize(self, screens): + """ + Set up the First Time Wizard + + :param screens: The screens detected by OpenLP + """ self.screens = screens # check to see if we have web access self.web = 'http://openlp.org/files/frw/' @@ -110,13 +150,6 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard, RegistryProperties): self.currentIdChanged.connect(self.on_current_id_changed) Registry().register_function('config_screen_changed', self.update_screen_list_combo) - def exec_(self): - """ - Run the wizard. - """ - self.set_defaults() - return QtGui.QWizard.exec_(self) - def set_defaults(self): """ Set up display at start of theme edit. @@ -157,31 +190,14 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard, RegistryProperties): self.theme_screenshot_thread.start() self.application.set_normal_cursor() - def nextId(self): + def update_screen_list_combo(self): """ - Determine the next page in the Wizard to go to. + The user changed screen resolution or enabled/disabled more screens, so + we need to update the combo box. """ - self.application.process_events() - if self.currentId() == FirstTimePage.Plugins: - if not self.web_access: - return FirstTimePage.NoInternet - else: - return FirstTimePage.Songs - elif self.currentId() == FirstTimePage.Progress: - return -1 - elif self.currentId() == FirstTimePage.NoInternet: - return FirstTimePage.Progress - elif self.currentId() == FirstTimePage.Themes: - self.application.set_busy_cursor() - while not self.theme_screenshot_thread.isFinished(): - time.sleep(0.1) - self.application.process_events() - # Build the screenshot icons, as this can not be done in the thread. - self._build_theme_screenshots() - self.application.set_normal_cursor() - return FirstTimePage.Defaults - else: - return self.currentId() + 1 + self.display_combo_box.clear() + self.display_combo_box.addItems(self.screens.get_screen_list()) + self.display_combo_box.setCurrentIndex(self.display_combo_box.count() - 1) def on_current_id_changed(self, page_id): """ @@ -230,15 +246,6 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard, RegistryProperties): self._post_wizard() self.application.set_normal_cursor() - def update_screen_list_combo(self): - """ - The user changed screen resolution or enabled/disabled more screens, so - we need to update the combo box. - """ - self.display_combo_box.clear() - self.display_combo_box.addItems(self.screens.get_screen_list()) - self.display_combo_box.setCurrentIndex(self.display_combo_box.count() - 1) - def on_cancel_button_clicked(self): """ Process the triggering of the cancel button. diff --git a/openlp/core/ui/firsttimewizard.py b/openlp/core/ui/firsttimewizard.py index 18d167371..a3c8dd7b2 100644 --- a/openlp/core/ui/firsttimewizard.py +++ b/openlp/core/ui/firsttimewizard.py @@ -50,13 +50,15 @@ class FirstTimePage(object): Progress = 7 -class Ui_FirstTimeWizard(object): +class UiFirstTimeWizard(object): """ The UI widgets for the first time wizard. """ - def setupUi(self, first_time_wizard): + def setup_ui(self, first_time_wizard): """ Set up the UI. + + :param first_time_wizard: The wizard form """ first_time_wizard.setObjectName('first_time_wizard') first_time_wizard.setWindowIcon(build_icon(u':/icon/openlp-logo.svg')) @@ -204,19 +206,21 @@ class Ui_FirstTimeWizard(object): self.progress_bar.setObjectName('progress_bar') self.progress_layout.addWidget(self.progress_bar) first_time_wizard.setPage(FirstTimePage.Progress, self.progress_page) - self.retranslateUi(first_time_wizard) + self.retranslate_ui(first_time_wizard) - def retranslateUi(self, first_time_wizard): + def retranslate_ui(self, first_time_wizard): """ Translate the UI on the fly + + :param first_time_wizard: The wizard form """ first_time_wizard.setWindowTitle(translate('OpenLP.FirstTimeWizard', 'First Time Wizard')) - self.title_label.setText('%s' % - translate('OpenLP.FirstTimeWizard', 'Welcome to the First Time Wizard')) - self.information_label.setText( + first_time_wizard.title_label.setText('%s' % + translate('OpenLP.FirstTimeWizard', 'Welcome to the First Time Wizard')) + first_time_wizard.information_label.setText( translate('OpenLP.FirstTimeWizard', 'This wizard will help you to configure OpenLP for initial use. ' 'Click the %s button below to start.') % - self.buttonText(QtGui.QWizard.NextButton)) + first_time_wizard.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')) @@ -238,9 +242,10 @@ class Ui_FirstTimeWizard(object): 'no sample data.\n\nTo re-run the First Time Wizard and import this sample ' 'data at a later time, check your Internet connection and re-run this ' '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 %s button now.') % self.buttonText(QtGui.QWizard.CancelButton) + self.cancel_wizard_text = translate('OpenLP.FirstTimeWizard', + '\n\nTo cancel the First Time Wizard completely (and not start OpenLP), ' + 'click the %s button now.') % \ + first_time_wizard.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/listpreviewwidget.py b/openlp/core/ui/listpreviewwidget.py index 3909c6a31..cd8aaa260 100644 --- a/openlp/core/ui/listpreviewwidget.py +++ b/openlp/core/ui/listpreviewwidget.py @@ -38,17 +38,30 @@ from openlp.core.lib import ImageSource, ServiceItem class ListPreviewWidget(QtGui.QTableWidget, RegistryProperties): + """ + A special type of QTableWidget which lists the slides in the slide controller + + :param parent: + :param screen_ratio: + """ + def __init__(self, parent, screen_ratio): """ Initializes the widget to default state. - An empty ServiceItem is used per default. - One needs to call replace_service_manager_item() to make this widget display something. + + An empty ``ServiceItem`` is used by default. replace_service_manager_item() needs to be called to make this + widget display something. """ super(QtGui.QTableWidget, self).__init__(parent) - # Set up the widget. + self._setup(screen_ratio) + + def _setup(self, screen_ratio): + """ + Set up the widget + """ self.setColumnCount(1) self.horizontalHeader().setVisible(False) - self.setColumnWidth(0, parent.width()) + self.setColumnWidth(0, self.parent().width()) self.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.setSelectionMode(QtGui.QAbstractItemView.SingleSelection) self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers) @@ -58,7 +71,7 @@ class ListPreviewWidget(QtGui.QTableWidget, RegistryProperties): self.service_item = ServiceItem() self.screen_ratio = screen_ratio - def resizeEvent(self, QResizeEvent): + def resizeEvent(self, event): """ Overloaded method from QTableWidget. Will recalculate the layout. """ @@ -82,16 +95,20 @@ class ListPreviewWidget(QtGui.QTableWidget, RegistryProperties): def screen_size_changed(self, screen_ratio): """ - To be called whenever the live screen size changes. - Because this makes a layout recalculation necessary. + This method is called whenever the live screen size changes, which then makes a layout recalculation necessary + + :param screen_ratio: The new screen ratio """ self.screen_ratio = screen_ratio self.__recalculate_layout() def replace_service_item(self, service_item, width, slide_number): """ - Replaces the current preview items with the ones in service_item. - Displays the given slide. + Replace the current preview items with the ones in service_item and display the given slide + + :param service_item: The service item to insert + :param width: The width of the column + :param slide_number: The slide number to pre-select """ self.service_item = service_item self.setRowCount(0) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 77a903c5f..bc6922d3e 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -655,8 +655,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow, RegistryProperties): QtGui.QMessageBox.No) if answer == QtGui.QMessageBox.No: return - screens = ScreenList() - first_run_wizard = FirstTimeForm(screens, self) + first_run_wizard = FirstTimeForm(self) + first_run_wizard.initialize(ScreenList()) first_run_wizard.exec_() if first_run_wizard.was_download_cancelled: return diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 983c0cfd0..02bd62b41 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -52,6 +52,7 @@ if not is_win() and not is_macosx(): from xdg import BaseDirectory XDG_BASE_AVAILABLE = True except ImportError: + BaseDirectory = None XDG_BASE_AVAILABLE = False from openlp.core.common import translate @@ -114,14 +115,25 @@ class HTTPRedirectHandlerFixed(urllib.request.HTTPRedirectHandler): Special HTTPRedirectHandler used to work around http://bugs.python.org/issue22248 (Redirecting to urls with special chars) """ - def redirect_request(self, req, fp, code, msg, headers, newurl): - # Test if the newurl can be decoded to ascii + def redirect_request(self, req, fp, code, msg, headers, new_url): + # + """ + Test if the new_url can be decoded to ascii + + :param req: + :param fp: + :param code: + :param msg: + :param headers: + :param new_url: + :return: + """ try: - test_url = newurl.encode('latin1').decode('ascii') - fixed_url = newurl + new_url.encode('latin1').decode('ascii') + fixed_url = new_url except Exception: # The url could not be decoded to ascii, so we do some url encoding - fixed_url = urllib.parse.quote(newurl.encode('latin1').decode('utf-8', 'replace'), safe='/:') + fixed_url = urllib.parse.quote(new_url.encode('latin1').decode('utf-8', 'replace'), safe='/:') return super(HTTPRedirectHandlerFixed, self).redirect_request(req, fp, code, msg, headers, fixed_url) @@ -170,18 +182,18 @@ def get_application_version(): full_version = '%s-bzr%s' % (tag_version.decode('utf-8'), tree_revision.decode('utf-8')) else: # We're not running the development version, let's use the file. - filepath = AppLocation.get_directory(AppLocation.VersionDir) - filepath = os.path.join(filepath, '.version') - fversion = None + file_path = AppLocation.get_directory(AppLocation.VersionDir) + file_path = os.path.join(file_path, '.version') + version_file = None try: - fversion = open(filepath, 'r') - full_version = str(fversion.read()).rstrip() + version_file = open(file_path, 'r') + full_version = str(version_file.read()).rstrip() except IOError: log.exception('Error in version file.') full_version = '0.0.0-bzr000' finally: - if fversion: - fversion.close() + if version_file: + version_file.close() bits = full_version.split('-') APPLICATION_VERSION = { 'full': full_version, @@ -200,13 +212,13 @@ def check_latest_version(current_version): Check the latest version of OpenLP against the version file on the OpenLP site. - :param current_version: The current version of OpenLP. - **Rules around versions and version files:** * If a version number has a build (i.e. -bzr1234), then it is a nightly. * If a version number's minor version is an odd number, it is a development release. * If a version number's minor version is an even number, it is a stable release. + + :param current_version: The current version of OpenLP. """ version_string = current_version['full'] # set to prod in the distribution config file. diff --git a/resources/__init__.py b/resources/__init__.py deleted file mode 100644 index 1bfef8133..000000000 --- a/resources/__init__.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2014 Raoul Snyman # -# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # -# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # -# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # -# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # -# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # -# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # -# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # -# --------------------------------------------------------------------------- # -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### -""" -The :mod:`resources` module contains a bunch of resources for OpenLP. - -DO NOT REMOVE THIS FILE, IT IS REQUIRED FOR INCLUDING THE RESOURCES ON SOME -PLATFORMS! -""" diff --git a/setup.py b/setup.py index 356710edb..ae914dec1 100755 --- a/setup.py +++ b/setup.py @@ -74,6 +74,7 @@ def natural_sort(seq): # NOTE: The following code is a duplicate of the code in openlp/core/utils/__init__.py. Any fix applied here should also # be applied there. +ver_file = None try: # Get the revision of this tree. bzr = Popen(('bzr', 'revno'), stdout=PIPE) diff --git a/tests/functional/openlp_core_common/test_settings.py b/tests/functional/openlp_core_common/test_settings.py index 8c2ef92d6..ea4bcf849 100644 --- a/tests/functional/openlp_core_common/test_settings.py +++ b/tests/functional/openlp_core_common/test_settings.py @@ -43,7 +43,7 @@ class TestSettings(TestCase, TestMixin): """ Create the UI """ - self.get_application() + self.setup_application() self.build_settings() def tearDown(self): diff --git a/tests/functional/openlp_core_lib/test_image_manager.py b/tests/functional/openlp_core_lib/test_image_manager.py index 293e890d6..a8c395893 100644 --- a/tests/functional/openlp_core_lib/test_image_manager.py +++ b/tests/functional/openlp_core_lib/test_image_manager.py @@ -52,7 +52,7 @@ class TestImageManager(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() ScreenList.create(self.app.desktop()) self.image_manager = ImageManager() self.lock = Lock() diff --git a/tests/functional/openlp_core_ui/test_firsttimeform.py b/tests/functional/openlp_core_ui/test_firsttimeform.py index 35bd1675d..ed7a7a9e8 100644 --- a/tests/functional/openlp_core_ui/test_firsttimeform.py +++ b/tests/functional/openlp_core_ui/test_firsttimeform.py @@ -29,44 +29,78 @@ """ Package to test the openlp.core.ui.firsttimeform package. """ +from configparser import ConfigParser from unittest import TestCase from openlp.core.common import Registry from openlp.core.ui.firsttimeform import FirstTimeForm -from tests.functional import MagicMock +from tests.functional import MagicMock, patch from tests.helpers.testmixin import TestMixin +FAKE_CONFIG = b""" +[general] +base url = http://example.com/frw/ +[songs] +directory = songs +[bibles] +directory = bibles +[themes] +directory = themes +""" + class TestFirstTimeForm(TestCase, TestMixin): def setUp(self): - screens = MagicMock() - self.get_application() + self.setup_application() + self.app.setApplicationVersion('0.0') Registry.create() Registry().register('application', self.app) - self.first_time_form = FirstTimeForm(screens) - def access_to_config_test(self): + def basic_initialise_test(self): """ - Test if we can access the First Time Form's config file + Test if we can intialise the FirstTimeForm without a config file """ - # GIVEN A new First Time Form instance. + # GIVEN: A mocked get_web_page, a First Time Wizard and an expected screen object + with patch('openlp.core.ui.firsttimeform.get_web_page') as mocked_get_web_page: + first_time_form = FirstTimeForm(None) + expected_screens = MagicMock() + expected_web_url = 'http://openlp.org/files/frw/' + expected_user_agent = 'OpenLP/0.0' + mocked_get_web_page.return_value = None - # WHEN The default First Time Form is built. + # WHEN: The First Time Wizard is initialised + first_time_form.initialize(expected_screens) - # THEN The First Time Form web configuration file should be accessable. - self.assertTrue(self.first_time_form.web_access, - 'First Time Wizard\'s web configuration file should be available') + # THEN: The First Time Form web configuration file should be accessible and parseable + self.assertEqual(expected_screens, first_time_form.screens, 'The screens should be correct') + self.assertEqual(expected_web_url, first_time_form.web, 'The base path of the URL should be correct') + self.assertIsInstance(first_time_form.config, ConfigParser, 'The config object should be a ConfigParser') + mocked_get_web_page.assert_called_with(expected_web_url + 'download.cfg', + header=('User-Agent', expected_user_agent)) - def parsable_config_test(self): + def config_initialise_test(self): """ - Test if the First Time Form's config file is parsable + Test if we can intialise the FirstTimeForm with a config file """ - # GIVEN A new First Time Form instance. + # GIVEN: A mocked get_web_page, a First Time Wizard and an expected screen object + with patch('openlp.core.ui.firsttimeform.get_web_page') as mocked_get_web_page: + first_time_form = FirstTimeForm(None) + expected_web_url = 'http://openlp.org/files/frw/' + expected_songs_url = 'http://example.com/frw/songs/' + expected_bibles_url = 'http://example.com/frw/bibles/' + expected_themes_url = 'http://example.com/frw/themes/' + expected_user_agent = 'OpenLP/0.0' + mocked_get_web_page.return_value.read.return_value = FAKE_CONFIG - # WHEN The default First Time Form is built. + # WHEN: The First Time Wizard is initialised + first_time_form.initialize(MagicMock()) - # THEN The First Time Form web configuration file should be parsable - self.assertTrue(self.first_time_form.songs_url, - 'First Time Wizard\'s web configuration file should be parsable') + # THEN: The First Time Form web configuration file should be accessible and parseable + self.assertIsInstance(first_time_form.config, ConfigParser, 'The config object should be a ConfigParser') + mocked_get_web_page.assert_called_with(expected_web_url + 'download.cfg', + header=('User-Agent', expected_user_agent)) + self.assertEqual(expected_songs_url, first_time_form.songs_url, 'The songs URL should be correct') + self.assertEqual(expected_bibles_url, first_time_form.bibles_url, 'The bibles URL should be correct') + self.assertEqual(expected_themes_url, first_time_form.themes_url, 'The themes URL should be correct') diff --git a/tests/functional/openlp_core_ui/test_formattingtagsform.py b/tests/functional/openlp_core_ui/test_formattingtagsform.py index 736a306c3..f006300dc 100644 --- a/tests/functional/openlp_core_ui/test_formattingtagsform.py +++ b/tests/functional/openlp_core_ui/test_formattingtagsform.py @@ -29,9 +29,7 @@ """ 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, call diff --git a/tests/functional/openlp_core_ui/test_mainwindow.py b/tests/functional/openlp_core_ui/test_mainwindow.py index b348f8f80..e3d1fc445 100644 --- a/tests/functional/openlp_core_ui/test_mainwindow.py +++ b/tests/functional/openlp_core_ui/test_mainwindow.py @@ -46,7 +46,7 @@ class TestMainWindow(TestCase, TestMixin): def setUp(self): Registry.create() self.registry = Registry() - self.get_application() + self.setup_application() # Mock cursor busy/normal methods. self.app.set_busy_cursor = MagicMock() self.app.set_normal_cursor = MagicMock() diff --git a/tests/functional/openlp_plugins/presentations/test_impresscontroller.py b/tests/functional/openlp_plugins/presentations/test_impresscontroller.py index bb3b43732..7be922f19 100644 --- a/tests/functional/openlp_plugins/presentations/test_impresscontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_impresscontroller.py @@ -51,7 +51,7 @@ class TestImpressController(TestCase, TestMixin): """ Set up the patches and mocks need for all tests. """ - self.get_application() + self.setup_application() self.build_settings() self.mock_plugin = MagicMock() self.temp_folder = mkdtemp() diff --git a/tests/functional/openlp_plugins/presentations/test_mediaitem.py b/tests/functional/openlp_plugins/presentations/test_mediaitem.py index 2210c7d1f..ffb2564e1 100644 --- a/tests/functional/openlp_plugins/presentations/test_mediaitem.py +++ b/tests/functional/openlp_plugins/presentations/test_mediaitem.py @@ -51,7 +51,7 @@ class TestMediaItem(TestCase, TestMixin): 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()) - self.get_application() + self.setup_application() def build_file_mask_string_test(self): """ diff --git a/tests/functional/openlp_plugins/presentations/test_pdfcontroller.py b/tests/functional/openlp_plugins/presentations/test_pdfcontroller.py index 277e83a5b..f094a2bf1 100644 --- a/tests/functional/openlp_plugins/presentations/test_pdfcontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_pdfcontroller.py @@ -61,7 +61,7 @@ class TestPdfController(TestCase, TestMixin): """ Set up the components need for all tests. """ - self.get_application() + self.setup_application() self.build_settings() # Mocked out desktop object self.desktop = MagicMock() diff --git a/tests/functional/openlp_plugins/presentations/test_powerpointcontroller.py b/tests/functional/openlp_plugins/presentations/test_powerpointcontroller.py index b74f7b6fc..8d0ba7cfa 100644 --- a/tests/functional/openlp_plugins/presentations/test_powerpointcontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_powerpointcontroller.py @@ -55,7 +55,7 @@ class TestPowerpointController(TestCase, TestMixin): """ Set up the patches and mocks need for all tests. """ - self.get_application() + self.setup_application() self.build_settings() self.mock_plugin = MagicMock() self.temp_folder = mkdtemp() @@ -92,7 +92,7 @@ class TestPowerpointDocument(TestCase, TestMixin): """ Set up the patches and mocks need for all tests. """ - self.get_application() + self.setup_application() self.build_settings() self.mock_plugin = MagicMock() self.temp_folder = mkdtemp() diff --git a/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py b/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py index 0d4d2ab1e..c2bfcecbb 100644 --- a/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_pptviewcontroller.py @@ -59,7 +59,7 @@ class TestPptviewController(TestCase, TestMixin): """ Set up the patches and mocks need for all tests. """ - self.get_application() + self.setup_application() self.build_settings() self.mock_plugin = MagicMock() self.temp_folder = mkdtemp() diff --git a/tests/functional/openlp_plugins/remotes/test_remotetab.py b/tests/functional/openlp_plugins/remotes/test_remotetab.py index 61714e9c5..704c9022e 100644 --- a/tests/functional/openlp_plugins/remotes/test_remotetab.py +++ b/tests/functional/openlp_plugins/remotes/test_remotetab.py @@ -63,7 +63,7 @@ class TestRemoteTab(TestCase, TestMixin): """ Create the UI """ - self.get_application() + self.setup_application() self.build_settings() Settings().extend_default_settings(__default_settings__) self.parent = QtGui.QMainWindow() diff --git a/tests/functional/openlp_plugins/remotes/test_router.py b/tests/functional/openlp_plugins/remotes/test_router.py index c0190ecda..cf5a23850 100644 --- a/tests/functional/openlp_plugins/remotes/test_router.py +++ b/tests/functional/openlp_plugins/remotes/test_router.py @@ -61,7 +61,7 @@ class TestRouter(TestCase, TestMixin): """ Create the UI """ - self.get_application() + self.setup_application() self.build_settings() Settings().extend_default_settings(__default_settings__) self.router = HttpRouter() diff --git a/tests/functional/openlp_plugins/songs/test_mediaitem.py b/tests/functional/openlp_plugins/songs/test_mediaitem.py index a473f8569..2f844b891 100644 --- a/tests/functional/openlp_plugins/songs/test_mediaitem.py +++ b/tests/functional/openlp_plugins/songs/test_mediaitem.py @@ -29,7 +29,7 @@ class TestMediaItem(TestCase, TestMixin): self.media_item = SongMediaItem(None, MagicMock()) self.media_item.display_songbook = False self.media_item.display_copyright_symbol = False - self.get_application() + self.setup_application() self.build_settings() QtCore.QLocale.setDefault(QtCore.QLocale('en_GB')) diff --git a/tests/helpers/testmixin.py b/tests/helpers/testmixin.py index b4e8a5c59..f0fb4b691 100644 --- a/tests/helpers/testmixin.py +++ b/tests/helpers/testmixin.py @@ -37,8 +37,11 @@ from openlp.core.common import Settings class TestMixin(object): + """ + The :class:`TestMixin` class provides test with extra functionality + """ - def get_application(self): + def setup_application(self): """ Build or reuse the Application object """ diff --git a/tests/interfaces/openlp_core_common/test_historycombobox.py b/tests/interfaces/openlp_core_common/test_historycombobox.py index c0131e46c..2d5f28d5e 100644 --- a/tests/interfaces/openlp_core_common/test_historycombobox.py +++ b/tests/interfaces/openlp_core_common/test_historycombobox.py @@ -43,7 +43,7 @@ from tests.interfaces import MagicMock, patch class TestHistoryComboBox(TestCase, TestMixin): def setUp(self): Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.combo = HistoryComboBox(self.main_window) diff --git a/tests/interfaces/openlp_core_lib/test_pluginmanager.py b/tests/interfaces/openlp_core_lib/test_pluginmanager.py index ba81d708f..e67e9bb40 100644 --- a/tests/interfaces/openlp_core_lib/test_pluginmanager.py +++ b/tests/interfaces/openlp_core_lib/test_pluginmanager.py @@ -58,7 +58,7 @@ class TestPluginManager(TestCase, TestMixin): Settings().setValue('advanced/data path', self.temp_dir) Registry.create() Registry().register('service_list', MagicMock()) - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) diff --git a/tests/interfaces/openlp_core_lib/test_searchedit.py b/tests/interfaces/openlp_core_lib/test_searchedit.py index f2cf18988..e2ce68b0c 100644 --- a/tests/interfaces/openlp_core_lib/test_searchedit.py +++ b/tests/interfaces/openlp_core_lib/test_searchedit.py @@ -57,7 +57,7 @@ class TestSearchEdit(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 7d14c7d9c..611b3453b 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -46,7 +46,7 @@ class TestStartFileRenameForm(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.form = filerenameform.FileRenameForm() diff --git a/tests/interfaces/openlp_core_ui/test_listpreviewwidget.py b/tests/interfaces/openlp_core_ui/test_listpreviewwidget.py index aced3127f..24766f6ef 100644 --- a/tests/interfaces/openlp_core_ui/test_listpreviewwidget.py +++ b/tests/interfaces/openlp_core_ui/test_listpreviewwidget.py @@ -49,7 +49,7 @@ class TestListPreviewWidget(TestCase, TestMixin): Create the UI. """ Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() self.image = QtGui.QImage(1, 1, QtGui.QImage.Format_RGB32) self.image_manager = MagicMock() diff --git a/tests/interfaces/openlp_core_ui/test_mainwindow.py b/tests/interfaces/openlp_core_ui/test_mainwindow.py index b79036547..c775be747 100644 --- a/tests/interfaces/openlp_core_ui/test_mainwindow.py +++ b/tests/interfaces/openlp_core_ui/test_mainwindow.py @@ -46,7 +46,7 @@ class TestMainWindow(TestCase, TestMixin): """ Registry.create() self.registry = Registry() - self.get_application() + self.setup_application() # Mock cursor busy/normal methods. self.app.set_busy_cursor = MagicMock() self.app.set_normal_cursor = MagicMock() diff --git a/tests/interfaces/openlp_core_ui/test_servicemanager.py b/tests/interfaces/openlp_core_ui/test_servicemanager.py index 78df788ab..a08e4a1f1 100644 --- a/tests/interfaces/openlp_core_ui/test_servicemanager.py +++ b/tests/interfaces/openlp_core_ui/test_servicemanager.py @@ -46,7 +46,7 @@ class TestServiceManager(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() ScreenList.create(self.app.desktop()) Registry().register('application', MagicMock()) with patch('openlp.core.lib.PluginManager'): diff --git a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py index 86fc425c1..bd23e79e9 100644 --- a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py +++ b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py @@ -46,7 +46,7 @@ class TestStartNoteDialog(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.form = servicenoteform.ServiceNoteForm() diff --git a/tests/interfaces/openlp_core_ui/test_settings_form.py b/tests/interfaces/openlp_core_ui/test_settings_form.py index 012b78036..7c2181b41 100644 --- a/tests/interfaces/openlp_core_ui/test_settings_form.py +++ b/tests/interfaces/openlp_core_ui/test_settings_form.py @@ -59,7 +59,7 @@ class TestSettingsForm(TestCase, TestMixin): self.dummy2 = MagicMock() self.dummy3 = MagicMock() self.desktop = MagicMock() - self.get_application() + self.setup_application() self.desktop.primaryScreen.return_value = SCREEN['primary'] self.desktop.screenCount.return_value = SCREEN['number'] self.desktop.screenGeometry.return_value = SCREEN['size'] diff --git a/tests/interfaces/openlp_core_ui/test_shortcutlistform.py b/tests/interfaces/openlp_core_ui/test_shortcutlistform.py index 29c365194..58bd5c015 100644 --- a/tests/interfaces/openlp_core_ui/test_shortcutlistform.py +++ b/tests/interfaces/openlp_core_ui/test_shortcutlistform.py @@ -46,7 +46,7 @@ class TestShortcutform(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.form = ShortcutListForm() diff --git a/tests/interfaces/openlp_core_ui/test_starttimedialog.py b/tests/interfaces/openlp_core_ui/test_starttimedialog.py index c959bb817..b561a1722 100644 --- a/tests/interfaces/openlp_core_ui/test_starttimedialog.py +++ b/tests/interfaces/openlp_core_ui/test_starttimedialog.py @@ -46,7 +46,7 @@ class TestStartTimeDialog(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.form = starttimeform.StartTimeForm() diff --git a/tests/interfaces/openlp_core_ui/test_thememanager.py b/tests/interfaces/openlp_core_ui/test_thememanager.py index 2d0fe5fd7..792c9f9f8 100644 --- a/tests/interfaces/openlp_core_ui/test_thememanager.py +++ b/tests/interfaces/openlp_core_ui/test_thememanager.py @@ -46,7 +46,7 @@ class TestThemeManager(TestCase, TestMixin): Create the UI """ self.build_settings() - self.get_application() + self.setup_application() Registry.create() self.theme_manager = ThemeManager() diff --git a/tests/interfaces/openlp_core_utils/test_utils.py b/tests/interfaces/openlp_core_utils/test_utils.py index 3da1db2e2..4a5bfd56d 100644 --- a/tests/interfaces/openlp_core_utils/test_utils.py +++ b/tests/interfaces/openlp_core_utils/test_utils.py @@ -46,7 +46,7 @@ class TestUtils(TestCase, TestMixin): """ Some pre-test setup required. """ - self.get_application() + self.setup_application() def is_not_image_empty_test(self): """ diff --git a/tests/interfaces/openlp_plugins/custom/forms/test_customform.py b/tests/interfaces/openlp_plugins/custom/forms/test_customform.py index ca238b1a6..577048378 100644 --- a/tests/interfaces/openlp_plugins/custom/forms/test_customform.py +++ b/tests/interfaces/openlp_plugins/custom/forms/test_customform.py @@ -50,7 +50,7 @@ class TestEditCustomForm(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) media_item = MagicMock() diff --git a/tests/interfaces/openlp_plugins/custom/forms/test_customslideform.py b/tests/interfaces/openlp_plugins/custom/forms/test_customslideform.py index 261519362..e961eff03 100644 --- a/tests/interfaces/openlp_plugins/custom/forms/test_customslideform.py +++ b/tests/interfaces/openlp_plugins/custom/forms/test_customslideform.py @@ -48,7 +48,7 @@ class TestEditCustomSlideForm(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.form = EditCustomSlideForm() diff --git a/tests/interfaces/openlp_plugins/media/forms/test_mediaclipselectorform.py b/tests/interfaces/openlp_plugins/media/forms/test_mediaclipselectorform.py index 89810aa50..45e1dee41 100644 --- a/tests/interfaces/openlp_plugins/media/forms/test_mediaclipselectorform.py +++ b/tests/interfaces/openlp_plugins/media/forms/test_mediaclipselectorform.py @@ -54,7 +54,7 @@ class TestMediaClipSelectorForm(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) # Mock VLC so we don't actually use it diff --git a/tests/interfaces/openlp_plugins/songs/forms/test_authorsform.py b/tests/interfaces/openlp_plugins/songs/forms/test_authorsform.py index 2257bbc84..567a48928 100644 --- a/tests/interfaces/openlp_plugins/songs/forms/test_authorsform.py +++ b/tests/interfaces/openlp_plugins/songs/forms/test_authorsform.py @@ -48,7 +48,7 @@ class TestAuthorsForm(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.form = AuthorsForm() diff --git a/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py b/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py index 2f57a3002..e84079f98 100644 --- a/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py +++ b/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py @@ -49,7 +49,7 @@ class TestEditSongForm(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) Registry().register('theme_manager', MagicMock()) diff --git a/tests/interfaces/openlp_plugins/songs/forms/test_editverseform.py b/tests/interfaces/openlp_plugins/songs/forms/test_editverseform.py index 178b1cd7c..6628d6cb3 100644 --- a/tests/interfaces/openlp_plugins/songs/forms/test_editverseform.py +++ b/tests/interfaces/openlp_plugins/songs/forms/test_editverseform.py @@ -48,7 +48,7 @@ class TestEditVerseForm(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.form = EditVerseForm() diff --git a/tests/interfaces/openlp_plugins/songs/forms/test_topicsform.py b/tests/interfaces/openlp_plugins/songs/forms/test_topicsform.py index c30c7838c..448f9b753 100644 --- a/tests/interfaces/openlp_plugins/songs/forms/test_topicsform.py +++ b/tests/interfaces/openlp_plugins/songs/forms/test_topicsform.py @@ -48,7 +48,7 @@ class TestTopicsForm(TestCase, TestMixin): Create the UI """ Registry.create() - self.get_application() + self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.form = TopicsForm()