示例#1
0
def test_extract_thumbnails_no_pages(mocked_uno):
    """
    Test the extract_thumbnails() method when there are no pages
    """
    # GIVEN: A LibreOfficeServer instance
    temp_folder = '/tmp'
    server = LibreOfficeServer()
    mocked_document = MagicMock()
    server._document = mocked_document
    mocked_uno.systemPathToFileUrl.side_effect = lambda x: x
    mocked_document.getDrawPages.return_value = None

    # WHEN: The extract_thumbnails() method is called
    with patch.object(server, '_create_property') as mocked_create_property:
        mocked_create_property.side_effect = lambda x, y: {x: y}
        thumbnails = server.extract_thumbnails(temp_folder)

    # THEN: Thumbnails have been extracted
    mocked_uno.systemPathToFileUrl.assert_called_once_with(temp_folder)
    mocked_create_property.assert_called_once_with('FilterName', 'impress_png_Export')
    mocked_document.getDrawPages.assert_called_once_with()
    assert thumbnails == []
示例#2
0
def test_extract_thumbnails(mocked_os, mocked_uno):
    """
    Test the extract_thumbnails() method
    """
    # GIVEN: A LibreOfficeServer instance
    temp_folder = '/tmp'
    server = LibreOfficeServer()
    mocked_document = MagicMock()
    mocked_pages = MagicMock()
    mocked_page_1 = MagicMock()
    mocked_page_2 = MagicMock()
    mocked_controller = MagicMock()
    server._document = mocked_document
    mocked_uno.systemPathToFileUrl.side_effect = lambda x: x
    mocked_document.getDrawPages.return_value = mocked_pages
    mocked_os.path.isdir.return_value = False
    mocked_pages.getCount.return_value = 2
    mocked_pages.getByIndex.side_effect = [mocked_page_1, mocked_page_2]
    mocked_document.getCurrentController.return_value = mocked_controller
    mocked_os.path.join.side_effect = lambda *x: '/'.join(x)

    # WHEN: The extract_thumbnails() method is called
    with patch.object(server, '_create_property') as mocked_create_property:
        mocked_create_property.side_effect = lambda x, y: {x: y}
        thumbnails = server.extract_thumbnails(temp_folder)

    # THEN: Thumbnails have been extracted
    mocked_uno.systemPathToFileUrl.assert_called_once_with(temp_folder)
    mocked_create_property.assert_called_once_with('FilterName', 'impress_png_Export')
    mocked_document.getDrawPages.assert_called_once_with()
    mocked_pages.getCount.assert_called_once_with()
    assert mocked_pages.getByIndex.call_args_list == [call(0), call(1)]
    assert mocked_controller.setCurrentPage.call_args_list == \
        [call(mocked_page_1), call(mocked_page_2)]
    assert mocked_document.storeToURL.call_args_list == \
        [call('/tmp/1.png', ({'FilterName': 'impress_png_Export'},)),
         call('/tmp/2.png', ({'FilterName': 'impress_png_Export'},))]
    assert thumbnails == ['/tmp/1.png', '/tmp/2.png']