def test_schema_class_resolver():
    """Test the Marshmallow schema class based on different resource types."""
    for type_, subtype, schema_class in SCHEMA_ORG_TYPES:
        obj = {'metadata': {'resource_type': {'type': type_}}}
        if subtype:
            obj['metadata']['resource_type']['subtype'] = subtype
        cls = ZenodoSchemaOrgSerializer._get_schema_class(obj)
        assert schema_class == cls
def test_schema_class_resolver():
    """Test the Marshmallow schema class based on different resource types."""
    for type_, subtype, schema_class in SCHEMA_ORG_TYPES:
        obj = {'metadata': {'resource_type': {'type': type_}}}
        if subtype:
            obj['metadata']['resource_type']['subtype'] = subtype
        cls = ZenodoSchemaOrgSerializer._get_schema_class(obj)
        assert schema_class == cls
def test_full_record(record_with_files_creation):
    """Test the full record model dumping."""
    recid, record, _ = record_with_files_creation
    # full_record fixture is a "book"
    schema_cls = ZenodoSchemaOrgSerializer._get_schema_class(
        dict(metadata=record))
    assert schema_cls == schemaorg.Book
    data, err = schemaorg.ScholarlyArticle().dump(dict(metadata=record))
    assert not err
    expected = {
        u'@context':
        u'https://schema.org/',
        u'@id':
        'https://doi.org/10.1234/foo.bar',
        u'@type':
        u'Book',
        u'identifier':
        'https://doi.org/10.1234/foo.bar',
        u'about': [{
            u'@id': u'http://id.loc.gov/authorities/subjects/sh85009003',
            u'@type': u'CreativeWork'
        }],
        u'citation': [{
            u'@id': 'https://doi.org/10.1234/foo.bar',
            u'@type': u'CreativeWork'
        }, {
            u'@id': 'http://arxiv.org/abs/arXiv:1234.4321',
            u'@type': u'CreativeWork'
        }, {
            '@id': 'http://arxiv.org/abs/arXiv:1234.4328',
            '@type': 'CreativeWork'
        }],
        u'contributor': [{
            u'@id': 'https://orcid.org/0000-0002-1825-0097',
            u'@type': u'Person',
            u'affiliation': u'CERN',
            u'name': u'Smith, Other'
        }, {
            u'@type': u'Person',
            u'affiliation': u'',
            u'name': u'Hansen, Viggo'
        }, {
            u'@type': u'Person',
            u'affiliation': u'CERN',
            u'name': u'Kowalski, Manager'
        }],
        u'creator': [{
            u'@id': 'https://orcid.org/0000-0002-1694-233X',
            u'@type': u'Person',
            u'affiliation': u'CERN',
            u'name': u'Doe, John'
        }, {
            u'@id': 'https://orcid.org/0000-0002-1825-0097',
            u'@type': u'Person',
            u'affiliation': u'CERN',
            u'name': u'Doe, Jane'
        }, {
            u'@type': u'Person',
            u'affiliation': u'CERN',
            u'name': u'Smith, John'
        }, {
            u'@id': 'http://d-nb.info/gnd/170118215',
            u'@type': u'Person',
            u'affiliation': u'CERN',
            u'name': u'Nowak, Jack'
        }],
        u'datePublished':
        '2014-02-27',
        u'description':
        u'Test Description',
        u'headline':
        u'Test title',
        u'image':
        u'https://zenodo.org/static/img/logos/zenodo-gradient-round.svg',
        u'inLanguage': {
            u'@type': u'Language',
            u'alternateName': u'eng',
            u'name': u'English'
        },
        u'sameAs': [
            u'http://arxiv.org/abs/arXiv:1234.4325',
            u'http://adsabs.harvard.edu/abs/2011ApJS..192...18K',
            u'https://doi.org/10.1234/alternate.doi',
        ],
        u'isPartOf': [{
            u'@id': 'https://doi.org/10.1234/zenodo.4321',
            u'@type': u'CreativeWork'
        }],
        u'hasPart': [{
            u'@id': 'https://doi.org/10.1234/zenodo.1234',
            u'@type': u'CreativeWork'
        }],
        u'keywords': [u'kw1', u'kw2', u'kw3'],
        u'license':
        u'https://creativecommons.org/licenses/by/4.0/',
        u'name':
        u'Test title',
        u'url':
        u'http://localhost/record/12345',
        u'version':
        u'1.2.5'
    }
    assert data == expected
