Пример #1
0
def test_matcher():
    cds_document_blob1 = {"003": "SzGeCERN", "690C_": [{"a": "BOOK"}]}
    springer_document_blob1 = {"003": "DE-He213"}
    safari_document_blob1 = {"003": "CaSebORM"}
    ebl_document_blob1 = {"003": "MiAaPQ"}
    assert cds_book.model == matcher(cds_document_blob1,
                                     "cds_ils.importer.models")
    assert springer.model == matcher(springer_document_blob1,
                                     "cds_ils.importer.models")
    assert safari.model == matcher(safari_document_blob1,
                                   "cds_ils.importer.models")
    assert ebl.model == matcher(ebl_document_blob1, "cds_ils.importer.models")
Пример #2
0
def test_marc21_matcher_books():
    """Test CDS DoJSON matcher - books."""
    book_blob1 = {"003": "SzGeCERN", "690C_": [{"a": "BOOK"}]}
    book_blob2 = {"003": "SzGeCERN", "980__": [{"a": "PROCEEDINGS"}]}
    book_blob3 = {"003": "SzGeCERN", "697C_": [{"a": "ENGLISH BOOK CLUB"}]}
    serial_blob1 = {
        "003": "SzGeCERN",
        "690C_": [{"a": "BOOK"}],
        "490__": {"a": "Test title"},
    }
    cds_blob2 = {
        "003": "SzGeCERN",
    }
    multipart_blob1 = {
        "003": "SzGeCERN",
        "690C_": [{"a": "BOOK"}],
        "245__": [{"a": "Test "}],
        "596__": [{"a": "MULTIVOLUMES"}],
        "246__": [{"p": "Volume Title", "n": "2"}],
    }
    multipart_blob2 = {
        "003": "SzGeCERN",
        "690C_": [{"a": "BOOK"}],
        "245__": [{"a": "Test "}],
        "246__": [{"n": "2"}],
        "596__": [{"a": "MULTIVOLUMES"}],
    }
    standard_blob1 = {"003": "SzGeCERN", "690C_": [{"a": "STANDARD"}]}
    journal_blob = {"003": "SzGeCERN", "980__": [{"a": "PERI"}]}
    not_match = {"foo": "bar"}

    models_entrypoint = "cds_ils.importer.models"
    series_models_entrypoint = "cds_ils.importer.series_models"
    assert book.model == matcher(book_blob1, models_entrypoint)
    assert book.model == matcher(book_blob2, models_entrypoint)

    with pytest.raises(AssertionError):
        # English book club should not be matched
        assert book.model == matcher(book_blob3, models_entrypoint)
    assert standard.model == matcher(standard_blob1, models_entrypoint)
    assert serial.model == matcher(serial_blob1, series_models_entrypoint)
    assert multipart.model == matcher(
        multipart_blob1, series_models_entrypoint
    )
    assert multipart.model == matcher(
        multipart_blob2, series_models_entrypoint
    )
    assert journal.model == matcher(journal_blob, series_models_entrypoint)
    # make sure that it won't match with any CDS record
    assert default.model == matcher(cds_blob2, models_entrypoint)
    assert default.model == matcher(not_match, models_entrypoint)
Пример #3
0
def test_marc21_matcher():
    """Test CDS DoJSON matcher."""
    album_blob = {'999__': {'a': 'ALBUM'}}
    cern_blob = {'690C_': {'a': 'CERN'}}
    duplicated_blob = {'999__': [{'a': 'IMAGE'}, {'a': 'ALBUM'}]}
    image_blob = {'999__': {'a': 'IMAGE'}}
    no_match_blob = {'000__': {'z': 'odd'}}
    video_blob = {'999__': {'a': 'PUBLVIDEOMOVIE'}}

    assert album.model == matcher(album_blob, 'cds_dojson.marc21.models')
    assert default.model == matcher(cern_blob, 'cds_dojson.marc21.models')
    assert default.model == matcher(
        duplicated_blob, 'cds_dojson.marc21.models')
    assert default.model == matcher(no_match_blob, 'cds_dojson.marc21.models')
    assert image.model == matcher(image_blob, 'cds_dojson.marc21.models')
