Exemple #1
0
def test_identifiers(minimal_json42):
    """Test identifiers."""
    pytest.raises(TypeError, dump_etree, {'identifiers': {
        'invalid': 'data'
    }})

    data = {'identifiers': [
        {
            'identifier': '10.1234/foo',
            'identifierType': 'DOI'
        }
    ]}
    validate_json(minimal_json42, data)
    tree = dump_etree(data)
    elem = dump_etree(data).xpath('/resource/identifier')[0]
    assert elem.get('identifierType') == 'DOI'
    assert elem.text == '10.1234/foo'

    data = {'identifiers': [
        {
            'identifier': '10.1234/foo',
            'identifierType': 'DOI',
        },
        {
            'identifierType': 'internal ID',
            'identifier': 'da|ra.14.103'
        }
    ]}
    validate_json(minimal_json42, data)

    elem = dump_etree(data).xpath(
            '/resource/alternateIdentifiers/alternateIdentifier')[0]
    assert elem.get('alternateIdentifierType') == 'internal ID'
    assert elem.text == 'da|ra.14.103'
    elem = dump_etree(data).xpath('/resource/identifier')[0]
    assert elem.get('identifierType') == 'DOI'
    assert elem.text == '10.1234/foo'

    data = {'identifiers': [
        {
            'identifier': '13682',
            'identifierType': 'Eprint_ID'}
        ]}

    xml = tostring(data)
    elem = dump_etree(data).xpath(
            '/resource/alternateIdentifiers/alternateIdentifier')[0]
    assert elem.get('alternateIdentifierType') == 'Eprint_ID'
    assert elem.text == '13682'
Exemple #2
0
        {'title': 'Minimal Test Case', }
    ],
    'publisher': 'Invenio Software',
    'publicationYear': '2015',
    'types': {
        'resourceType': 'Dataset',
        'resourceTypeGeneral': 'Dataset'
    },
    'schemaVersion': 'http://datacite.org/schema/kernel-4',
}

# Validate dictionary
assert schema42.validate(data)

# Generate DataCite XML from dictionary.
doc = schema42.tostring(data)

# Initialize the MDS client.
d = DataCiteMDSClient(
    username='******',
    password='******',
    prefix='10.5072',
)

# Set metadata for DOI
d.metadata_post(doc)

# Mint new DOI
d.doi_post('10.5072/test-doi', 'http://example.org/test-doi')

# Get DOI location
Exemple #3
0
def test_empty_arrays(xsd42, minimal_json42, field_name):
    """Test proper behavior with empty lists for certain fields."""
    minimal_json42[field_name] = []
    validator.validate(minimal_json42)
    xsd42.assertValid(etree.XML(tostring(minimal_json42).encode('utf8')))
Exemple #4
0
def test_minimal_xsd(xsd42, minimal_json42):
    """Test that example XML converts to example JSON."""
    validator.validate(minimal_json42)
    xsd42.assertValid(etree.XML(tostring(minimal_json42).encode('utf8')))
Exemple #5
0
def test_json_eq_xml(example_xml_file42, example_json42, xsd42):
    """Test that example XML converts to example JSON."""
    xsd42.assertValid(etree.XML(tostring(example_json42).encode('utf8')))
Exemple #6
0
def test_json_to_xml(example_xml42, example_json42, xsd42):
    """Test that example XML converts to example JSON."""
    example_xml = load_xml_path(example_xml42)
    example_json = load_json_path(example_json42)
    xsd42.assertValid(etree.XML(example_xml.encode('utf8')))
    xsd42.assertValid(etree.XML(tostring(example_json).encode('utf8')))