Fix up the tests

This commit is contained in:
Raoul Snyman 2019-05-18 08:56:22 -07:00
parent f74e0c7dc8
commit 3d18478ac7
4 changed files with 24 additions and 87 deletions

View File

@ -162,9 +162,9 @@ class LibreOfficeServer(object):
log.exception('Unable to find running instance, retrying...') log.exception('Unable to find running instance, retrying...')
loop += 1 loop += 1
try: try:
manager = uno_instance.ServiceManager self._manager = uno_instance.ServiceManager
log.debug('get UNO Desktop Openoffice - createInstanceWithContext - Desktop') 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: if not desktop:
raise Exception('Failed to get UNO desktop') raise Exception('Failed to get UNO desktop')
self._desktop = desktop self._desktop = desktop

View File

@ -65,21 +65,6 @@ class TestVLCPlayer(TestCase, TestMixin):
# THEN: The extra environment variable should be there # THEN: The extra environment variable should be there
assert 'openlp.core.ui.media.vendor.vlc' not in sys.modules 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.dict(os.environ)
@patch('openlp.core.ui.media.vlcplayer.is_macosx') @patch('openlp.core.ui.media.vlcplayer.is_macosx')
def test_not_osx_fix_vlc_22_plugin_path(self, mocked_is_macosx): def test_not_osx_fix_vlc_22_plugin_path(self, mocked_is_macosx):

View File

