2015-03-10 21:33:35 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2016-12-31 11:01:36 +00:00
|
|
|
# Copyright (c) 2008-2017 OpenLP Developers #
|
2015-03-10 21:33:35 +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; 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 #
|
|
|
|
###############################################################################
|
|
|
|
"""
|
|
|
|
Test the media plugin
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
2017-04-24 05:17:55 +00:00
|
|
|
from unittest.mock import MagicMock, patch
|
2015-03-10 21:33:35 +00:00
|
|
|
|
|
|
|
from openlp.core import Registry
|
2016-04-20 16:36:37 +00:00
|
|
|
from openlp.plugins.media.mediaplugin import MediaPlugin, process_check_binary
|
2015-03-10 21:33:35 +00:00
|
|
|
|
|
|
|
from tests.helpers.testmixin import TestMixin
|
|
|
|
|
|
|
|
|
|
|
|
class MediaPluginTest(TestCase, TestMixin):
|
|
|
|
"""
|
|
|
|
Test the media plugin
|
|
|
|
"""
|
|
|
|
def setUp(self):
|
|
|
|
Registry.create()
|
|
|
|
|
2017-08-12 17:45:56 +00:00
|
|
|
@patch('openlp.plugins.media.mediaplugin.Plugin.initialise')
|
|
|
|
def test_initialise(self, mocked_initialise):
|
2015-03-10 21:33:35 +00:00
|
|
|
"""
|
|
|
|
Test that the initialise() method overwrites the built-in one, but still calls it
|
|
|
|
"""
|
2017-08-12 17:45:56 +00:00
|
|
|
# GIVEN: A media plugin instance
|
2015-03-10 21:33:35 +00:00
|
|
|
media_plugin = MediaPlugin()
|
|
|
|
|
|
|
|
# WHEN: initialise() is called
|
|
|
|
media_plugin.initialise()
|
|
|
|
|
2017-08-12 17:45:56 +00:00
|
|
|
# THEN: The the base initialise() method should be called
|
2015-03-10 21:33:35 +00:00
|
|
|
mocked_initialise.assert_called_with()
|
2016-01-04 00:28:13 +00:00
|
|
|
|
|
|
|
def test_about_text(self):
|
|
|
|
# GIVEN: The MediaPlugin
|
|
|
|
# WHEN: Retrieving the about text
|
|
|
|
# THEN: about() should return a string object
|
|
|
|
self.assertIsInstance(MediaPlugin.about(), str)
|
|
|
|
# THEN: about() should return a non-empty string
|
|
|
|
self.assertNotEquals(len(MediaPlugin.about()), 0)
|
2016-04-20 16:36:37 +00:00
|
|
|
|
2016-04-21 16:26:34 +00:00
|
|
|
@patch('openlp.plugins.media.mediaplugin.check_binary_exists')
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_process_check_binary_pass(self, mocked_checked_binary_exists):
|
2016-04-20 16:36:37 +00:00
|
|
|
"""
|
|
|
|
Test that the Process check returns true if found
|
|
|
|
"""
|
|
|
|
# GIVEN: A media plugin instance
|
|
|
|
# WHEN: function is called with the correct name
|
2016-04-21 16:26:34 +00:00
|
|
|
mocked_checked_binary_exists.return_value = str.encode('MediaInfo Command line')
|
|
|
|
result = process_check_binary('MediaInfo')
|
2016-04-20 16:36:37 +00:00
|
|
|
|
|
|
|
# THEN: The the result should be True
|
2016-04-21 16:26:34 +00:00
|
|
|
self.assertTrue(result, 'Mediainfo should have been found')
|
2016-04-20 16:36:37 +00:00
|
|
|
|
2016-04-21 16:26:34 +00:00
|
|
|
@patch('openlp.plugins.media.mediaplugin.check_binary_exists')
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_process_check_binary_fail(self, mocked_checked_binary_exists):
|
2016-04-20 16:36:37 +00:00
|
|
|
"""
|
|
|
|
Test that the Process check returns false if not found
|
|
|
|
"""
|
|
|
|
# GIVEN: A media plugin instance
|
|
|
|
# WHEN: function is called with the wrong name
|
2016-04-21 16:26:34 +00:00
|
|
|
mocked_checked_binary_exists.return_value = str.encode('MediaInfo1 Command line')
|
2016-04-20 16:36:37 +00:00
|
|
|
result = process_check_binary("MediaInfo1")
|
|
|
|
|
|
|
|
# THEN: The the result should be True
|
2016-04-21 16:26:34 +00:00
|
|
|
self.assertFalse(result, "Mediainfo should not have been found")
|