~openlp-core/openlp/2.4

« back to all changes in this revision

Viewing changes to tests/interfaces/openlp_plugins/songusage/test_songusagedetailform.py

  • Committer: Raoul Snyman
  • Author(s): raoul at snyman
  • Date: 2017-02-03 16:57:54 UTC
  • mfrom: (2668.2.3 fix-songusage)
  • Revision ID: raoul@snyman.info-20170203165754-0nfiwphxn88zs43v
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/jo...

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
"""
 
23
Package to test the openlp.plugins.songusage.forms.songusagedetailform package.
 
24
"""
 
25
from unittest import TestCase
 
26
from unittest.mock import MagicMock, patch
 
27
 
 
28
from PyQt5 import QtCore, QtWidgets
 
29
 
 
30
from openlp.core.common import Registry
 
31
from openlp.plugins.songusage.forms.songusagedetailform import SongUsageDetailForm
 
32
 
 
33
from tests.helpers.testmixin import TestMixin
 
34
 
 
35
 
 
36
class 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()