openlp/tests/functional/openlp_plugins/songusage/test_songusage.py

100 lines
4.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2019-02-14 15:09:09 +00:00
# Copyright (c) 2008-2019 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 #
###############################################################################
"""
This module contains tests for the Songusage plugin.
"""
from unittest import TestCase
from unittest.mock import MagicMock, patch
2017-10-10 07:08:44 +00:00
from openlp.core.common.registry 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
class TestSongUsage(TestCase):
def setUp(self):
Registry.create()
2016-05-31 21:40:13 +00:00
def test_about_text(self):
"""
Test the about text of the song usage plugin
"""
# GIVEN: The SongUsagePlugin
# WHEN: Retrieving the about text
# THEN: about() should return a string object
2017-12-22 16:53:40 +00:00
assert isinstance(SongUsagePlugin.about(), str)
# THEN: about() should return a non-empty string
2017-12-23 09:22:53 +00:00
assert len(SongUsagePlugin.about()) is not 0
assert len(SongUsagePlugin.about()) is not 0
@patch('openlp.plugins.songusage.songusageplugin.Manager')
2016-05-31 21:40:13 +00:00
def test_song_usage_init(self, MockedManager):
"""
Test the initialisation of the SongUsagePlugin class
"""
# GIVEN: A mocked database manager
mocked_manager = MagicMock()
MockedManager.return_value = mocked_manager
# WHEN: The SongUsagePlugin class is instantiated
song_usage = SongUsagePlugin()
# THEN: It should be initialised correctly
MockedManager.assert_called_with('songusage', init_schema, upgrade_mod=upgrade)
2017-12-22 21:04:29 +00:00
assert mocked_manager == song_usage.manager
assert song_usage.song_usage_active is False
2016-02-12 20:23:18 +00:00
@patch('openlp.plugins.songusage.songusageplugin.Manager')
2016-05-31 21:40:13 +00:00
def test_check_pre_conditions(self, MockedManager):
2016-02-12 20:23:18 +00:00
"""
Test that check_pre_condition returns true for valid manager session
"""
# GIVEN: A mocked database manager
mocked_manager = MagicMock()
mocked_manager.session = MagicMock()
MockedManager.return_value = mocked_manager
song_usage = SongUsagePlugin()
# WHEN: The calling check_pre_conditions
ret = song_usage.check_pre_conditions()
2016-02-12 20:23:18 +00:00
# THEN: It should return True
2017-12-22 22:20:04 +00:00
assert ret is True
2016-02-29 19:29:32 +00:00
@patch('openlp.plugins.songusage.songusageplugin.Manager')
2016-05-31 21:40:13 +00:00
def test_toggle_song_usage_state(self, MockedManager):
2016-02-29 19:29:32 +00:00
"""
Test that toggle_song_usage_state does toggle song_usage_state
"""
# GIVEN: A SongUsagePlugin
song_usage = SongUsagePlugin()
song_usage.set_button_state = MagicMock()
song_usage.song_usage_active = True
# WHEN: calling toggle_song_usage_state
song_usage.toggle_song_usage_state()
# THEN: song_usage_state should have been toogled
2017-12-22 22:20:04 +00:00
assert song_usage.song_usage_active is False