1
# -*- coding: utf-8 -*-
2
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
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. #
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 #
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
###############################################################################
23
Package to test the openlp.plugins.songusage.forms.songusagedetailform package.
25
from unittest import TestCase
26
from unittest.mock import MagicMock, patch
28
from PyQt5 import QtCore, QtWidgets
30
from openlp.core.common import Registry
31
from openlp.plugins.songusage.forms.songusagedetailform import SongUsageDetailForm
33
from tests.helpers.testmixin import TestMixin
36
class TestSongUsageDetailForm(TestCase, TestMixin):
38
Test the SongUsageDetailForm class
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)
54
Delete all the C++ objects at the end so that we don't have a segfault
59
@patch('openlp.plugins.songusage.forms.songusagedetailform.Settings')
60
def test_initalise_without_settings(self, MockedSettings):
62
Test the initialise() method when there are no settings
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
69
# WHEN: initialise() is called
70
self.form.initialise()
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()
80
@patch('openlp.plugins.songusage.forms.songusagedetailform.Settings')
81
def test_initalise_with_settings(self, MockedSettings):
83
Test the initialise() method when there are existing settings
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
92
# WHEN: initialise() is called
93
self.form.initialise()
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()