2016-01-11 21:57:45 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2020-01-01 02:53:08 +00:00
|
|
|
# Copyright (c) 2008-2020 OpenLP Developers #
|
2019-04-13 13:00:22 +00:00
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# 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
|
|
|
|
"""
|
2020-03-04 06:06:47 +00:00
|
|
|
import pytest
|
2019-05-22 06:47:00 +00:00
|
|
|
from pathlib import Path
|
2017-04-24 05:17:55 +00:00
|
|
|
from unittest.mock import MagicMock, patch
|
2016-01-11 21:57:45 +00:00
|
|
|
|
2020-02-09 20:24:05 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
2017-04-24 05:17:55 +00:00
|
|
|
from openlp.plugins.media.lib.mediaitem import MediaMediaItem
|
2016-01-11 21:57:45 +00:00
|
|
|
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2020-03-04 06:06:47 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def media_item(settings):
|
|
|
|
"""Local test setup"""
|
|
|
|
mocked_main_window = MagicMock()
|
|
|
|
Registry().register('service_list', MagicMock())
|
|
|
|
Registry().register('main_window', mocked_main_window)
|
|
|
|
Registry().register('live_controller', MagicMock())
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
with patch('openlp.plugins.media.lib.mediaitem.MediaManagerItem._setup'), \
|
|
|
|
patch('openlp.plugins.media.lib.mediaitem.MediaMediaItem.setup_item'):
|
|
|
|
m_item = MediaMediaItem(None, mocked_plugin)
|
|
|
|
return m_item
|
2016-01-11 21:57:45 +00:00
|
|
|
|
|
|
|
|
2020-03-04 06:06:47 +00:00
|
|
|
def test_search_found(media_item):
|
2016-01-11 21:57:45 +00:00
|
|
|
"""
|
2020-03-04 06:06:47 +00:00
|
|
|
Media Remote Search Successful find
|
2016-01-11 21:57:45 +00:00
|
|
|
"""
|
2020-03-04 06:06:47 +00:00
|
|
|
# GIVEN: The Mediaitem set up a list of media
|
2020-06-06 16:05:36 +00:00
|
|
|
media_item.settings.setValue('media/media files', [Path('test.mp3'), Path('test.mp4')])
|
2020-03-04 06:06:47 +00:00
|
|
|
# WHEN: Retrieving the test file
|
|
|
|
result = media_item.search('test.mp4', False)
|
|
|
|
# THEN: a file should be found
|
|
|
|
assert result == [['test.mp4', 'test.mp4']], 'The result file contain the file name'
|
2016-01-11 21:57:45 +00:00
|
|
|
|
|
|
|
|
2020-06-10 20:10:56 +00:00
|
|
|
def test_search_found_mixed(media_item):
|
|
|
|
"""
|
|
|
|
Media Remote Search Successful find with Paths and Strings
|
|
|
|
"""
|
|
|
|
# GIVEN: The Mediaitem set up a list of media
|
|
|
|
media_item.settings.setValue('media/media files', [Path('test.mp3'), 'test.mp4'])
|
|
|
|
# WHEN: Retrieving the test file
|
|
|
|
result = media_item.search('test.mp4', False)
|
|
|
|
# THEN: a file should be found
|
|
|
|
assert result == [['test.mp4', 'test.mp4']], 'The result file contain the file name'
|
|
|
|
|
|
|
|
|
2020-03-04 06:06:47 +00:00
|
|
|
def test_search_not_found(media_item):
|
|
|
|
"""
|
|
|
|
Media Remote Search not find
|
|
|
|
"""
|
|
|
|
# GIVEN: The Mediaitem set up a list of media
|
2020-06-06 16:05:36 +00:00
|
|
|
media_item.settings.setValue('media/media files', [Path('test.mp3'), Path('test.mp4')])
|
2020-03-04 06:06:47 +00:00
|
|
|
# WHEN: Retrieving the test file
|
|
|
|
result = media_item.search('test.mpx', False)
|
|
|
|
# THEN: a file should be found
|
|
|
|
assert result == [], 'The result file should be empty'
|