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

Proposed by Raoul Snyman on 2017-02-03
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 2017-02-03 Approve on 2017-02-03
Review via email: mp+316303@code.launchpad.net
To post a comment you must log in.
Tomas Groth (tomasgroth) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/plugins/songusage/forms/songusagedetailform.py'
2--- openlp/plugins/songusage/forms/songusagedetailform.py 2016-12-31 11:05:48 +0000
3+++ openlp/plugins/songusage/forms/songusagedetailform.py 2017-02-03 04:49:43 +0000
4@@ -22,6 +22,7 @@
5
6 import logging
7 import os
8+from datetime import datetime
9
10 from PyQt5 import QtCore, QtWidgets
11 from sqlalchemy.sql import and_
12@@ -52,8 +53,16 @@
13 """
14 We need to set up the screen
15 """
16- self.from_date_calendar.setSelectedDate(Settings().value(self.plugin.settings_section + '/from date'))
17- self.to_date_calendar.setSelectedDate(Settings().value(self.plugin.settings_section + '/to date'))
18+ from_date = Settings().value(self.plugin.settings_section + '/from date')
19+ if from_date:
20+ self.from_date_calendar.setSelectedDate(from_date)
21+ else:
22+ self.from_date_calendar.setSelectedDate(datetime.today().replace(day=1))
23+ to_date = Settings().value(self.plugin.settings_section + '/to date')
24+ if to_date:
25+ self.to_date_calendar.setSelectedDate(to_date)
26+ else:
27+ self.to_date_calendar.setSelectedDate(datetime.today())
28 self.file_line_edit.setText(Settings().value(self.plugin.settings_section + '/last directory export'))
29
30 def define_output_location(self):
31
32=== modified file 'openlp/plugins/songusage/songusageplugin.py'
33--- openlp/plugins/songusage/songusageplugin.py 2016-12-31 11:05:48 +0000
34+++ openlp/plugins/songusage/songusageplugin.py 2017-02-03 04:49:43 +0000
35@@ -44,9 +44,9 @@
36 __default_settings__ = {
37 'songusage/db type': 'sqlite',
38 'songusage/db username': '',
39- 'songuasge/db password': '',
40- 'songuasge/db hostname': '',
41- 'songuasge/db database': '',
42+ 'songusage/db password': '',
43+ 'songusage/db hostname': '',
44+ 'songusage/db database': '',
45 'songusage/active': False,
46 'songusage/to date': QtCore.QDate(YEAR, 8, 31),
47 'songusage/from date': QtCore.QDate(YEAR - 1, 9, 1),
48
49=== modified file 'tests/functional/openlp_plugins/songusage/test_songusage.py'
50--- tests/functional/openlp_plugins/songusage/test_songusage.py 2016-12-31 11:05:48 +0000
51+++ tests/functional/openlp_plugins/songusage/test_songusage.py 2017-02-03 04:49:43 +0000
52@@ -28,7 +28,7 @@
53 from openlp.core import Registry
54 from openlp.plugins.songusage.lib import upgrade
55 from openlp.plugins.songusage.lib.db import init_schema
56-from openlp.plugins.songusage.songusageplugin import SongUsagePlugin
57+from openlp.plugins.songusage.songusageplugin import SongUsagePlugin, __default_settings__
58
59
60 class TestSongUsage(TestCase):
61@@ -81,3 +81,27 @@
62
63 # THEN: It should return True
64 self.assertTrue(ret)
65+
66+ def test_default_settings(self):
67+ """
68+ Test that all the default settings are correct
69+ """
70+ # GIVEN: A list of default settings
71+ expected_defaults = sorted([
72+ 'songusage/db type',
73+ 'songusage/db username',
74+ 'songusage/db password',
75+ 'songusage/db hostname',
76+ 'songusage/db database',
77+ 'songusage/active',
78+ 'songusage/to date',
79+ 'songusage/from date',
80+ 'songusage/last directory',
81+ 'songusage/last directory export',
82+ 'songusage/status'
83+ ])
84+
85+ # WHEN: The plugin is initialised
86+ # THEN: The defaults should be correct
87+ for e_key, a_key in zip(expected_defaults, sorted(__default_settings__.keys())):
88+ assert e_key == a_key, '{} != {}'.format(e_key, a_key)
89
90=== added directory 'tests/interfaces/openlp_plugins/songusage'
91=== added file 'tests/interfaces/openlp_plugins/songusage/test_songusagedetailform.py'
92--- tests/interfaces/openlp_plugins/songusage/test_songusagedetailform.py 1970-01-01 00:00:00 +0000
93+++ tests/interfaces/openlp_plugins/songusage/test_songusagedetailform.py 2017-02-03 04:49:43 +0000
94@@ -0,0 +1,99 @@
95+# -*- coding: utf-8 -*-
96+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
97+
98+###############################################################################
99+# OpenLP - Open Source Lyrics Projection #
100+# --------------------------------------------------------------------------- #
101+# Copyright (c) 2008-2017 OpenLP Developers #
102+# --------------------------------------------------------------------------- #
103+# This program is free software; you can redistribute it and/or modify it #
104+# under the terms of the GNU General Public License as published by the Free #
105+# Software Foundation; version 2 of the License. #
106+# #
107+# This program is distributed in the hope that it will be useful, but WITHOUT #
108+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
109+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
110+# more details. #
111+# #
112+# You should have received a copy of the GNU General Public License along #
113+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
114+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
115+###############################################################################
116+"""
117+Package to test the openlp.plugins.songusage.forms.songusagedetailform package.
118+"""
119+from unittest import TestCase
120+from unittest.mock import MagicMock, patch
121+
122+from PyQt5 import QtCore, QtWidgets
123+
124+from openlp.core.common import Registry
125+from openlp.plugins.songusage.forms.songusagedetailform import SongUsageDetailForm
126+
127+from tests.helpers.testmixin import TestMixin
128+
129+
130+class TestSongUsageDetailForm(TestCase, TestMixin):
131+ """
132+ Test the SongUsageDetailForm class
133+ """
134+
135+ def setUp(self):
136+ """
137+ Create the UI
138+ """
139+ Registry.create()
140+ self.setup_application()
141+ self.main_window = QtWidgets.QMainWindow()
142+ self.mocked_plugin = MagicMock()
143+ Registry().register('main_window', self.main_window)
144+ self.form = SongUsageDetailForm(self.mocked_plugin, self.main_window)
145+
146+ def tearDown(self):
147+ """
148+ Delete all the C++ objects at the end so that we don't have a segfault
149+ """
150+ del self.form
151+ del self.main_window
152+
153+ @patch('openlp.plugins.songusage.forms.songusagedetailform.Settings')
154+ def test_initalise_without_settings(self, MockedSettings):
155+ """
156+ Test the initialise() method when there are no settings
157+ """
158+ # GIVEN: A song usage detail form and a mocked settings object
159+ mocked_settings = MagicMock()
160+ mocked_settings.value.side_effect = ['', None, '']
161+ MockedSettings.return_value = mocked_settings
162+
163+ # WHEN: initialise() is called
164+ self.form.initialise()
165+
166+ # THEN: The dates on the calendar should be this month
167+ today = QtCore.QDate.currentDate()
168+ month_start = QtCore.QDate.currentDate().addDays(1 - today.day())
169+ assert self.form.from_date_calendar.selectedDate() == month_start, \
170+ self.form.from_date_calendar.selectedDate()
171+ assert self.form.to_date_calendar.selectedDate() == today, \
172+ self.form.to_date_calendar.selectedDate()
173+
174+ @patch('openlp.plugins.songusage.forms.songusagedetailform.Settings')
175+ def test_initalise_with_settings(self, MockedSettings):
176+ """
177+ Test the initialise() method when there are existing settings
178+ """
179+ # GIVEN: A song usage detail form and a mocked settings object
180+ to_date = QtCore.QDate.currentDate().addDays(-1)
181+ from_date = QtCore.QDate.currentDate().addDays(2 - to_date.day())
182+ mocked_settings = MagicMock()
183+ mocked_settings.value.side_effect = [from_date, to_date, '']
184+ MockedSettings.return_value = mocked_settings
185+
186+ # WHEN: initialise() is called
187+ self.form.initialise()
188+
189+ # THEN: The dates on the calendar should be this month
190+ assert self.form.from_date_calendar.selectedDate() == from_date, \
191+ self.form.from_date_calendar.selectedDate()
192+ assert self.form.to_date_calendar.selectedDate() == to_date, \
193+ self.form.to_date_calendar.selectedDate()

Subscribers

People subscribed via source and target branches

to all changes: