From d758ed257cf705587d3dde468e7482065ab93bb5 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 13 Jan 2018 16:24:26 -0700 Subject: [PATCH 1/2] Fix progress not showing in the FTW --- openlp/core/ui/firsttimeform.py | 4 +- openlp/core/ui/firsttimewizard.py | 2 +- .../openlp_core/api/endpoint/test_remote.py | 44 +++++++++++++ .../openlp_core/lib/test_pluginmanager.py | 28 +++++++- tests/interfaces/openlp_core/ui/test_init.py | 64 +++++++++++++++++++ 5 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 tests/functional/openlp_core/api/endpoint/test_remote.py create mode 100644 tests/interfaces/openlp_core/ui/test_init.py diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index 631ae4dfc..2b9e70abf 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -400,9 +400,9 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): if item: item.setIcon(build_icon(Path(gettempdir(), 'openlp', screenshot))) - def _download_progress(self, count, block_size): + def update_progress(self, count, block_size): """ - Calculate and display the download progress. + Calculate and display the download progress. This method is called by download_file(). """ increment = (count * block_size) - self.previous_size self._increment_progress_bar(None, increment) diff --git a/openlp/core/ui/firsttimewizard.py b/openlp/core/ui/firsttimewizard.py index 9f9261015..faa481455 100644 --- a/openlp/core/ui/firsttimewizard.py +++ b/openlp/core/ui/firsttimewizard.py @@ -63,7 +63,7 @@ class UiFirstTimeWizard(object): first_time_wizard.setOptions(QtWidgets.QWizard.IndependentPages | QtWidgets.QWizard.NoBackButtonOnStartPage | QtWidgets.QWizard.NoBackButtonOnLastPage | QtWidgets.QWizard.HaveCustomButton1 | QtWidgets.QWizard.HaveCustomButton2) - if is_macosx(): + if is_macosx(): # pragma: nocover first_time_wizard.setPixmap(QtWidgets.QWizard.BackgroundPixmap, QtGui.QPixmap(':/wizards/openlp-osx-wizard.png')) first_time_wizard.resize(634, 386) diff --git a/tests/functional/openlp_core/api/endpoint/test_remote.py b/tests/functional/openlp_core/api/endpoint/test_remote.py new file mode 100644 index 000000000..c330f64d6 --- /dev/null +++ b/tests/functional/openlp_core/api/endpoint/test_remote.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2018 OpenLP Developers # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +Functional tests to test the remote index +""" +from unittest.mock import MagicMock, patch + +from openlp.core.api.endpoint.remote import index +from openlp.core.api.endpoint.core import TRANSLATED_STRINGS + + +@patch('openlp.core.api.endpoint.remote.remote_endpoint') +def test_index(mocked_endpoint): + """ + Test the index method of the remote + """ + # GIVEN: A mocked Endpoint + mocked_endpoint.render_template.return_value = 'test template' + + # WHEN: index is called + result = index(MagicMock(), 'index') + + # THEN: The result should be "test template" and the right methods should have been called + mocked_endpoint.render_template.assert_called_once_with('index.mako', **TRANSLATED_STRINGS) + assert result == 'test template' diff --git a/tests/functional/openlp_core/lib/test_pluginmanager.py b/tests/functional/openlp_core/lib/test_pluginmanager.py index 553221ff2..a2e981276 100644 --- a/tests/functional/openlp_core/lib/test_pluginmanager.py +++ b/tests/functional/openlp_core/lib/test_pluginmanager.py @@ -23,7 +23,7 @@ Package to test the openlp.core.lib.pluginmanager package. """ from unittest import TestCase -from unittest.mock import MagicMock +from unittest.mock import MagicMock, patch from openlp.core.common.registry import Registry from openlp.core.common.settings import Settings @@ -50,6 +50,32 @@ class TestPluginManager(TestCase): Registry().register('main_window', self.mocked_main_window) Registry().register('settings_form', self.mocked_settings_form) + def test_bootstrap_initialise(self): + """ + Test the PluginManager.bootstrap_initialise() method + """ + # GIVEN: A plugin manager with some mocked out methods + manager = PluginManager() + + with patch.object(manager, 'find_plugins') as mocked_find_plugins, \ + patch.object(manager, 'hook_settings_tabs') as mocked_hook_settings_tabs, \ + patch.object(manager, 'hook_media_manager') as mocked_hook_media_manager, \ + patch.object(manager, 'hook_import_menu') as mocked_hook_import_menu, \ + patch.object(manager, 'hook_export_menu') as mocked_hook_export_menu, \ + patch.object(manager, 'hook_tools_menu') as mocked_hook_tools_menu, \ + patch.object(manager, 'initialise_plugins') as mocked_initialise_plugins: + # WHEN: bootstrap_initialise() is called + manager.bootstrap_initialise() + + # THEN: The hook methods should have been called + mocked_find_plugins.assert_called_with() + mocked_hook_settings_tabs.assert_called_with() + mocked_hook_media_manager.assert_called_with() + mocked_hook_import_menu.assert_called_with() + mocked_hook_export_menu.assert_called_with() + mocked_hook_tools_menu.assert_called_with() + mocked_initialise_plugins.assert_called_with() + def test_hook_media_manager_with_disabled_plugin(self): """ Test running the hook_media_manager() method with a disabled plugin diff --git a/tests/interfaces/openlp_core/ui/test_init.py b/tests/interfaces/openlp_core/ui/test_init.py new file mode 100644 index 000000000..3ef405751 --- /dev/null +++ b/tests/interfaces/openlp_core/ui/test_init.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2017 OpenLP Developers # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +Test the openlp.core.ui package. +""" +from unittest.mock import MagicMock, patch + +from openlp.core.ui import SingleColumnTableWidget + + +def test_single_col_widget_create(): + """ + Test creating the SingleColumnTableWidget object + """ + # GIVEN: the SingleColumnTableWidget class + # WHEN: An object is created + widget = SingleColumnTableWidget(None) + + # THEN: The object should have 1 column and no visible header + assert widget.columnCount() == 1, 'There should be only 1 column' + assert widget.horizontalHeader().isVisible() is False, 'The horizontal header should not be visible' + + +@patch('openlp.core.ui.QtWidgets.QTableWidget') +def test_single_col_widget_resize_event(MockQTableWidget): + """ + Test that the resizeEvent method does the right thing + """ + # GIVEN: An instance of a SingleColumnTableWidget and a mocked event + widget = SingleColumnTableWidget(None) + mocked_event = MagicMock() + mocked_event.size.return_value.width.return_value = 10 + + # WHEN: resizeEvent() is called + with patch.object(widget, 'columnCount') as mocked_column_count, \ + patch.object(widget, 'setColumnWidth') as mocked_set_column_width, \ + patch.object(widget, 'resizeRowsToContents') as mocked_resize_rows_to_contents: + mocked_column_count.return_value = 1 + widget.resizeEvent(mocked_event) + + # THEN: The correct calls should have been made + MockQTableWidget.resizeEvent.assert_called_once_with(widget, mocked_event) + mocked_column_count.assert_called_once_with() + mocked_set_column_width.assert_called_once_with(0, 10) + mocked_resize_rows_to_contents.assert_called_once_with() From 53ac8468d420ba8cff9d37b872f3642650b1d679 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 24 Jan 2018 13:27:22 -0700 Subject: [PATCH 2/2] Fix copyright --- tests/interfaces/openlp_core/ui/test_init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/interfaces/openlp_core/ui/test_init.py b/tests/interfaces/openlp_core/ui/test_init.py index 3ef405751..8bfc08b9e 100644 --- a/tests/interfaces/openlp_core/ui/test_init.py +++ b/tests/interfaces/openlp_core/ui/test_init.py @@ -4,7 +4,7 @@ ############################################################################### # OpenLP - Open Source Lyrics Projection # # --------------------------------------------------------------------------- # -# Copyright (c) 2008-2017 OpenLP Developers # +# Copyright (c) 2008-2018 OpenLP Developers # # --------------------------------------------------------------------------- # # 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 #