← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~raoul-snyman/openlp/media-player-config into lp:openlp

 

Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/media-player-config into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~raoul-snyman/openlp/media-player-config/+merge/216562

Fix an exception raised when loading media players if the configuration is blank

--------------------------------
lp:~raoul-snyman/openlp/media-player-config (revision 2369)
[SUCCESS] http://ci.openlp.org/job/Branch-01-Pull/373/
[SUCCESS] http://ci.openlp.org/job/Branch-02-Functional-Tests/330/
[SUCCESS] http://ci.openlp.org/job/Branch-03-Interface-Tests/277/
[SUCCESS] http://ci.openlp.org/job/Branch-04-Windows_Tests/239/
[SUCCESS] http://ci.openlp.org/job/Branch-05a-Code_Analysis/164/
[SUCCESS] http://ci.openlp.org/job/Branch-05b-Test_Coverage/39/
-- 
https://code.launchpad.net/~raoul-snyman/openlp/media-player-config/+merge/216562
Your team OpenLP Core is requested to review the proposed merge of lp:~raoul-snyman/openlp/media-player-config into lp:openlp.
=== modified file 'openlp/core/ui/media/__init__.py'
--- openlp/core/ui/media/__init__.py	2014-04-12 20:19:22 +0000
+++ openlp/core/ui/media/__init__.py	2014-04-20 22:42:51 +0000
@@ -90,7 +90,7 @@
             overridden_player = 'auto'
     else:
         overridden_player = ''
-    saved_players_list = saved_players.replace('[', '').replace(']', '').split(',')
+    saved_players_list = saved_players.replace('[', '').replace(']', '').split(',') if saved_players else []
     return saved_players_list, overridden_player
 
 

=== added file 'tests/functional/openlp_core_ui/test_media.py'
--- tests/functional/openlp_core_ui/test_media.py	1970-01-01 00:00:00 +0000
+++ tests/functional/openlp_core_ui/test_media.py	2014-04-20 22:42:51 +0000
@@ -0,0 +1,128 @@
+# -*- 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                          #
+###############################################################################
+"""
+Package to test the openlp.core.ui package.
+"""
+from PyQt4 import QtCore
+from unittest import TestCase
+
+from openlp.core.ui.media import get_media_players
+
+from tests.functional import MagicMock, patch
+from tests.helpers.testmixin import TestMixin
+
+
+class TestMedia(TestCase, TestMixin):
+
+    def setUp(self):
+        pass
+
+    def test_get_media_players_no_config(self):
+        """
+        Test that when there's no config, get_media_players() returns an empty list of players (not a string)
+        """
+        def value_results(key):
+            if key == 'media/players':
+                return ''
+            else:
+                return False
+
+        # GIVEN: A mocked out Settings() object
+        with patch('openlp.core.ui.media.Settings.value') as mocked_value:
+            mocked_value.side_effect = value_results
+
+            # WHEN: get_media_players() is called
+            used_players, overridden_player = get_media_players()
+
+            # THEN: the used_players should be an empty list, and the overridden player should be an empty string
+            self.assertEqual([], used_players, 'Used players should be an empty list')
+            self.assertEqual('', overridden_player, 'Overridden player should be an empty string')
+
+    def test_get_media_players_no_players(self):
+        """
+        Test that when there's no players but overridden player is set, get_media_players() returns 'auto'
+        """
+        def value_results(key):
+            if key == 'media/override player':
+                return QtCore.Qt.Checked
+            else:
+                return ''
+
+        # GIVEN: A mocked out Settings() object
+        with patch('openlp.core.ui.media.Settings.value') as mocked_value:
+            mocked_value.side_effect = value_results
+
+            # WHEN: get_media_players() is called
+            used_players, overridden_player = get_media_players()
+
+            # THEN: the used_players should be an empty list, and the overridden player should be an empty string
+            self.assertEqual([], used_players, 'Used players should be an empty list')
+            self.assertEqual('auto', overridden_player, 'Overridden player should be "auto"')
+
+    def test_get_media_players_with_valid_list(self):
+        """
+        Test that when get_media_players() is called the string list is interpreted correctly
+        """
+        def value_results(key):
+            if key == 'media/players':
+                return '[vlc,webkit,phonon]'
+            else:
+                return False
+
+        # GIVEN: A mocked out Settings() object
+        with patch('openlp.core.ui.media.Settings.value') as mocked_value:
+            mocked_value.side_effect = value_results
+
+            # WHEN: get_media_players() is called
+            used_players, overridden_player = get_media_players()
+
+            # THEN: the used_players should be an empty list, and the overridden player should be an empty string
+            self.assertEqual(['vlc', 'webkit', 'phonon'], used_players, 'Used players should be correct')
+            self.assertEqual('', overridden_player, 'Overridden player should be an empty string')
+
+    def test_get_media_players_with_overridden_player(self):
+        """
+        Test that when get_media_players() is called the overridden player is correctly set
+        """
+        def value_results(key):
+            if key == 'media/players':
+                return '[vlc,webkit,phonon]'
+            else:
+                return QtCore.Qt.Checked
+
+        # GIVEN: A mocked out Settings() object
+        with patch('openlp.core.ui.media.Settings.value') as mocked_value:
+            mocked_value.side_effect = value_results
+
+            # WHEN: get_media_players() is called
+            used_players, overridden_player = get_media_players()
+
+            # THEN: the used_players should be an empty list, and the overridden player should be an empty string
+            self.assertEqual(['vlc', 'webkit', 'phonon'], used_players, 'Used players should be correct')
+            self.assertEqual('vlc,webkit,phonon', overridden_player, 'Overridden player should be a string of players')
\ No newline at end of file


Follow ups