Пример #4
0
def test_video_clip(app):
    """Test video clip loading from XML."""
    with app.app_context():
        blob = create_record(CDS_VIDEO_CLIP)
        model = matcher(blob, 'cds_dojson.marc21.models')

        assert model == marc21

        data = model.do(blob)

        assert len(data.get('creation_production_credits_note')) == 3
        # It is a tuple and not a list because it is not dump to JSON
        assert data[
            'host_item_entry'][0]['report_number'] == ("CERN-MOVIE-2015-038", )
        expected_physical_description = [
            {
                "accompanying_material": "16:9",
                "other_physical_details": "1920x1080 16/9, 25.00",
                "dimensions": ("25", ),
                "extent": ("00:09:05.280", ),
                "maximum_resolution": "1920x1080",
            }
        ]
        assert data.get(
            'physical_description') == expected_physical_description

        # Check that no fields are missing their model
        assert model.missing(blob) == []
def test_jsonschema(app):
    """Test jsonschema."""
    with app.app_context():
        blob = create_record(RECORD_SIMPLE)
        model = matcher(blob, 'cds_dojson.marc21.models')
        data = model.do(blob)

        assert '$schema' in data
        assert data['$schema'] == {
            '$ref': 'records/default-v1.0.0.json'}
Пример #6
0
def test_jsonschema(app):
    """Test jsonschema."""
    with app.app_context():
        blob = create_record(CDS_VIDEO_PROJECT)
        model = matcher(blob, 'cds_dojson.marc21.models')
        data = model.do(blob)

        assert '$schema' in data
        assert data['$schema'] == {
            '$ref': 'records/video-v1.0.0.json'}

        blob = create_record(CDS_VIDEO_CLIP)
        model = matcher(blob, 'cds_dojson.marc21.models')
        data = model.do(blob)

        assert '$schema' in data
        assert data['$schema'] == {
            '$ref': 'records/video-v1.0.0.json'}

        schema = {
            '$ref': 'http://cdslabs.cern.ch/schemas/records/video-v1.0.0.json'}
        resolver = json_resolver(schema)
        with pytest.raises(ValidationError) as exc_info:
            validate({'$schema': schema}, schema, resolver=resolver)
Пример #7
0
def test_video_project():
    """Test video project from XML."""
    blob = create_record(CDS_VIDEO_PROJECT)
    model = matcher(blob, 'cds_dojson.marc21.models')

    assert model == marc21

    data = model.do(blob)

    assert data['constituent_unit_entry'][0][
        'report_number'] == ['CERN-MOVIE-2015-038-001']
    assert data.get('control_number') == '2053119'

    # Check that no fields are missing their model
    assert model.missing(blob) == []
Пример #8
0
def test_video_project():
    """Test video project from XML."""
    blob = create_record(CDS_VIDEO_PROJECT)
    model = matcher(blob, 'cds_dojson.marc21.models')

    assert model == marc21

    data = model.do(blob)

    assert data['constituent_unit_entry'][0]['report_number'] == [
        'CERN-MOVIE-2015-038-001'
    ]
    assert data.get('control_number') == '2053119'

    # Check that no fields are missing their model
    assert model.missing(blob) == []
Пример #9
0
def test_album():
    """Test album model from XML into JSON"""
    blob = create_record(CDS_ALBUM)
    model = matcher(blob, 'cds_dojson.marc21.models')

    assert model == marc21

    data = model.do(blob)

    assert data['physical_medium'][1][
        'material_base_and_configuration'] == ['Neg NB 6 x 6']
    assert data['images'][3]['$ref'] == 'http://cds.cern.ch/record/1782448'
    assert data['images'][3]['relation'] == 'Cover'
    assert data['imprint'][0]['complete_date'] == 'Sep 1970'
    assert data['place_of_photo'] == [
        {'place': 'CERN PS', 'requester': 'PHILIPPS'}]

    # Check that no fields are missing their model
    assert model.missing(blob) == []
Пример #10
0
def test_image():
    """Test image model from XML into JSONi."""
    blob = create_record(CDS_IMAGE)
    model = matcher(blob, 'cds_dojson.marc21.models')

    assert model == marc21

    data = model.do(blob)
    # Check the control number (doJSON)
    assert data.get('control_number') == '1782445'

    # Check the parent album (CDSImage)
    assert data['album_parent'][0]['album_id'] == '2054964'

    # Check the imprint (CDSMarc21)
    assert data['imprint'][0]['place_of_publication'] == 'Geneva'

    # Check that no fields are missing their model
    assert model.missing(blob) == []
