Added first tests for mediaclipselectorform.py

This commit is contained in:
Tomas Groth 2014-03-20 22:52:53 +01:00
parent 852ec00fd7
commit 3608ad4fcd
4 changed files with 136 additions and 3 deletions

View File

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################

View File

@ -36,6 +36,7 @@ from datetime import datetime
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.common import translate
from openlp.plugins.media.forms.mediaclipselectordialog import Ui_MediaClipSelector from openlp.plugins.media.forms.mediaclipselectordialog import Ui_MediaClipSelector
from openlp.core.lib.ui import critical_error_message_box from openlp.core.lib.ui import critical_error_message_box
from openlp.core.ui.media.vendor import vlc from openlp.core.ui.media.vendor import vlc
@ -117,13 +118,14 @@ class MediaClipSelectorForm(QtGui.QDialog, Ui_MediaClipSelector):
path = self.media_path_combobox.currentText() path = self.media_path_combobox.currentText()
if path == '': if path == '':
log.debug('no given path') log.debug('no given path')
critical_error_message_box('Error', 'No path was given') critical_error_message_box(message=translate('MediaPlugin.MediaClipSelectorForm', 'No path was given'))
self.toggle_disable_load_media(False) self.toggle_disable_load_media(False)
return return
self.vlc_media = self.vlc_instance.media_new_path(path) self.vlc_media = self.vlc_instance.media_new_path(path)
if not self.vlc_media: if not self.vlc_media:
log.debug('vlc media player is none') log.debug('vlc media player is none')
critical_error_message_box('Error', 'An error happened during initialization of VLC player') critical_error_message_box(message=translate('MediaPlugin.MediaClipSelectorForm',
'An error happened during initialization of VLC player'))
self.toggle_disable_load_media(False) self.toggle_disable_load_media(False)
return return
# put the media in the media player # put the media in the media player
@ -132,7 +134,8 @@ class MediaClipSelectorForm(QtGui.QDialog, Ui_MediaClipSelector):
# start playback to get vlc to parse the media # start playback to get vlc to parse the media
if self.vlc_media_player.play() < 0: if self.vlc_media_player.play() < 0:
log.debug('vlc play returned error') log.debug('vlc play returned error')
critical_error_message_box('Error', 'An error happen when starting VLC player') critical_error_message_box(message=translate('MediaPlugin.MediaClipSelectorForm',
'An error happen when starting VLC player'))
self.toggle_disable_load_media(False) self.toggle_disable_load_media(False)
return return
self.vlc_media_player.audio_set_mute(True) self.vlc_media_player.audio_set_mute(True)

View File

@ -0,0 +1,102 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
"""
Module to test the MediaClipSelectorForm.
"""
from unittest import TestCase
from PyQt4 import QtGui, QtTest, QtCore
from openlp.core.common import Registry
from openlp.plugins.media.forms.mediaclipselectorform import MediaClipSelectorForm
from tests.interfaces import MagicMock, patch
from tests.helpers.testmixin import TestMixin
class TestMediaClipSelectorForm(TestCase, TestMixin):
"""
Test the EditCustomSlideForm.
"""
def setUp(self):
"""
Create the UI
"""
Registry.create()
self.get_application()
self.main_window = QtGui.QMainWindow()
Registry().register('main_window', self.main_window)
# Mock VLC so we don't actually use it
self.vlc_patcher = patch('openlp.plugins.media.forms.mediaclipselectorform.vlc')
self.vlc_patcher.start()
# Mock the media item
self.mock_media_item = MagicMock()
# Mock media_state_wait to avoid waiting for VLC playing state
#self.mock_media_state_wait = patch('openlp.plugins.media.forms.mediaclipselectorform.media_state_wait')
#self.mock_media_state_wait.return_value = True
#self.mock_media_state_wait.start()
# create form to test
self.form = MediaClipSelectorForm(self.mock_media_item, self.main_window, None)
mock_media_state_wait = MagicMock()
mock_media_state_wait.return_value = True
self.form.media_state_wait = mock_media_state_wait
def tearDown(self):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
#self.mock_media_state_wait.stop()
self.vlc_patcher.stop()
del self.form
del self.main_window
def basic_test(self):
"""
Test if the dialog is correctly set up.
"""
# GIVEN: A mocked QDialog.exec_() method
with patch('PyQt4.QtGui.QDialog.exec_') as mocked_exec:
# WHEN: Show the dialog.
self.form.exec_()
# THEN: The media path should be empty.
assert self.form.media_path_combobox.currentText() == '', 'There should not be any text in the media path.'
def click_load_button_test(self):
"""
Test that the correct function is called when load is clicked
"""
# GIVEN: Mocked methods.
with patch('openlp.plugins.media.forms.mediaclipselectorform.critical_error_message_box') as \
mocked_critical_error_message_box:
# WHEN: The load button is clicked with no path set
QtTest.QTest.mouseClick(self.form.load_disc_pushbutton, QtCore.Qt.LeftButton)
# THEN: we should get an error
mocked_critical_error_message_box.assert_called_with(message='No path was given')