示例#1
0
def test_load_presentation(mocked_uno):
    """
    Test the load_presentation() method
    """
    # GIVEN: A LibreOfficeServer object
    presentation_file = '/path/to/presentation.odp'
    screen_number = 1
    server = LibreOfficeServer()
    mocked_desktop = MagicMock()
    mocked_document = MagicMock()
    mocked_presentation = MagicMock()
    mocked_uno.systemPathToFileUrl.side_effect = lambda x: x
    server._desktop = mocked_desktop
    mocked_desktop.loadComponentFromURL.return_value = mocked_document
    mocked_document.getPresentation.return_value = mocked_presentation

    # WHEN: load_presentation() is called
    with patch.object(server, '_create_property') as mocked_create_property:
        mocked_create_property.side_effect = lambda x, y: {x: y}
        result = server.load_presentation(presentation_file, screen_number)

    # THEN: A presentation is loaded
    assert result is True
    mocked_uno.systemPathToFileUrl.assert_called_once_with(presentation_file)
    mocked_create_property.assert_called_once_with('Hidden', True)
    mocked_desktop.loadComponentFromURL.assert_called_once_with(
        presentation_file, '_blank', 0, ({'Hidden': True},))
    assert server._document is mocked_document
    mocked_document.getPresentation.assert_called_once_with()
    assert server._presentation is mocked_presentation
    assert server._presentation.Display == screen_number
    assert server._control is None
示例#2
0
def test_desktop_already_has_desktop(mocked_uno):
    """
    Test that setup_desktop() exits early when there's already a desktop
    """
    # GIVEN: A LibreOfficeServer instance
    server = LibreOfficeServer()
    server._desktop = MagicMock()

    # WHEN: the desktop property is called
    desktop = server.desktop

    # THEN: setup_desktop() exits early
    assert desktop is server._desktop
    assert server._manager is None
示例#3
0
def test_load_presentation_exception(mocked_uno):
    """
    Test the load_presentation() method when an exception occurs
    """
    # GIVEN: A LibreOfficeServer object
    presentation_file = '/path/to/presentation.odp'
    screen_number = 1
    server = LibreOfficeServer()
    mocked_desktop = MagicMock()
    mocked_uno.systemPathToFileUrl.side_effect = lambda x: x
    server._desktop = mocked_desktop
    mocked_desktop.loadComponentFromURL.side_effect = Exception()

    # WHEN: load_presentation() is called
    with patch.object(server, '_create_property') as mocked_create_property:
        mocked_create_property.side_effect = lambda x, y: {x: y}
        result = server.load_presentation(presentation_file, screen_number)

    # THEN: A presentation is loaded
    assert result is False
示例#4
0
def test_shutdown_other_docs():
    """
    Test the shutdown method while other documents are open in LibreOffice
    """
    def close_docs():
        server._docs = []

    # GIVEN: An up an running LibreOfficeServer
    server = LibreOfficeServer()
    mocked_doc = MagicMock()
    mocked_desktop = MagicMock()
    mocked_docs = MagicMock()
    mocked_list = MagicMock()
    mocked_element_doc = MagicMock()
    server._docs = [mocked_doc]
    server._desktop = mocked_desktop
    server._process = MagicMock()
    mocked_doc.close_presentation.side_effect = close_docs
    mocked_desktop.getComponents.return_value = mocked_docs
    mocked_docs.hasElements.return_value = True
    mocked_docs.createEnumeration.return_value = mocked_list
    mocked_list.hasMoreElements.side_effect = [True, False]
    mocked_list.nextElement.return_value = mocked_element_doc
    mocked_element_doc.getImplementationName.side_effect = [
        'org.openlp.Nothing',
        'com.sun.star.comp.framework.BackingComp'
    ]

    # WHEN: shutdown() is called
    server.shutdown()

    # THEN: The right methods are called and everything works
    mocked_doc.close_presentation.assert_called_once_with()
    mocked_desktop.getComponents.assert_called_once_with()
    mocked_docs.hasElements.assert_called_once_with()
    mocked_docs.createEnumeration.assert_called_once_with()
    assert mocked_list.hasMoreElements.call_count == 2
    mocked_list.nextElement.assert_called_once_with()
    mocked_element_doc.getImplementationName.assert_called_once_with()
    assert mocked_desktop.terminate.call_count == 0
    assert server._process.kill.call_count == 0