From 43f18ee2c9f8cfe0cb0ec99504042763363346c1 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sat, 5 Apr 2014 09:46:35 +0200 Subject: [PATCH] Added some tests. --- .../media/forms/mediaclipselectorform.py | 6 +- .../media/forms/test_mediaclipselectorform.py | 59 ++++++++++++++++++- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/media/forms/mediaclipselectorform.py b/openlp/plugins/media/forms/mediaclipselectorform.py index 005f821a4..bbc525834 100644 --- a/openlp/plugins/media/forms/mediaclipselectorform.py +++ b/openlp/plugins/media/forms/mediaclipselectorform.py @@ -129,7 +129,7 @@ class MediaClipSelectorForm(QtGui.QDialog, Ui_MediaClipSelector): self.toggle_disable_load_media(False) return if not os.path.exists(path): - log.debug('vlc media player is none') + log.debug('Given path does not exists') critical_error_message_box(message=translate('MediaPlugin.MediaClipSelectorForm', 'Given path does not exists')) self.toggle_disable_load_media(False) @@ -259,7 +259,7 @@ class MediaClipSelectorForm(QtGui.QDialog, Ui_MediaClipSelector): :param index: The index of the newly chosen title track. """ - log.debug('in on_title_combo_box_changed, index: ', str(index)) + log.debug('in on_title_combo_box_changed, index: %d', index) self.vlc_media_player.set_title(index) self.vlc_media_player.set_time(0) self.vlc_media_player.play() @@ -306,7 +306,7 @@ class MediaClipSelectorForm(QtGui.QDialog, Ui_MediaClipSelector): :param index: The index of the newly chosen audio track. """ audio_track = self.audio_tracks_combobox.itemData(index) - log.debug('in on_audio_tracks_combobox_currentIndexChanged, index: ', str(index), ' audio_track: ', audio_track) + log.debug('in on_audio_tracks_combobox_currentIndexChanged, index: %d audio_track: %s' % (index, audio_track)) if audio_track and int(audio_track) > 0: self.vlc_media_player.audio_set_track(int(audio_track)) diff --git a/tests/interfaces/openlp_plugins/media/forms/test_mediaclipselectorform.py b/tests/interfaces/openlp_plugins/media/forms/test_mediaclipselectorform.py index 5939a5e05..fb7519057 100644 --- a/tests/interfaces/openlp_plugins/media/forms/test_mediaclipselectorform.py +++ b/tests/interfaces/openlp_plugins/media/forms/test_mediaclipselectorform.py @@ -84,14 +84,69 @@ class TestMediaClipSelectorForm(TestCase, TestMixin): def click_load_button_test(self): """ - Test that the correct function is called when load is clicked + Test that the correct function is called when load is clicked, and that it behaves as expected. """ # GIVEN: Mocked methods. with patch('openlp.plugins.media.forms.mediaclipselectorform.critical_error_message_box') as \ - mocked_critical_error_message_box: + mocked_critical_error_message_box,\ + patch('openlp.plugins.media.forms.mediaclipselectorform.os.path.exists') as mocked_os_path_exists,\ + patch('PyQt4.QtGui.QDialog.exec_') as mocked_exec: + self.form.exec_() # 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') + + # WHEN: The load button is clicked with a non-existing path + mocked_os_path_exists.return_value = False + self.form.media_path_combobox.insertItem (0, '/non-existing/test-path.test') + self.form.media_path_combobox.setCurrentIndex(0) + QtTest.QTest.mouseClick(self.form.load_disc_pushbutton, QtCore.Qt.LeftButton) + + # THEN: we should get an error + assert self.form.media_path_combobox.currentText() == '/non-existing/test-path.test',\ + 'The media path should be the given one.' + mocked_critical_error_message_box.assert_called_with(message='Given path does not exists') + + # WHEN: The load button is clicked with a mocked existing path + mocked_os_path_exists.return_value = True + self.form.vlc_media_player = MagicMock() + self.form.vlc_media_player.play.return_value = -1 + self.form.media_path_combobox.insertItem (0, '/existing/test-path.test') + self.form.media_path_combobox.setCurrentIndex(0) + QtTest.QTest.mouseClick(self.form.load_disc_pushbutton, QtCore.Qt.LeftButton) + + # THEN: we should get an error + assert self.form.media_path_combobox.currentText() == '/existing/test-path.test',\ + 'The media path should be the given one.' + mocked_critical_error_message_box.assert_called_with(message='VLC player failed playing the media') + + def title_combobox_test(self): + """ + Test the behavior when the title combobox is updated + """ + # GIVEN: Mocked methods and some entries in the title combobox. + with patch('PyQt4.QtGui.QDialog.exec_') as mocked_exec: + self.form.exec_() + self.form.audio_tracks_combobox.itemData = MagicMock() + self.form.subtitle_tracks_combobox.itemData = MagicMock() + self.form.audio_tracks_combobox.itemData.return_value = None + self.form.subtitle_tracks_combobox.itemData.return_value = None + self.form.title_combo_box.insertItem(0, 'Test Title 0') + self.form.title_combo_box.insertItem(1, 'Test Title 1') + + + # WHEN: There exists audio and subtitle tracks and the index is updated. + self.form.vlc_media_player.audio_get_track_description.return_value = [(-1, b'Disabled'), + (0, b'Audio Track 1')] + self.form.vlc_media_player.video_get_spu_description.return_value = [(-1, b'Disabled'), + (0, b'Subtitle Track 1')] + self.form.title_combo_box.setCurrentIndex(1) + + # THEN: The subtitle and audio track comboboxes should be updated and get signals and call itemData. + self.form.audio_tracks_combobox.itemData.assert_any_call(0) + self.form.audio_tracks_combobox.itemData.assert_any_call(1) + self.form.subtitle_tracks_combobox.itemData.assert_any_call(0) +