2015-03-06 22:18:51 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# 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, either version 3 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
# 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, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2015-03-06 22:18:51 +00:00
|
|
|
"""
|
|
|
|
Package to test the openlp.core.lib.mediamanageritem package.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
2017-04-24 05:17:55 +00:00
|
|
|
from unittest.mock import MagicMock, patch
|
2015-03-06 22:18:51 +00:00
|
|
|
|
2018-08-25 14:08:19 +00:00
|
|
|
from openlp.core.lib.mediamanageritem import MediaManagerItem
|
2015-03-06 22:18:51 +00:00
|
|
|
from tests.helpers.testmixin import TestMixin
|
|
|
|
|
|
|
|
|
|
|
|
class TestMediaManagerItem(TestCase, TestMixin):
|
|
|
|
"""
|
|
|
|
Test the MediaManagerItem class
|
|
|
|
"""
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Mock out stuff for all the tests
|
|
|
|
"""
|
|
|
|
self.setup_patcher = patch('openlp.core.lib.mediamanageritem.MediaManagerItem._setup')
|
|
|
|
self.mocked_setup = self.setup_patcher.start()
|
|
|
|
self.addCleanup(self.setup_patcher.stop)
|
|
|
|
|
2017-12-02 22:10:22 +00:00
|
|
|
@patch('openlp.core.lib.mediamanageritem.Settings')
|
|
|
|
@patch('openlp.core.lib.mediamanageritem.MediaManagerItem.on_preview_click')
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_on_double_clicked(self, mocked_on_preview_click, MockedSettings):
|
2015-03-06 22:18:51 +00:00
|
|
|
"""
|
|
|
|
Test that when an item is double-clicked then the item is previewed
|
|
|
|
"""
|
|
|
|
# GIVEN: A setting to enable "Double-click to go live" and a media manager item
|
|
|
|
mocked_settings = MagicMock()
|
|
|
|
mocked_settings.value.return_value = False
|
|
|
|
MockedSettings.return_value = mocked_settings
|
|
|
|
mmi = MediaManagerItem(None)
|
2018-12-02 10:09:01 +00:00
|
|
|
mmi.can_preview = True
|
|
|
|
mmi.can_make_live = True
|
|
|
|
mmi.can_add_to_service = True
|
2015-03-06 22:18:51 +00:00
|
|
|
|
|
|
|
# WHEN: on_double_clicked() is called
|
|
|
|
mmi.on_double_clicked()
|
|
|
|
|
|
|
|
# THEN: on_preview_click() should have been called
|
|
|
|
mocked_on_preview_click.assert_called_with()
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_required_icons(self):
|
2016-01-07 12:36:11 +00:00
|
|
|
"""
|
|
|
|
Test the default icons for plugins
|
|
|
|
"""
|
|
|
|
# GIVEN: A MediaManagerItem
|
|
|
|
mmi = MediaManagerItem(None)
|
|
|
|
# WHEN: Object is created
|
|
|
|
mmi.required_icons()
|
|
|
|
# THEN: Default icons should be populated
|
2017-12-17 17:52:17 +00:00
|
|
|
assert mmi.has_import_icon is False, 'There should be no import icon by default'
|
|
|
|
assert mmi.has_new_icon is True, 'By default a new icon should be present'
|
|
|
|
assert mmi.has_file_icon is False, 'There should be no file icon by default'
|
|
|
|
assert mmi.has_delete_icon is True, 'By default a delete icon should be present'
|
|
|
|
assert mmi.add_to_service_item is False, 'There should be no add_to_service icon by default'
|
2018-12-02 10:09:01 +00:00
|
|
|
assert mmi.can_preview is True, 'There should be a preview icon by default'
|
|
|
|
assert mmi.can_make_live is True, 'There should be a make live by default'
|
|
|
|
assert mmi.can_add_to_service is True, 'There should be a add to service icon by default'
|
2016-01-07 12:36:11 +00:00
|
|
|
|
2017-12-02 22:10:22 +00:00
|
|
|
@patch('openlp.core.lib.mediamanageritem.Settings')
|
|
|
|
@patch('openlp.core.lib.mediamanageritem.MediaManagerItem.on_live_click')
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_on_double_clicked_go_live(self, mocked_on_live_click, MockedSettings):
|
2015-03-06 22:18:51 +00:00
|
|
|
"""
|
|
|
|
Test that when "Double-click to go live" is enabled that the item goes live
|
|
|
|
"""
|
|
|
|
# GIVEN: A setting to enable "Double-click to go live" and a media manager item
|
|
|
|
mocked_settings = MagicMock()
|
|
|
|
mocked_settings.value.side_effect = lambda x: x == 'advanced/double click live'
|
|
|
|
MockedSettings.return_value = mocked_settings
|
|
|
|
mmi = MediaManagerItem(None)
|
2018-12-02 09:49:30 +00:00
|
|
|
mmi.can_preview = True
|
|
|
|
mmi.can_make_live = True
|
|
|
|
mmi.can_add_to_service = True
|
2015-03-06 22:18:51 +00:00
|
|
|
|
|
|
|
# WHEN: on_double_clicked() is called
|
|
|
|
mmi.on_double_clicked()
|
|
|
|
|
|
|
|
# THEN: on_live_click() should have been called
|
|
|
|
mocked_on_live_click.assert_called_with()
|
|
|
|
|
2017-12-02 22:10:22 +00:00
|
|
|
@patch('openlp.core.lib.mediamanageritem.Settings')
|
|
|
|
@patch('openlp.core.lib.mediamanageritem.MediaManagerItem.on_live_click')
|
|
|
|
@patch('openlp.core.lib.mediamanageritem.MediaManagerItem.on_preview_click')
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_on_double_clicked_single_click_preview(self, mocked_on_preview_click, mocked_on_live_click,
|
2015-03-06 22:18:51 +00:00
|
|
|
MockedSettings):
|
|
|
|
"""
|
|
|
|
Test that when "Single-click preview" is enabled then nothing happens on double-click
|
|
|
|
"""
|
|
|
|
# GIVEN: A setting to enable "Double-click to go live" and a media manager item
|
|
|
|
mocked_settings = MagicMock()
|
|
|
|
mocked_settings.value.side_effect = lambda x: x == 'advanced/single click preview'
|
|
|
|
MockedSettings.return_value = mocked_settings
|
|
|
|
mmi = MediaManagerItem(None)
|
2018-12-02 09:49:30 +00:00
|
|
|
mmi.can_preview = True
|
|
|
|
mmi.can_make_live = True
|
|
|
|
mmi.can_add_to_service = True
|
2015-03-06 22:18:51 +00:00
|
|
|
|
|
|
|
# WHEN: on_double_clicked() is called
|
|
|
|
mmi.on_double_clicked()
|
|
|
|
|
|
|
|
# THEN: on_live_click() should have been called
|
2017-12-17 17:52:17 +00:00
|
|
|
assert 0 == mocked_on_live_click.call_count, 'on_live_click() should not have been called'
|
|
|
|
assert 0 == mocked_on_preview_click.call_count, 'on_preview_click() should not have been called'
|