← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~raoul-snyman/openlp/fix-songusage-2.4 into lp:openlp/2.4

 

Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/fix-songusage-2.4 into lp:openlp/2.4.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #1532193 in OpenLP: "Typos in songusageplugin.py"
  https://bugs.launchpad.net/openlp/+bug/1532193
  Bug #1661416 in OpenLP: "Initial "extract song usage data" produces a traceback"
  https://bugs.launchpad.net/openlp/+bug/1661416

For more details, see:
https://code.launchpad.net/~raoul-snyman/openlp/fix-songusage-2.4/+merge/316303

Fix some bugs in the songsusage plugin:

 * Bug 1532193
 * Bug 1661416

Add this to your merge proposal:
--------------------------------
lp:~raoul-snyman/openlp/fix-songusage-2.4 (revision 2671)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1899/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1810/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1749/
[SUCCESS] https://ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/1485/
[SUCCESS] https://ci.openlp.io/job/Branch-04b-Windows_Interface_Tests/1075/
[SUCCESS] https://ci.openlp.io/job/Branch-05a-Code_Analysis/1143/
[SUCCESS] https://ci.openlp.io/job/Branch-05b-Test_Coverage/1011/
-- 
Your team OpenLP Core is requested to review the proposed merge of lp:~raoul-snyman/openlp/fix-songusage-2.4 into lp:openlp/2.4.
=== modified file 'openlp/plugins/songusage/forms/songusagedetailform.py'
--- openlp/plugins/songusage/forms/songusagedetailform.py	2016-12-31 11:05:48 +0000
+++ openlp/plugins/songusage/forms/songusagedetailform.py	2017-02-03 04:49:43 +0000
@@ -22,6 +22,7 @@
 
 import logging
 import os
+from datetime import datetime
 
 from PyQt5 import QtCore, QtWidgets
 from sqlalchemy.sql import and_
@@ -52,8 +53,16 @@
         """
         We need to set up the screen
         """
-        self.from_date_calendar.setSelectedDate(Settings().value(self.plugin.settings_section + '/from date'))
-        self.to_date_calendar.setSelectedDate(Settings().value(self.plugin.settings_section + '/to date'))
+        from_date = Settings().value(self.plugin.settings_section + '/from date')
+        if from_date:
+            self.from_date_calendar.setSelectedDate(from_date)
+        else:
+            self.from_date_calendar.setSelectedDate(datetime.today().replace(day=1))
+        to_date = Settings().value(self.plugin.settings_section + '/to date')
+        if to_date:
+            self.to_date_calendar.setSelectedDate(to_date)
+        else:
+            self.to_date_calendar.setSelectedDate(datetime.today())
         self.file_line_edit.setText(Settings().value(self.plugin.settings_section + '/last directory export'))
 
     def define_output_location(self):