@ -64,13 +64,13 @@ def test_start_process(MockedPopen):
'--minimized', '--minimized',
'--nodefault', '--nodefault',
'--nofirststartwizard', '--nofirststartwizard',
'--accept=pipe,name=openlp_pipe;urp;' '--accept=pipe,name=openlp_maclo;urp;StarOffice.ServiceManager'
]) ])
assert server._process is mocked_process assert server._process is mocked_process
@patch('openlp.plugins.presentations.lib.libreofficeserver.uno') @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 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 = LibreOfficeServer()
server._desktop = MagicMock() server._desktop = MagicMock()
# WHEN: setup_desktop() is called # WHEN: the desktop property is called
server.setup_desktop() desktop = server.desktop
# THEN: setup_desktop() exits early # THEN: setup_desktop() exits early
assert desktop is server._desktop
assert server._manager is None assert server._manager is None
@patch('openlp.plugins.presentations.lib.libreofficeserver.uno') @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 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 mocked_uno_instance.ServiceManager = MockedServiceManager
MockedServiceManager.createInstanceWithContext.side_effect = Exception() MockedServiceManager.createInstanceWithContext.side_effect = Exception()
# WHEN: setup_desktop() is called # WHEN: the desktop property is called
server.setup_desktop() server.desktop
# THEN: A desktop object was created # THEN: A desktop object was created
mocked_uno.getComponentContext.assert_called_once_with() mocked_uno.getComponentContext.assert_called_once_with()
mocked_context.ServiceManager.createInstanceWithContext.assert_called_once_with( mocked_context.ServiceManager.createInstanceWithContext.assert_called_once_with(
'com.sun.star.bridge.UnoUrlResolver', mocked_context) 'com.sun.star.bridge.UnoUrlResolver', mocked_context)
expected_calls = [ expected_calls = [
call('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext'), call('uno:pipe,name=openlp_maclo;urp;StarOffice.ComponentContext'),
call('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext') call('uno:pipe,name=openlp_maclo;urp;StarOffice.ComponentContext')
] ]
assert mocked_resolver.resolve.call_args_list == expected_calls assert mocked_resolver.resolve.call_args_list == expected_calls
MockedServiceManager.createInstanceWithContext.assert_called_once_with( MockedServiceManager.createInstanceWithContext.assert_called_once_with(
@ -121,7 +122,7 @@ def test_setup_desktop_exception(mocked_uno):
@patch('openlp.plugins.presentations.lib.libreofficeserver.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 Test that setting up the desktop works correctly
""" """
@ -138,16 +139,16 @@ def test_setup_desktop(mocked_uno):
mocked_uno_instance.ServiceManager = MockedServiceManager mocked_uno_instance.ServiceManager = MockedServiceManager
MockedServiceManager.createInstanceWithContext.return_value = mocked_desktop MockedServiceManager.createInstanceWithContext.return_value = mocked_desktop
# WHEN: setup_desktop() is called # WHEN: the desktop property is called
server.setup_desktop() server.desktop
# THEN: A desktop object was created # THEN: A desktop object was created
mocked_uno.getComponentContext.assert_called_once_with() mocked_uno.getComponentContext.assert_called_once_with()
mocked_context.ServiceManager.createInstanceWithContext.assert_called_once_with( mocked_context.ServiceManager.createInstanceWithContext.assert_called_once_with(
'com.sun.star.bridge.UnoUrlResolver', mocked_context) 'com.sun.star.bridge.UnoUrlResolver', mocked_context)
expected_calls = [ expected_calls = [
call('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext'), call('uno:pipe,name=openlp_maclo;urp;StarOffice.ComponentContext'),
call('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext') call('uno:pipe,name=openlp_maclo;urp;StarOffice.ComponentContext')
] ]
assert mocked_resolver.resolve.call_args_list == expected_calls assert mocked_resolver.resolve.call_args_list == expected_calls
MockedServiceManager.createInstanceWithContext.assert_called_once_with( MockedServiceManager.createInstanceWithContext.assert_called_once_with(
@ -257,35 +258,6 @@ def test_get_text_from_page_notes():
assert text == 'Page Notes\n' 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(): def test_shutdown_other_docs():
""" """
Test the shutdown method while other documents are open in LibreOffice Test the shutdown method while other documents are open in LibreOffice

View File

@ -160,21 +160,6 @@ class TestMacLODocument(TestCase):
self.controller._client = self.mocked_client self.controller._client = self.mocked_client
self.document = MacLODocument(self.controller, self.file_name) 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') @patch('openlp.plugins.presentations.lib.maclocontroller.ScreenList')
def test_load_presentation_cannot_load(self, MockedScreenList): def test_load_presentation_cannot_load(self, MockedScreenList):
""" """
@ -183,17 +168,14 @@ class TestMacLODocument(TestCase):
# GIVEN: A document and a mocked client # GIVEN: A document and a mocked client
mocked_screen_list = MagicMock() mocked_screen_list = MagicMock()
MockedScreenList.return_value = mocked_screen_list MockedScreenList.return_value = mocked_screen_list
mocked_screen_list.current = {'number': 0} mocked_screen_list.current.number = 0
self.mocked_client.has_desktop.return_value = True
self.mocked_client.load_presentation.return_value = False self.mocked_client.load_presentation.return_value = False
# WHEN: load_presentation() is called # WHEN: load_presentation() is called
result = self.document.load_presentation() result = self.document.load_presentation()
# THEN: Stuff should work right # THEN: Stuff should work right
self.mocked_client.setup_desktop.assert_called_once_with() self.mocked_client.load_presentation.assert_called_once_with(str(self.file_name), 1)
self.mocked_client.has_desktop.assert_called_once_with()
self.mocked_client.load_presentation.assert_called_once_with(self.file_name, 1)
assert result is False assert result is False
@patch('openlp.plugins.presentations.lib.maclocontroller.ScreenList') @patch('openlp.plugins.presentations.lib.maclocontroller.ScreenList')
@ -204,8 +186,7 @@ class TestMacLODocument(TestCase):
# GIVEN: A document and a mocked client # GIVEN: A document and a mocked client
mocked_screen_list = MagicMock() mocked_screen_list = MagicMock()
MockedScreenList.return_value = mocked_screen_list MockedScreenList.return_value = mocked_screen_list
mocked_screen_list.current = {'number': 0} mocked_screen_list.current.number = 0
self.mocked_client.has_desktop.return_value = True
self.mocked_client.load_presentation.return_value = True self.mocked_client.load_presentation.return_value = True
# WHEN: load_presentation() is called # WHEN: load_presentation() is called
@ -214,9 +195,7 @@ class TestMacLODocument(TestCase):
result = self.document.load_presentation() result = self.document.load_presentation()
# THEN: Stuff should work right # THEN: Stuff should work right
self.mocked_client.setup_desktop.assert_called_once_with() self.mocked_client.load_presentation.assert_called_once_with(str(self.file_name), 1)
self.mocked_client.has_desktop.assert_called_once_with()
self.mocked_client.load_presentation.assert_called_once_with(self.file_name, 1)
mocked_create_thumbnails.assert_called_once_with() mocked_create_thumbnails.assert_called_once_with()
mocked_create_titles_and_notes.assert_called_once_with() mocked_create_titles_and_notes.assert_called_once_with()
assert result is True assert result is True
@ -252,8 +231,8 @@ class TestMacLODocument(TestCase):
# THEN: The method should complete successfully # THEN: The method should complete successfully
self.mocked_client.extract_thumbnails.assert_called_once_with('temp') self.mocked_client.extract_thumbnails.assert_called_once_with('temp')
assert mocked_convert_thumbnail.call_args_list == [ assert mocked_convert_thumbnail.call_args_list == [
call('thumb1.png', 1), call('thumb2.png', 2)] call(Path('thumb1.png'), 1), call(Path('thumb2.png'), 2)]
assert mocked_delete_file.call_args_list == [call('thumb1.png'), call('thumb2.png')] assert mocked_delete_file.call_args_list == [call(Path('thumb1.png')), call(Path('thumb2.png'))]
def test_create_titles_and_notes(self): def test_create_titles_and_notes(self):
""" """
@ -370,6 +349,7 @@ class TestMacLODocument(TestCase):
""" """
# GIVEN: a mocked client, and multiple screens # GIVEN: a mocked client, and multiple screens
mocked_screen_list = MagicMock() mocked_screen_list = MagicMock()
mocked_screen_list.__len__.return_value = 2
mocked_registry = MagicMock() mocked_registry = MagicMock()
mocked_main_window = MagicMock() mocked_main_window = MagicMock()
MockedScreenList.return_value = mocked_screen_list MockedScreenList.return_value = mocked_screen_list