Ejemplo n.º 1
0
def test_initial_task(monkeypatch):
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        workflow = wf.CaptureOneBatchToHathiComplete()
    user_args = {
        "Source": "./some_real_source_folder",
        "Destination": "./some_real_folder/",
        "Identifier type": "MMS ID"
    }

    mock_builder = Mock()
    workflow.initial_task(task_builder=mock_builder, **user_args)
    created_task = mock_builder.add_subtask.call_args[0][0]
    created_task.log = Mock()

    number_of_fake_files = 20

    def mock_scandir(path):
        for i_number in range(number_of_fake_files):
            file_mock = Mock()
            file_mock.name = f"99423682912205899_{str(i_number).zfill(8)}.tif"
            yield file_mock

    with monkeypatch.context() as mp:
        mp.setattr(os, "scandir", mock_scandir)
        created_task.work()
    assert len(created_task.results) == 1 and \
           len(created_task.results[0].items) == number_of_fake_files
Ejemplo n.º 2
0
def test_hathi_limited_to_dl_compound_has_options(index, label):
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        workflow = wf.CaptureOneBatchToHathiComplete()
    user_options = workflow.user_options()
    assert len(user_options) > 0
    assert user_options[index].label_text == label
Ejemplo n.º 3
0
def unconfigured_workflow():
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        workflow = wf.CaptureOneBatchToHathiComplete(
            global_settings={"getmarc_server_url": "http://fake.com"})
    user_options = {i.label_text: i.data for i in workflow.user_options()}

    return workflow, user_options
Ejemplo n.º 4
0
def test_initial_task_creates_task():
    workflow = wf.CaptureOneBatchToHathiComplete()
    user_args = {
        "Source": "./some_real_source_folder",
        "Destination": "./some_real_folder/",
        "Identifier type": "Bibid"
    }

    mock_builder = Mock()
    workflow.initial_task(task_builder=mock_builder, **user_args)
    assert \
        mock_builder.add_subtask.called is True and \
        mock_builder.add_subtask.call_args[0][0]._root == user_args['Source']
Ejemplo n.º 5
0
def test_get_additional_info(qtbot, monkeypatch):
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        workflow = wf.CaptureOneBatchToHathiComplete()
    mock_package = MagicMock()
    mock_data = {
        "ID": "99423682912205899",
        "ITEM_NAME": "",
        "TITLE_PAGE": "99423682912205899_0001.tif",
        "PATH": "/some/random/path/"
    }

    def mock_get_item(obj, key):
        return mock_data.get(key.name, str(key))

    mock_package.metadata.__getitem__ = mock_get_item
    mock_package.__len__ = lambda x: 1

    pretask_result = speedwagon.tasks.Result(
        source=wf.FindCaptureOnePackageTask, data=[mock_package])

    def patched_package_browser(packages, parent):
        patched_browser = \
            speedwagon.workflows.title_page_selection.PackageBrowser(
                packages, parent
            )

        patched_browser.exec = Mock()
        patched_browser.result = Mock(return_value=patched_browser.Accepted)
        data = MagicMock()
        data.metadata = MagicMock()

        data.metadata.__getitem__ = \
            lambda _, k: mock_data.get(k.name, str(k))

        patched_browser.data = Mock(return_value=[data])
        return patched_browser

    with monkeypatch.context() as mp:
        mp.setattr(wf, "PackageBrowser", patched_package_browser)

        extra_data = workflow.get_additional_info(
            parent=None, options={}, pretask_results=[pretask_result])

    assert extra_data['title_pages']['99423682912205899'] == \
           "99423682912205899_0001.tif"

    assert isinstance(extra_data, dict)
Ejemplo n.º 6
0
def test_hathi_limited_to_dl_compound_has_options(index, label):
    workflow = wf.CaptureOneBatchToHathiComplete()
    user_options = workflow.user_options()
    assert len(user_options) > 0
    assert user_options[index].label_text == label