예제 #1
0
def test_start_presentation_no_control(mocked_sleep):
    """
    Test the start_presentation() method when there's no control
    """
    # GIVEN: A LibreOfficeServer instance and some mocks
    server = LibreOfficeServer()
    mocked_control = MagicMock()
    mocked_document = MagicMock()
    mocked_presentation = MagicMock()
    mocked_controller = MagicMock()
    mocked_frame = MagicMock()
    mocked_window = MagicMock()
    server._document = mocked_document
    server._presentation = mocked_presentation
    mocked_document.getCurrentController.return_value = mocked_controller
    mocked_controller.getFrame.return_value = mocked_frame
    mocked_frame.getContainerWindow.return_value = mocked_window
    mocked_presentation.getController.side_effect = [None, mocked_control]

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

    # THEN: The slide number should be correct
    mocked_document.getCurrentController.assert_called_once_with()
    mocked_controller.getFrame.assert_called_once_with()
    mocked_frame.getContainerWindow.assert_called_once_with()
    mocked_presentation.start.assert_called_once_with()
    assert mocked_presentation.getController.call_count == 2
    mocked_sleep.assert_called_once_with(0.1)
    assert mocked_window.setVisible.call_args_list == [call(True), call(False)]
    assert server._control is mocked_control
예제 #2
0
def test_stop_presentation():
    """
    Test the stop_presentation() method
    """
    # GIVEN: A LibreOfficeServer instance and a mocked presentation
    server = LibreOfficeServer()
    mocked_presentation = MagicMock()
    mocked_control = MagicMock()
    server._presentation = mocked_presentation
    server._control = mocked_control

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

    # THEN: The presentation is ended and the control is removed
    mocked_presentation.end.assert_called_once_with()
    assert server._control is None
예제 #3
0
def test_is_loaded_no_presentation():
    """
    Test the is_loaded() method when there's no presentation
    """
    # GIVEN: A LibreOfficeServer instance and a bunch of mocks
    server = LibreOfficeServer()
    mocked_document = MagicMock()
    server._document = mocked_document
    server._presentation = MagicMock()
    mocked_document.getPresentation.return_value = None

    # WHEN: The is_loaded() method is called
    result = server.is_loaded()

    # THEN: The result should be false
    assert result is False
    mocked_document.getPresentation.assert_called_once_with()
예제 #4
0
def test_is_loaded_exception():
    """
    Test the is_loaded() method when an exception is thrown
    """
    # GIVEN: A LibreOfficeServer instance and a bunch of mocks
    server = LibreOfficeServer()
    mocked_document = MagicMock()
    server._document = mocked_document
    server._presentation = MagicMock()
    mocked_document.getPresentation.side_effect = Exception()

    # WHEN: The is_loaded() method is called
    result = server.is_loaded()

    # THEN: The result should be false
    assert result is False
    mocked_document.getPresentation.assert_called_once_with()
예제 #5
0
def test_close_presentation():
    """
    Test that closing the presentation cleans things up correctly
    """
    # GIVEN: A LibreOfficeServer instance and a bunch of mocks
    server = LibreOfficeServer()
    mocked_document = MagicMock()
    mocked_presentation = MagicMock()
    server._document = mocked_document
    server._presentation = mocked_presentation

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

    # THEN: The presentation and document should be closed
    mocked_presentation.end.assert_called_once_with()
    mocked_document.dispose.assert_called_once_with()
    assert server._document is None
    assert server._presentation is None