Ejemplo n.º 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'
            # Validation fails on Windows
            if os.name == "nt":
                valid = True
            else:
                valid = schema43.validate(metadata)
            # Debugging if verification fails
            if valid == False:
                v = schema43.validator.validate(metadata)
                errors = sorted(v.iter_errors(instance), key=lambda e: e.path)
                for error in errors:
                    print(error.message)

            if args.mint != True:

                xml = schema43.tostring(metadata)

                outname = f.split(".xml")[0] + "_datacite.xml"
                outfile = open(outname, "w", encoding="utf8")
                outfile.write(xml)

            else:

                # What record in eprints are we dealing with?
                record_number = eprint["eprintid"]

                if args.prefix != None:
                    prefix = args.prefix
                else:
                    prefix = "10.7907"
Ejemplo n.º 3
0
 def serialize_object(self, record, **kwargs):
     """Serialize a single record."""
     data = self.dump_one(record, **kwargs)
     return schema43.tostring(data)
Ejemplo n.º 4
0
def test_json_eq_xml(example_xml_file43, example_json43, xsd43):
    """Test that example XML converts to example JSON."""
    xsd43.assertValid(etree.XML(tostring(example_json43).encode('utf8')))
Ejemplo n.º 5
0
def test_json_to_xml(example_xml43, example_json43, xsd43):
    """Test that example XML converts to example JSON."""
    example_xml = load_xml_path(example_xml43)
    example_json = load_json_path(example_json43)
    xsd43.assertValid(etree.XML(example_xml.encode('utf8')))
    xsd43.assertValid(etree.XML(tostring(example_json).encode('utf8')))
Ejemplo n.º 6
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')))
Ejemplo n.º 7
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')))