Fix up tests

This commit is contained in:
Phill Ridout 2015-01-26 20:42:19 +00:00
parent 3dc248e556
commit 1712464e8c
3 changed files with 27 additions and 17 deletions

View File

@ -222,9 +222,15 @@ class WebkitPlayer(MediaPlayer):
def check_available(self):
"""
Check the availability of the media player
Check the availability of the media player.
:return: boolean. True if available
"""
web = QtWebKit.QWebPage()
# This script should return '[object HTMLVideoElement]' if the html5 video is available in webkit. Otherwise it
# should return '[object HTMLUnknownElement]'
mf = web.mainFrame()
return web.mainFrame().evaluateJavaScript(
"Object.prototype.toString.call(document.createElement('video'));") == '[object HTMLVideoElement]'

View File

@ -23,7 +23,7 @@
Package to test the openlp.core.ui.media.webkitplayer package.
"""
from unittest import TestCase
from tests.functional import patch
from tests.functional import MagicMock, patch
from openlp.core.ui.media.webkitplayer import WebkitPlayer
@ -33,32 +33,36 @@ class TestWebkitPlayer(TestCase):
Test the functions in the :mod:`webkitplayer` module.
"""
def check_available_mac_test(self):
def check_available_video_disabled_test(self):
"""
Simple test of webkitplayer availability on Mac OS X
Test of webkit video unavailability
"""
# GIVEN: A WebkitPlayer and a mocked is_macosx
with patch('openlp.core.ui.media.webkitplayer.is_macosx') as mocked_is_macosx:
mocked_is_macosx.return_value = True
# GIVEN: A WebkitPlayer instance and a mocked QWebPage
mocked_qwebpage = MagicMock()
mocked_qwebpage.mainFrame().evaluateJavaScript.return_value = '[object HTMLUnknownElement]'
with patch('openlp.core.ui.media.webkitplayer.QtWebKit.QWebPage', **{'return_value': mocked_qwebpage}):
webkit_player = WebkitPlayer(None)
# WHEN: An checking if the player is available
available = webkit_player.check_available()
# THEN: The player should not be available on Mac OS X
self.assertEqual(False, available, 'The WebkitPlayer should not be available on Mac OS X.')
# THEN: The player should not be available when '[object HTMLUnknownElement]' is returned
self.assertEqual(False, available,
'The WebkitPlayer should not be available when video feature detection fails')
def check_available_non_mac_test(self):
def check_available_video_enabled_test(self):
"""
Simple test of webkitplayer availability when not on Mac OS X
Test of webkit video availability
"""
# GIVEN: A WebkitPlayer and a mocked is_macosx
with patch('openlp.core.ui.media.webkitplayer.is_macosx') as mocked_is_macosx:
mocked_is_macosx.return_value = False
# GIVEN: A WebkitPlayer instance and a mocked QWebPage
mocked_qwebpage = MagicMock()
mocked_qwebpage.mainFrame().evaluateJavaScript.return_value = '[object HTMLUnknownElement]'
with patch('openlp.core.ui.media.webkitplayer.QtWebKit.QWebPage', **{'return_value': mocked_qwebpage}):
webkit_player = WebkitPlayer(None)
# WHEN: An checking if the player is available
available = webkit_player.check_available()
# THEN: The player should be available when not on Mac OS X
self.assertEqual(True, available, 'The WebkitPlayer should be available when not on Mac OS X.')
# THEN: The player should be available when '[object HTMLVideoElement]' is returned
self.assertEqual(True, available,
'The WebkitPlayer should be available when video feature detection passes')

View File

@ -134,7 +134,7 @@ class TestInit(TestCase, TestMixin):
Test that parse_options parses valid short options correctly when passed through sys.argv
"""
# GIVEN: A list of valid options
options = ['-e', '-l', 'debug', '-pd', '-s', 'style', 'extra', 'qt', 'args']
options = ['openlp.py', '-e', '-l', 'debug', '-pd', '-s', 'style', 'extra', 'qt', 'args']
# WHEN: Passing in the options through sys.argv and calling parse_args with None
with patch.object(sys, 'argv', options):