=== modified file 'openlp/plugins/songusage/songusageplugin.py'
--- openlp/plugins/songusage/songusageplugin.py	2016-12-31 11:05:48 +0000
+++ openlp/plugins/songusage/songusageplugin.py	2017-02-03 04:49:43 +0000
@@ -44,9 +44,9 @@
 __default_settings__ = {
     'songusage/db type': 'sqlite',
     'songusage/db username': '',
-    'songuasge/db password': '',
-    'songuasge/db hostname': '',
-    'songuasge/db database': '',
+    'songusage/db password': '',
+    'songusage/db hostname': '',
+    'songusage/db database': '',
     'songusage/active': False,
     'songusage/to date': QtCore.QDate(YEAR, 8, 31),
     'songusage/from date': QtCore.QDate(YEAR - 1, 9, 1),

=== modified file 'tests/functional/openlp_plugins/songusage/test_songusage.py'
--- tests/functional/openlp_plugins/songusage/test_songusage.py	2016-12-31 11:05:48 +0000
+++ tests/functional/openlp_plugins/songusage/test_songusage.py	2017-02-03 04:49:43 +0000
@@ -28,7 +28,7 @@
 from openlp.core import Registry
 from openlp.plugins.songusage.lib import upgrade
 from openlp.plugins.songusage.lib.db import init_schema
-from openlp.plugins.songusage.songusageplugin import SongUsagePlugin
+from openlp.plugins.songusage.songusageplugin import SongUsagePlugin, __default_settings__
 
 
 class TestSongUsage(TestCase):
@@ -81,3 +81,27 @@
 
         # THEN: It should return True
         self.assertTrue(ret)
+
+    def test_default_settings(self):
+        """
+        Test that all the default settings are correct
+        """
+        # GIVEN: A list of default settings
+        expected_defaults = sorted([
+            'songusage/db type',
+            'songusage/db username',
+            'songusage/db password',
+            'songusage/db hostname',
+            'songusage/db database',
+            'songusage/active',
+            'songusage/to date',
+            'songusage/from date',
+            'songusage/last directory',
+            'songusage/last directory export',
+            'songusage/status'
+        ])
+
+        # WHEN: The plugin is initialised
+        # THEN: The defaults should be correct
+        for e_key, a_key in zip(expected_defaults, sorted(__default_settings__.keys())):
+            assert e_key == a_key, '{} != {}'.format(e_key, a_key)

=== added directory 'tests/interfaces/openlp_plugins/songusage'
=== added file 'tests/interfaces/openlp_plugins/songusage/test_songusagedetailform.py'
--- tests/interfaces/openlp_plugins/songusage/test_songusagedetailform.py	1970-01-01 00:00:00 +0000
+++ tests/interfaces/openlp_plugins/songusage/test_songusagedetailform.py	2017-02-03 04:49:43 +0000
@@ -0,0 +1,99 @@
+# -*- 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                          #
+###############################################################################
+"""
+Package to test the openlp.plugins.songusage.forms.songusagedetailform package.
+"""
+from unittest import TestCase
+from unittest.mock import MagicMock, patch
+
+from PyQt5 import QtCore, QtWidgets
+
+from openlp.core.common import Registry
+from openlp.plugins.songusage.forms.songusagedetailform import SongUsageDetailForm
+
+from tests.helpers.testmixin import TestMixin
+
+
+class TestSongUsageDetailForm(TestCase, TestMixin):
+    """
+    Test the SongUsageDetailForm class
+    """
+
+    def setUp(self):
+        """
+        Create the UI
+        """
+        Registry.create()
+        self.setup_application()
+        self.main_window = QtWidgets.QMainWindow()
+        self.mocked_plugin = MagicMock()
+        Registry().register('main_window', self.main_window)
+        self.form = SongUsageDetailForm(self.mocked_plugin, self.main_window)
+
+    def tearDown(self):
+        """
+        Delete all the C++ objects at the end so that we don't have a segfault
+        """
+        del self.form
+        del self.main_window
+
+    @patch('openlp.plugins.songusage.forms.songusagedetailform.Settings')
+    def test_initalise_without_settings(self, MockedSettings):
+        """
+        Test the initialise() method when there are no settings
+        """
+        # GIVEN: A song usage detail form and a mocked settings object
+        mocked_settings = MagicMock()
+        mocked_settings.value.side_effect = ['', None, '']
+        MockedSettings.return_value = mocked_settings
+
+        # WHEN: initialise() is called
+        self.form.initialise()
+
+        # THEN: The dates on the calendar should be this month
+        today = QtCore.QDate.currentDate()
+        month_start = QtCore.QDate.currentDate().addDays(1 - today.day())
+        assert self.form.from_date_calendar.selectedDate() == month_start, \
+            self.form.from_date_calendar.selectedDate()
+        assert self.form.to_date_calendar.selectedDate() == today, \
+            self.form.to_date_calendar.selectedDate()
+
+    @patch('openlp.plugins.songusage.forms.songusagedetailform.Settings')
+    def test_initalise_with_settings(self, MockedSettings):
+        """
+        Test the initialise() method when there are existing settings
+        """
+        # GIVEN: A song usage detail form and a mocked settings object
+        to_date = QtCore.QDate.currentDate().addDays(-1)
+        from_date = QtCore.QDate.currentDate().addDays(2 - to_date.day())
+        mocked_settings = MagicMock()
+        mocked_settings.value.side_effect = [from_date, to_date, '']
+        MockedSettings.return_value = mocked_settings
+
+        # WHEN: initialise() is called
+        self.form.initialise()
+
+        # THEN: The dates on the calendar should be this month
+        assert self.form.from_date_calendar.selectedDate() == from_date, \
+            self.form.from_date_calendar.selectedDate()
+        assert self.form.to_date_calendar.selectedDate() == to_date, \
+            self.form.to_date_calendar.selectedDate()


Follow ups