Пример #11
0
def test_image():
    """Test image model from XML into JSONi."""
    blob = create_record(CDS_IMAGE)
    model = matcher(blob, 'cds_dojson.marc21.models')

    assert model == marc21

    data = model.do(blob)
    # Check the control number (doJSON)
    assert data.get('control_number') == '1782445'

    # Check the parent album (CDSImage)
    assert data['album_parent'][0]['album_id'] == '2054964'

    # Check the imprint (CDSMarc21)
    assert data['imprint'][0]['place_of_publication'] == 'Geneva'

    # Check that no fields are missing their model
    assert model.missing(blob) == []
Пример #12
0
def test_marc21_matcher():
    """Test CDS DoJSON matcher."""
    video_blob1 = {'980__': [{'a': 'PUBLVIDEOMOVIE'}, {'b': 'VIDEOMEDIALAB'}]}
    video_blob2 = {'980__': [{'a': 'PUBLVIDEOMOVIE'}, {'c': 'DELETED'}]}
    video_blob3 = {'980__': {'a': 'VIDEOARC'}}
    video_blob4 = {'980__': {'a': 'CERNVIDEOSHOOT'}}
    video_blob5 = {
        '980__': [{
            'a': 'PUBLVIDEOMOVIE'
        }, {
            'b': 'VIDEOMEDIALAB'
        }],
        '970__': {
            'a': 'AVW.project.1234'
        }
    }
    video_blob6 = {
        '980__': [{
            'a': 'PUBLVIDEOMOVIE'
        }, {
            'c': 'DELETED'
        }],
        '970__': {
            'a': 'AVW.project.1234'
        }
    }
    video_blob7 = {'970__': {'a': 'FCS.project.987'}}
    not_match = {'foo': 'bar'}

    assert video.model == matcher(video_blob1, 'cds_dojson.marc21.models')
    assert default.model == matcher(video_blob2, 'cds_dojson.marc21.models')
    assert default.model == matcher(video_blob3, 'cds_dojson.marc21.models')
    assert default.model == matcher(video_blob4, 'cds_dojson.marc21.models')
    assert project.model == matcher(video_blob5, 'cds_dojson.marc21.models')
    assert default.model == matcher(video_blob6, 'cds_dojson.marc21.models')
    assert project.model == matcher(video_blob7, 'cds_dojson.marc21.models')
    assert default.model == matcher(not_match, 'cds_dojson.marc21.models')
Пример #13
0
def test_album():
    """Test album model from XML into JSON"""
    blob = create_record(CDS_ALBUM)
    model = matcher(blob, 'cds_dojson.marc21.models')

    assert model == marc21

    data = model.do(blob)

    assert data['physical_medium'][1]['material_base_and_configuration'] == [
        'Neg NB 6 x 6'
    ]
    assert data['images'][3]['$ref'] == 'http://cds.cern.ch/record/1782448'
    assert data['images'][3]['relation'] == 'Cover'
    assert data['imprint'][0]['complete_date'] == 'Sep 1970'
    assert data['place_of_photo'] == [{
        'place': 'CERN PS',
        'requester': 'PHILIPPS'
    }]

    # Check that no fields are missing their model
    assert model.missing(blob) == []
Пример #14
0
def test_video_clip():
    """Test video clip loading from XML."""
    blob = create_record(CDS_VIDEO_CLIP)
    model = matcher(blob, 'cds_dojson.marc21.models')

    assert model == marc21

    data = model.do(blob)

    assert len(data.get('creation_production_credits_note')) == 3
    assert data['host_item_entry'][0]['report_number'] == [
        "CERN-MOVIE-2015-038"
    ]
    expected_physical_description = [{
        "accompanying_material": "16:9",
        "other_physical_details": "1920x1080 16/9, 25.00",
        "dimensions": ["25"],
        "extent": ["00:09:05.280"],
        "maximum_resolution": "1920x1080",
    }]
    assert data.get('physical_description') == expected_physical_description

    # Check that no fields are missing their model
    assert model.missing(blob) == []