From 3d18478ac793914082a71476ed12e37d0810d66c Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 18 May 2019 08:56:22 -0700 Subject: [PATCH] Fix up the tests --- .../presentations/lib/libreofficeserver.py | 4 +- .../openlp_core/ui/media/test_vlcplayer.py | 15 ----- .../presentations/test_libreofficeserver.py | 58 +++++-------------- .../presentations/test_maclocontroller.py | 34 +++-------- 4 files changed, 24 insertions(+), 87 deletions(-) diff --git a/openlp/plugins/presentations/lib/libreofficeserver.py b/openlp/plugins/presentations/lib/libreofficeserver.py index 38981789f..99a04f654 100644 --- a/openlp/plugins/presentations/lib/libreofficeserver.py +++ b/openlp/plugins/presentations/lib/libreofficeserver.py @@ -162,9 +162,9 @@ class LibreOfficeServer(object): log.exception('Unable to find running instance, retrying...') loop += 1 try: - manager = uno_instance.ServiceManager + self._manager = uno_instance.ServiceManager log.debug('get UNO Desktop Openoffice - createInstanceWithContext - Desktop') - desktop = manager.createInstanceWithContext('com.sun.star.frame.Desktop', uno_instance) + desktop = self._manager.createInstanceWithContext('com.sun.star.frame.Desktop', uno_instance) if not desktop: raise Exception('Failed to get UNO desktop') self._desktop = desktop diff --git a/tests/functional/openlp_core/ui/media/test_vlcplayer.py b/tests/functional/openlp_core/ui/media/test_vlcplayer.py index 08e17377b..d3de03758 100644 --- a/tests/functional/openlp_core/ui/media/test_vlcplayer.py +++ b/tests/functional/openlp_core/ui/media/test_vlcplayer.py @@ -65,21 +65,6 @@ class TestVLCPlayer(TestCase, TestMixin): # THEN: The extra environment variable should be there assert 'openlp.core.ui.media.vendor.vlc' not in sys.modules - @patch('openlp.core.ui.media.vlcplayer.is_macosx') - def test_fix_vlc_22_plugin_path(self, mocked_is_macosx): - """ - Test that on OS X we set the VLC plugin path to fix a bug in the VLC module - """ - # GIVEN: We're on OS X and we don't have the VLC plugin path set - mocked_is_macosx.return_value = True - - # WHEN: An checking if the player is available - get_vlc() - - # THEN: The extra environment variable should be there - assert 'VLC_PLUGIN_PATH' in os.environ, 'The plugin path should be in the environment variables' - assert '/Applications/VLC.app/Contents/MacOS/plugins' == os.environ['VLC_PLUGIN_PATH'] - @patch.dict(os.environ) @patch('openlp.core.ui.media.vlcplayer.is_macosx') def test_not_osx_fix_vlc_22_plugin_path(self, mocked_is_macosx): diff --git a/tests/functional/openlp_plugins/presentations/test_libreofficeserver.py b/tests/functional/openlp_plugins/presentations/test_libreofficeserver.py index cb98705f4..af8548a52 100644 --- a/tests/functional/openlp_plugins/presentations/test_libreofficeserver.py +++ b/tests/functional/openlp_plugins/presentations/test_libreofficeserver.py @@ -64,13 +64,13 @@ def test_start_process(MockedPopen): '--minimized', '--nodefault', '--nofirststartwizard', - '--accept=pipe,name=openlp_pipe;urp;' + '--accept=pipe,name=openlp_maclo;urp;StarOffice.ServiceManager' ]) assert server._process is mocked_process @patch('openlp.plugins.presentations.lib.libreofficeserver.uno') -def test_setup_desktop_already_has_desktop(mocked_uno): +def test_desktop_already_has_desktop(mocked_uno): """ Test that setup_desktop() exits early when there's already a desktop """ @@ -78,15 +78,16 @@ def test_setup_desktop_already_has_desktop(mocked_uno): server = LibreOfficeServer() server._desktop = MagicMock() - # WHEN: setup_desktop() is called - server.setup_desktop() + # WHEN: the desktop property is called + desktop = server.desktop # THEN: setup_desktop() exits early + assert desktop is server._desktop assert server._manager is None @patch('openlp.plugins.presentations.lib.libreofficeserver.uno') -def test_setup_desktop_exception(mocked_uno): +def test_desktop_exception(mocked_uno): """ Test that setting up the desktop works correctly when an exception occurs """ @@ -102,16 +103,16 @@ def test_setup_desktop_exception(mocked_uno): mocked_uno_instance.ServiceManager = MockedServiceManager MockedServiceManager.createInstanceWithContext.side_effect = Exception() - # WHEN: setup_desktop() is called - server.setup_desktop() + # WHEN: the desktop property is called + server.desktop # THEN: A desktop object was created mocked_uno.getComponentContext.assert_called_once_with() mocked_context.ServiceManager.createInstanceWithContext.assert_called_once_with( 'com.sun.star.bridge.UnoUrlResolver', mocked_context) expected_calls = [ - call('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext'), - call('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext') + call('uno:pipe,name=openlp_maclo;urp;StarOffice.ComponentContext'), + call('uno:pipe,name=openlp_maclo;urp;StarOffice.ComponentContext') ] assert mocked_resolver.resolve.call_args_list == expected_calls MockedServiceManager.createInstanceWithContext.assert_called_once_with( @@ -121,7 +122,7 @@ def test_setup_desktop_exception(mocked_uno): @patch('openlp.plugins.presentations.lib.libreofficeserver.uno') -def test_setup_desktop(mocked_uno): +def test_desktop(mocked_uno): """ Test that setting up the desktop works correctly """ @@ -138,16 +139,16 @@ def test_setup_desktop(mocked_uno): mocked_uno_instance.ServiceManager = MockedServiceManager MockedServiceManager.createInstanceWithContext.return_value = mocked_desktop - # WHEN: setup_desktop() is called - server.setup_desktop() + # WHEN: the desktop property is called + server.desktop # THEN: A desktop object was created mocked_uno.getComponentContext.assert_called_once_with() mocked_context.ServiceManager.createInstanceWithContext.assert_called_once_with( 'com.sun.star.bridge.UnoUrlResolver', mocked_context) expected_calls = [ - call('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext'), - call('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext') + call('uno:pipe,name=openlp_maclo;urp;StarOffice.ComponentContext'), + call('uno:pipe,name=openlp_maclo;urp;StarOffice.ComponentContext') ] assert mocked_resolver.resolve.call_args_list == expected_calls MockedServiceManager.createInstanceWithContext.assert_called_once_with( @@ -257,35 +258,6 @@ def test_get_text_from_page_notes(): assert text == 'Page Notes\n' -def test_has_desktop_no_desktop(): - """ - Test the has_desktop() method when there's no desktop - """ - # GIVEN: A LibreOfficeServer object - server = LibreOfficeServer() - - # WHEN: has_desktop() is called - result = server.has_desktop() - - # THEN: The result should be False - assert result is False - - -def test_has_desktop(): - """ - Test the has_desktop() method - """ - # GIVEN: A LibreOfficeServer object and a desktop - server = LibreOfficeServer() - server._desktop = MagicMock() - - # WHEN: has_desktop() is called - result = server.has_desktop() - - # THEN: The result should be True - assert result is True - - def test_shutdown_other_docs(): """ Test the shutdown method while other documents are open in LibreOffice diff --git a/tests/functional/openlp_plugins/presentations/test_maclocontroller.py b/tests/functional/openlp_plugins/presentations/test_maclocontroller.py index e295dfd86..846ff098f 100644 --- a/tests/functional/openlp_plugins/presentations/test_maclocontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_maclocontroller.py @@ -160,21 +160,6 @@ class TestMacLODocument(TestCase): self.controller._client = self.mocked_client self.document = MacLODocument(self.controller, self.file_name) - def test_load_presentation_no_desktop(self): - """ - Test the load_presentation() method when there's no desktop yet - """ - # GIVEN: A document and a mocked client - self.mocked_client.has_desktop.return_value = False - - # WHEN: load_presentation() is called - result = self.document.load_presentation() - - # THEN: Stuff should work right - self.mocked_client.setup_desktop.assert_called_once_with() - self.mocked_client.has_desktop.assert_called_once_with() - assert result is False - @patch('openlp.plugins.presentations.lib.maclocontroller.ScreenList') def test_load_presentation_cannot_load(self, MockedScreenList): """ @@ -183,17 +168,14 @@ class TestMacLODocument(TestCase): # GIVEN: A document and a mocked client mocked_screen_list = MagicMock() MockedScreenList.return_value = mocked_screen_list - mocked_screen_list.current = {'number': 0} - self.mocked_client.has_desktop.return_value = True + mocked_screen_list.current.number = 0 self.mocked_client.load_presentation.return_value = False # WHEN: load_presentation() is called result = self.document.load_presentation() # THEN: Stuff should work right - self.mocked_client.setup_desktop.assert_called_once_with() - self.mocked_client.has_desktop.assert_called_once_with() - self.mocked_client.load_presentation.assert_called_once_with(self.file_name, 1) + self.mocked_client.load_presentation.assert_called_once_with(str(self.file_name), 1) assert result is False @patch('openlp.plugins.presentations.lib.maclocontroller.ScreenList') @@ -204,8 +186,7 @@ class TestMacLODocument(TestCase): # GIVEN: A document and a mocked client mocked_screen_list = MagicMock() MockedScreenList.return_value = mocked_screen_list - mocked_screen_list.current = {'number': 0} - self.mocked_client.has_desktop.return_value = True + mocked_screen_list.current.number = 0 self.mocked_client.load_presentation.return_value = True # WHEN: load_presentation() is called @@ -214,9 +195,7 @@ class TestMacLODocument(TestCase): result = self.document.load_presentation() # THEN: Stuff should work right - self.mocked_client.setup_desktop.assert_called_once_with() - self.mocked_client.has_desktop.assert_called_once_with() - self.mocked_client.load_presentation.assert_called_once_with(self.file_name, 1) + self.mocked_client.load_presentation.assert_called_once_with(str(self.file_name), 1) mocked_create_thumbnails.assert_called_once_with() mocked_create_titles_and_notes.assert_called_once_with() assert result is True @@ -252,8 +231,8 @@ class TestMacLODocument(TestCase): # THEN: The method should complete successfully self.mocked_client.extract_thumbnails.assert_called_once_with('temp') assert mocked_convert_thumbnail.call_args_list == [ - call('thumb1.png', 1), call('thumb2.png', 2)] - assert mocked_delete_file.call_args_list == [call('thumb1.png'), call('thumb2.png')] + call(Path('thumb1.png'), 1), call(Path('thumb2.png'), 2)] + assert mocked_delete_file.call_args_list == [call(Path('thumb1.png')), call(Path('thumb2.png'))] def test_create_titles_and_notes(self): """ @@ -370,6 +349,7 @@ class TestMacLODocument(TestCase): """ # GIVEN: a mocked client, and multiple screens mocked_screen_list = MagicMock() + mocked_screen_list.__len__.return_value = 2 mocked_registry = MagicMock() mocked_main_window = MagicMock() MockedScreenList.return_value = mocked_screen_list