def test_full_record(record_with_files_creation):
    """Test the full record model dumping."""
    recid, record, _ = record_with_files_creation
    # full_record fixture is a "book"
    schema_cls = ZenodoSchemaOrgSerializer._get_schema_class(
        dict(metadata=record))
    assert schema_cls == schemaorg.Book
    data, err = schemaorg.ScholarlyArticle().dump(dict(metadata=record))
    assert not err
    expected = {
        u'@context': u'https://schema.org/',
        u'@id': 'https://doi.org/10.1234/foo.bar',
        u'@type': u'Book',
        u'identifier': 'https://doi.org/10.1234/foo.bar',
        u'about': [
            {
                u'@id': u'http://id.loc.gov/authorities/subjects/sh85009003',
                u'@type': u'CreativeWork'
            }
        ],
        u'citation': [
            {
                u'@id': 'https://doi.org/10.1234/foo.bar',
                u'@type': u'CreativeWork'
            },
            {
                u'@id': 'https://arxiv.org/abs/arXiv:1234.4321',
                u'@type': u'CreativeWork'
            },
            {
                '@id': 'https://arxiv.org/abs/arXiv:1234.4328',
                '@type': 'CreativeWork'
            }
        ],
        u'contributor': [
            {
                u'@id': 'https://orcid.org/0000-0002-1825-0097',
                u'@type': u'Person',
                u'affiliation': u'CERN',
                u'name': u'Smith, Other'
            },
            {
                u'@type': u'Person',
                u'affiliation': u'',
                u'name': u'Hansen, Viggo'
            },
            {
                u'@type': u'Person',
                u'affiliation': u'CERN',
                u'name': u'Kowalski, Manager'
            }
        ],
        u'creator': [
            {
                u'@id': 'https://orcid.org/0000-0002-1694-233X',
                u'@type': u'Person',
                u'affiliation': u'CERN',
                u'name': u'Doe, John'
            },
            {
                u'@id': 'https://orcid.org/0000-0002-1825-0097',
                u'@type': u'Person',
                u'affiliation': u'CERN',
                u'name': u'Doe, Jane'
            },
            {
                u'@type': u'Person',
                u'affiliation': u'CERN',
                u'name': u'Smith, John'
            },
            {
                u'@id': 'https://d-nb.info/gnd/170118215',
                u'@type': u'Person',
                u'affiliation': u'CERN',
                u'name': u'Nowak, Jack'
            }
        ],
        u'datePublished': '2014-02-27',
        u'description': u'Test Description',
        u'headline': u'Test title',
        u'image':
            u'https://zenodo.org/static/img/logos/zenodo-gradient-round.svg',
        u'inLanguage': {
            u'@type': u'Language',
            u'alternateName': u'eng',
            u'name': u'English'
        },
        u'sameAs': [
            u'https://arxiv.org/abs/arXiv:1234.4325',
            u'https://ui.adsabs.harvard.edu/#abs/2011ApJS..192...18K',
            u'https://doi.org/10.1234/alternate.doi',
        ],
        u'isPartOf': [
            {
                u'@id': 'https://doi.org/10.1234/zenodo.4321',
                u'@type': u'CreativeWork'
            }
        ],
        u'hasPart': [
            {
                u'@id': 'https://doi.org/10.1234/zenodo.1234',
                u'@type': u'CreativeWork'
            }
        ],
        u'keywords': [u'kw1', u'kw2', u'kw3'],
        u'license': u'https://creativecommons.org/licenses/by/4.0/',
        u'name': u'Test title',
        u'url': u'http://localhost/record/12345',
        u'version': u'1.2.5'
    }
    assert data == expected
