2016-01-11 21:57:45 +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/>. #
|
|
|
|
##########################################################################
|
2016-01-11 21:57:45 +00:00
|
|
|
"""
|
|
|
|
Test the media plugin
|
|
|
|
"""
|
2019-05-22 06:47:00 +00:00
|
|
|
from pathlib import Path
|
2016-01-11 21:57:45 +00:00
|
|
|
from unittest import TestCase
|
2017-04-24 05:17:55 +00:00
|
|
|
from unittest.mock import MagicMock, patch
|
2016-01-11 21:57:45 +00:00
|
|
|
|
|
|
|
from PyQt5 import QtCore
|
|
|
|
|
2017-12-28 08:22:55 +00:00
|
|
|
from openlp.core.common.settings import Settings
|
2017-04-24 05:17:55 +00:00
|
|
|
from openlp.plugins.media.lib.mediaitem import MediaMediaItem
|
2016-01-11 21:57:45 +00:00
|
|
|
from tests.helpers.testmixin import TestMixin
|
|
|
|
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2016-01-11 21:57:45 +00:00
|
|
|
__default_settings__ = {
|
|
|
|
'media/media auto start': QtCore.Qt.Unchecked,
|
|
|
|
'media/media files': []
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class MediaItemTest(TestCase, TestMixin):
|
|
|
|
"""
|
|
|
|
Test the media item for Media
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Set up the components need for all tests.
|
|
|
|
"""
|
|
|
|
with patch('openlp.plugins.media.lib.mediaitem.MediaManagerItem.__init__'),\
|
|
|
|
patch('openlp.plugins.media.lib.mediaitem.MediaMediaItem.setup'):
|
|
|
|
self.media_item = MediaMediaItem(None, MagicMock())
|
|
|
|
self.media_item.settings_section = 'media'
|
|
|
|
self.setup_application()
|
|
|
|
self.build_settings()
|
|
|
|
Settings().extend_default_settings(__default_settings__)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Clean up after the tests
|
|
|
|
"""
|
|
|
|
self.destroy_settings()
|
|
|
|
|
|
|
|
def test_search_found(self):
|
|
|
|
"""
|
|
|
|
Media Remote Search Successful find
|
|
|
|
"""
|
|
|
|
# GIVEN: The Mediaitem set up a list of media
|
2017-08-26 15:06:11 +00:00
|
|
|
Settings().setValue(self.media_item.settings_section + '/media files', [Path('test.mp3'), Path('test.mp4')])
|
2016-01-11 21:57:45 +00:00
|
|
|
# WHEN: Retrieving the test file
|
|
|
|
result = self.media_item.search('test.mp4', False)
|
|
|
|
# THEN: a file should be found
|
2017-12-22 21:04:29 +00:00
|
|
|
assert result == [['test.mp4', 'test.mp4']], 'The result file contain the file name'
|
2016-01-11 21:57:45 +00:00
|
|
|
|
|
|
|
def test_search_not_found(self):
|
|
|
|
"""
|
|
|
|
Media Remote Search not find
|
|
|
|
"""
|
|
|
|
# GIVEN: The Mediaitem set up a list of media
|
2017-08-26 15:06:11 +00:00
|
|
|
Settings().setValue(self.media_item.settings_section + '/media files', [Path('test.mp3'), Path('test.mp4')])
|
2016-01-11 21:57:45 +00:00
|
|
|
# WHEN: Retrieving the test file
|
|
|
|
result = self.media_item.search('test.mpx', False)
|
|
|
|
# THEN: a file should be found
|
2017-12-22 21:04:29 +00:00
|
|
|
assert result == [], 'The result file should be empty'
|