Exemple #1
0
def test_cli_do_marc21_from_xml():
    """Test MARC21 loading from XML."""
    expected = [{
        "__order__": ["main_entry_personal_name"],
        "main_entry_personal_name": {
            "__order__": ["personal_name"],
            "personal_name": "Donges, Jonathan F",
        },
    }]

    runner = CliRunner()
    with runner.isolated_filesystem():
        with open("record.xml", "wb") as f:
            f.write(RECORD_SIMPLE.encode("utf-8"))

        result = runner.invoke(
            cli.cli,
            ["-i", "record.xml", "-l", "marcxml", "missing", "marc21"])
        assert "" == result.output
        assert 0 == result.exit_code

        result = runner.invoke(
            cli.cli, ["-i", "record.xml", "-l", "marcxml", "do", "marc21"])

        try:
            data = json.loads(result.output)
            assert expected == data
        except ValueError:
            assert False, result.output

        result = runner.invoke(
            cli.cli,
            ["-i", "record.xml", "-l", "marcxml", "do", "--strict", "marc21"])
        assert 0 == result.exit_code
Exemple #2
0
def test_cli_do_marc21_from_xml():
    """Test MARC21 loading from XML."""
    expected = [{
        '__order__': ['main_entry_personal_name'],
        'main_entry_personal_name': {
            '__order__': ['personal_name'],
            'personal_name': 'Donges, Jonathan F',
        }
    }]

    runner = CliRunner()
    with runner.isolated_filesystem():
        with open('record.xml', 'wb') as f:
            f.write(RECORD_SIMPLE.encode('utf-8'))

        result = runner.invoke(
            cli.cli,
            ['-i', 'record.xml', '-l', 'marcxml', 'missing', 'marc21'])
        assert '' == result.output
        assert 0 == result.exit_code

        result = runner.invoke(
            cli.cli, ['-i', 'record.xml', '-l', 'marcxml', 'do', 'marc21'])

        try:
            data = json.loads(result.output)
            assert expected == data
        except ValueError:
            assert False, result.output

        result = runner.invoke(
            cli.cli,
            ['-i', 'record.xml', '-l', 'marcxml', 'do', '--strict', 'marc21'])
        assert 0 == result.exit_code
def test_xslt_not_found():
    """Test xslt not found."""
    runner = CliRunner()
    with runner.isolated_filesystem():
        with open('record.xml', 'wb') as f:
            f.write(RECORD_SIMPLE.encode('utf-8'))
        data = list(load('record.xml'))
        pytest.raises(IOError, dumps, data, xslt_filename='file_not_exist')
def test_xslt_not_found():
    """Test xslt not found."""
    runner = CliRunner()
    with runner.isolated_filesystem():
        with open('record.xml', 'wb') as f:
            f.write(RECORD_SIMPLE.encode('utf-8'))
        data = list(load('record.xml'))
        pytest.raises(IOError, dumps, data, xslt_filename='file_not_exist')
Exemple #5
0
def test_xslt_not_found():
    """Test xslt not found."""
    runner = CliRunner()
    with runner.isolated_filesystem():
        with open("record.xml", "wb") as f:
            f.write(RECORD_SIMPLE.encode("utf-8"))
        data = list(load("record.xml"))
        pytest.raises(IOError, dumps, data, xslt_filename="file_not_exist")
Exemple #6
0
def test_cli_do_marc21_from_xml():
    """Test MARC21 loading from XML."""
    from dojson import cli
    from test_core import RECORD_SIMPLE, RECORD_999_FIELD

    expected = [{'main_entry_personal_name': {'personal_name': 'Donges, Jonathan F'}}]
    runner = CliRunner()

    with runner.isolated_filesystem():
        with open('record.xml', 'wb') as f:
            f.write(RECORD_SIMPLE.encode('utf-8'))

        with open('record_999.xml', 'wb') as f:
            f.write(RECORD_999_FIELD.encode('utf-8'))

        result = runner.invoke(
            cli.missing_fields,
            ['-i', 'record.xml', '-l', 'marcxml', 'marc21']
        )
        assert result.output == ''
        assert result.exit_code == 0

        result = runner.invoke(
            cli.missing_fields,
            ['-i', 'record_999.xml', '-l', 'marcxml', 'marc21']
        )
        assert result.output == '999__\n'
        assert result.exit_code == 1

        result = runner.invoke(
            cli.apply_rule,
            ['-i', 'record.xml', '-l', 'marcxml', 'marc21']
        )
        data = json.loads(result.output)
        assert expected == data

        result = runner.invoke(
            cli.apply_rule,
            ['-i', 'record_999.xml', '-l', 'marcxml', 'marc21']
        )
        data = json.loads(result.output)
        assert {} == data[0]
        assert result.exit_code == 0

        result = runner.invoke(
            cli.apply_rule,
            ['-i', 'record.xml', '-l', 'marcxml', '--strict', 'marc21']
        )
        assert result.exit_code == -1
Exemple #7
0
def test_cli_do_marc21_from_xml():
    """Test MARC21 loading from XML."""
    expected = [{
        '__order__': ['main_entry_personal_name'],
        'main_entry_personal_name': [
            {
                '__order__': ['personal_name'],
                'personal_name': 'Donges, Jonathan F',
            }
        ],
    }]

    runner = CliRunner()
    with runner.isolated_filesystem():
        with open('record.xml', 'wb') as f:
            f.write(RECORD_SIMPLE.encode('utf-8'))

        result = runner.invoke(
            cli.cli,
            ['-i', 'record.xml', '-l', 'marcxml', 'missing', 'marc21']
        )
        assert '' == result.output
        assert 0 == result.exit_code

        result = runner.invoke(
            cli.cli,
            ['-i', 'record.xml', '-l', 'marcxml', 'do', 'marc21']
        )

        try:
            data = json.loads(result.output)
            assert expected == data
        except ValueError:
            assert False, result.output

        result = runner.invoke(
            cli.cli,
            ['-i', 'record.xml', '-l', 'marcxml', 'do', '--strict', 'marc21']
        )
        assert 0 == result.exit_code