Beispiel #5
0
def test_full_record(record_with_files_creation):
    """Test the full record model dumping."""
    recid, record, _ = record_with_files_creation
    # full_record fixture is a "book"
    schema_cls = ZenodoSchemaOrgSerializer._get_schema_class(
        dict(metadata=record))
    assert schema_cls == schemaorg.Book
    data, err = schemaorg.ScholarlyArticle().dump(dict(metadata=record))
    assert not err
    expected = {
        u'@context':
        u'https://schema.org/',
        u'@id':
        'https://doi.org/10.1234/foo.bar',
        u'@type':
        u'Book',
        u'identifier':
        'https://doi.org/10.1234/foo.bar',
        u'about': [{
            u'@id': u'http://id.loc.gov/authorities/subjects/sh85009003',
            u'@type': u'CreativeWork'
        }],
        u'citation': [{
            u'@id': 'https://doi.org/10.1234/foo.bar',
            u'@type': u'Dataset'
        }, {
            u'@id': 'https://arxiv.org/abs/arXiv:1234.4321',
            u'@type': u'Dataset'
        }, {
            '@id': 'https://arxiv.org/abs/arXiv:1234.4328',
            '@type': 'Dataset'
        }],
        u'contributor': [{
            u'@id': 'https://orcid.org/0000-0002-1825-0097',
            u'@type': u'Person',
            u'affiliation': u'CERN',
            u'name': u'Smith, Other'
        }, {
            u'@type': u'Person',
            u'affiliation': u'',
            u'name': u'Hansen, Viggo'
        }, {
            u'@type': u'Person',
            u'affiliation': u'CERN',
            u'name': u'Kowalski, Manager'
        }],
        u'creator': [{
            u'@id': 'https://orcid.org/0000-0002-1694-233X',
            u'@type': u'Person',
            u'affiliation': u'CERN',
            u'name': u'Doe, John'
        }, {
            u'@id': 'https://orcid.org/0000-0002-1825-0097',
            u'@type': u'Person',
            u'affiliation': u'CERN',
            u'name': u'Doe, Jane'
        }, {
            u'@type': u'Person',
            u'affiliation': u'CERN',
            u'name': u'Smith, John'
        }, {
            u'@id': 'https://d-nb.info/gnd/170118215',
            u'@type': u'Person',
            u'affiliation': u'CERN',
            u'name': u'Nowak, Jack'
        }],
        u'datePublished':
        '2014-02-27',
        u'description':
        u'Test Description',
        u'headline':
        u'Test title',
        u'image':
        u'https://zenodo.org/static/img/logos/zenodo-gradient-round.svg',
        u'inLanguage': {
            u'@type': u'Language',
            u'alternateName': u'eng',
            u'name': u'English'
        },
        u'sameAs': [
            u'https://arxiv.org/abs/arXiv:1234.4325',
            u'https://ui.adsabs.harvard.edu/#abs/2011ApJS..192...18K',
            u'https://doi.org/10.1234/alternate.doi',
        ],
        u'isPartOf': [{
            u'@id': 'https://doi.org/10.1234/zenodo.4321',
            u'@type': u'SoftwareSourceCode'
        }],
        u'hasPart': [{
            u'@id': 'https://doi.org/10.1234/zenodo.1234',
            u'@type': u'ScholarlyArticle'
        }],
        u'keywords': [u'kw1', u'kw2', u'kw3'],
        u'license':
        u'https://creativecommons.org/licenses/by/4.0/',
        u'name':
        u'Test title',
        u'url':
        u'http://localhost/record/12345',
        u'version':
        u'1.2.5',
        u'temporal': [
            '2019-01-01/..',
            '../2019-01-01',
            '2019-01-01',
            '2019-01-01/2019-02-01',
        ],
        u'spatial': [{
            u'@type': u'Place',
            u'geo': {
                u'@type': u'GeoCoordinates',
                u'latitude': 2.35,
                u'longitude': 1.534
            },
            u'name': u'my place'
        }, {
            '@type': 'Place',
            'name': 'New York'
        }],
        u'workFeatured': {
            u'@type': u'Event',
            u'name': u'The 13th Biennial HITRAN Conference',
            u'alternateName': u'HITRAN13',
            u'location': u'Harvard-Smithsonian Center for Astrophysics',
            u'url': u'http://hitran.org/conferences/hitran-13-2014/',
        },
    }
    assert data == expected