def test_transform_harvested_records(app, bucket_location,
                                     without_oaiset_signals, capsys):
    """Test harvested record transformation."""
    request, records = get_records(
        ['oai:doc.rero.ch:20120503160026-MV'],
        metadata_prefix='marcxml',
        url='http://doc.rero.ch/oai2d',
    )

    transform_harvested_records(None, records, **{
        'name': 'rerodoc',
        'max': '1'
    })
    captured = capsys.readouterr()
    assert captured.out.find('1 records harvested') != -1

    # Max set to 0 --> import all
    transform_harvested_records(None, records, **{
        'name': 'rerodoc',
        'max': '0'
    })
    captured = capsys.readouterr()
    assert captured.out.find('1 records harvested') != -1

    # Not an import
    transform_harvested_records(
        None, records, **{
            'name': 'rerodoc',
            'max': '1',
            'action': 'not-existing'
        })
    captured = capsys.readouterr()
    assert captured.out == ''
def test_transform_harvested_records(app, bucket_location,
                                     without_oaiset_signals):
    """Test harvested record transformation."""
    request, records = get_records(
        ['oai:doc.rero.ch:20120503160026-MV'],
        metadata_prefix="marcxml",
        url='http://doc.rero.ch/oai2d',
    )

    transform_harvested_records(None, records, **{'name': 'test', 'max': 1})
def test_export_json(app, bucket_location, monkeypatch):
    """Test export records to file."""
    # Patch the file upload to webdav.
    monkeypatch.setattr('webdav3.client.Client.upload_file',
                        lambda *args: True)

    request, records = get_records(
        ['oai:doc.rero.ch:20120503160026-MV'],
        metadata_prefix='marcxml',
        url='http://doc.rero.ch/oai2d',
    )

    data_directory = join(app.instance_path, 'data')

    export_json(None, records, **{'name': 'rerodoc', 'action': 'not-existing'})
    assert not exists(data_directory)

    export_json(None, records, **{'name': 'rerodoc', 'action': 'export'})
    assert len(listdir(data_directory)) == 1