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

Proposed by Raoul Snyman
Status: Merged
Merged at revision: 2670
Proposed branch: lp:~raoul-snyman/openlp/fix-songusage-2.4
Merge into: lp:openlp/2.4
Diff against target: 193 lines (+138/-6)
4 files modified
openlp/plugins/songusage/forms/songusagedetailform.py (+11/-2)
openlp/plugins/songusage/songusageplugin.py (+3/-3)
tests/functional/openlp_plugins/songusage/test_songusage.py (+25/-1)
tests/interfaces/openlp_plugins/songusage/test_songusagedetailform.py (+99/-0)
To merge this branch: bzr merge lp:~raoul-snyman/openlp/fix-songusage-2.4
Reviewer Review Type Date Requested Status
Tomas Groth Approve
Review via email: mp+316303@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tomas Groth (tomasgroth) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
2222
23import logging23import logging
24import os24import os
25from datetime import datetime
2526
26from PyQt5 import QtCore, QtWidgets27from PyQt5 import QtCore, QtWidgets
27from sqlalchemy.sql import and_28from sqlalchemy.sql import and_
@@ -52,8 +53,16 @@
52 """53 """
53 We need to set up the screen54 We need to set up the screen
54 """55 """
55 self.from_date_calendar.setSelectedDate(Settings().value(self.plugin.settings_section + '/from date'))56 from_date = Settings().value(self.plugin.settings_section + '/from date')
56 self.to_date_calendar.setSelectedDate(Settings().value(self.plugin.settings_section + '/to date'))57 if from_date:
58 self.from_date_calendar.setSelectedDate(from_date)
59 else:
60 self.from_date_calendar.setSelectedDate(datetime.today().replace(day=1))
61 to_date = Settings().value(self.plugin.settings_section + '/to date')
62 if to_date:
63 self.to_date_calendar.setSelectedDate(to_date)
64 else:
65 self.to_date_calendar.setSelectedDate(datetime.today())
57 self.file_line_edit.setText(Settings().value(self.plugin.settings_section + '/last directory export'))66 self.file_line_edit.setText(Settings().value(self.plugin.settings_section + '/last directory export'))
5867
59 def define_output_location(self):68 def define_output_location(self):
6069
=== 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 @@
44__default_settings__ = {44__default_settings__ = {
45 'songusage/db type': 'sqlite',45 'songusage/db type': 'sqlite',
46 'songusage/db username': '',46 'songusage/db username': '',
47 'songuasge/db password': '',47 'songusage/db password': '',
48 'songuasge/db hostname': '',48 'songusage/db hostname': '',
49 'songuasge/db database': '',49 'songusage/db database': '',
50 'songusage/active': False,50 'songusage/active': False,
51 'songusage/to date': QtCore.QDate(YEAR, 8, 31),51 'songusage/to date': QtCore.QDate(YEAR, 8, 31),
52 'songusage/from date': QtCore.QDate(YEAR - 1, 9, 1),52 'songusage/from date': QtCore.QDate(YEAR - 1, 9, 1),
5353
=== 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 @@
28from openlp.core import Registry28from openlp.core import Registry
29from openlp.plugins.songusage.lib import upgrade29from openlp.plugins.songusage.lib import upgrade
30from openlp.plugins.songusage.lib.db import init_schema30from openlp.plugins.songusage.lib.db import init_schema
31from openlp.plugins.songusage.songusageplugin import SongUsagePlugin31from openlp.plugins.songusage.songusageplugin import SongUsagePlugin, __default_settings__
3232
3333
34class TestSongUsage(TestCase):34class TestSongUsage(TestCase):
@@ -81,3 +81,27 @@
8181
82 # THEN: It should return True82 # THEN: It should return True
83 self.assertTrue(ret)83 self.assertTrue(ret)
84
85 def test_default_settings(self):
86 """
87 Test that all the default settings are correct
88 """
89 # GIVEN: A list of default settings
90 expected_defaults = sorted([
91 'songusage/db type',
92 'songusage/db username',
93 'songusage/db password',
94 'songusage/db hostname',
95 'songusage/db database',
96 'songusage/active',
97 'songusage/to date',
98 'songusage/from date',
99 'songusage/last directory',
100 'songusage/last directory export',
101 'songusage/status'
102 ])
103
104 # WHEN: The plugin is initialised
105 # THEN: The defaults should be correct
106 for e_key, a_key in zip(expected_defaults, sorted(__default_settings__.keys())):
107 assert e_key == a_key, '{} != {}'.format(e_key, a_key)
84108
=== 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 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2017 OpenLP Developers #
8# --------------------------------------------------------------------------- #
9# This program is free software; you can redistribute it and/or modify it #
10# under the terms of the GNU General Public License as published by the Free #
11# Software Foundation; version 2 of the License. #
12# #
13# This program is distributed in the hope that it will be useful, but WITHOUT #
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
16# more details. #
17# #
18# You should have received a copy of the GNU General Public License along #
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################
22"""
23Package to test the openlp.plugins.songusage.forms.songusagedetailform package.
24"""
25from unittest import TestCase
26from unittest.mock import MagicMock, patch
27
28from PyQt5 import QtCore, QtWidgets
29
30from openlp.core.common import Registry
31from openlp.plugins.songusage.forms.songusagedetailform import SongUsageDetailForm
32
33from tests.helpers.testmixin import TestMixin
34
35
36class TestSongUsageDetailForm(TestCase, TestMixin):
37 """
38 Test the SongUsageDetailForm class
39 """
40
41 def setUp(self):
42 """
43 Create the UI
44 """
45 Registry.create()
46 self.setup_application()
47 self.main_window = QtWidgets.QMainWindow()
48 self.mocked_plugin = MagicMock()
49 Registry().register('main_window', self.main_window)
50 self.form = SongUsageDetailForm(self.mocked_plugin, self.main_window)
51
52 def tearDown(self):
53 """
54 Delete all the C++ objects at the end so that we don't have a segfault
55 """
56 del self.form
57 del self.main_window
58
59 @patch('openlp.plugins.songusage.forms.songusagedetailform.Settings')
60 def test_initalise_without_settings(self, MockedSettings):
61 """
62 Test the initialise() method when there are no settings
63 """
64 # GIVEN: A song usage detail form and a mocked settings object
65 mocked_settings = MagicMock()
66 mocked_settings.value.side_effect = ['', None, '']
67 MockedSettings.return_value = mocked_settings
68
69 # WHEN: initialise() is called
70 self.form.initialise()
71
72 # THEN: The dates on the calendar should be this month
73 today = QtCore.QDate.currentDate()
74 month_start = QtCore.QDate.currentDate().addDays(1 - today.day())
75 assert self.form.from_date_calendar.selectedDate() == month_start, \
76 self.form.from_date_calendar.selectedDate()
77 assert self.form.to_date_calendar.selectedDate() == today, \
78 self.form.to_date_calendar.selectedDate()
79
80 @patch('openlp.plugins.songusage.forms.songusagedetailform.Settings')
81 def test_initalise_with_settings(self, MockedSettings):
82 """
83 Test the initialise() method when there are existing settings
84 """
85 # GIVEN: A song usage detail form and a mocked settings object
86 to_date = QtCore.QDate.currentDate().addDays(-1)
87 from_date = QtCore.QDate.currentDate().addDays(2 - to_date.day())
88 mocked_settings = MagicMock()
89 mocked_settings.value.side_effect = [from_date, to_date, '']
90 MockedSettings.return_value = mocked_settings
91
92 # WHEN: initialise() is called
93 self.form.initialise()
94
95 # THEN: The dates on the calendar should be this month
96 assert self.form.from_date_calendar.selectedDate() == from_date, \
97 self.form.from_date_calendar.selectedDate()
98 assert self.form.to_date_calendar.selectedDate() == to_date, \
99 self.form.to_date_calendar.selectedDate()

Subscribers

People subscribed via source and target branches

to all changes: