Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_datacite_build_metadata(self, registration, datacite_client):
metadata_xml = datacite_client.build_metadata(registration).encode('utf-8')
parser = lxml.etree.XMLParser(ns_clean=True, recover=True, encoding='utf-8')
root = lxml.etree.fromstring(metadata_xml, parser=parser)
xsi_location = '{http://www.w3.org/2001/XMLSchema-instance}schemaLocation'
expected_location = 'http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd'
assert root.attrib[xsi_location] == expected_location
identifier = root.find('{%s}identifier' % schema40.ns[None])
assert identifier.attrib['identifierType'] == 'DOI'
assert identifier.text == settings.DOI_FORMAT.format(prefix=settings.DATACITE_PREFIX, guid=registration._id)
creators = root.find('{%s}creators' % schema40.ns[None])
assert len(creators.getchildren()) == len(registration.visible_contributors)
publisher = root.find('{%s}publisher' % schema40.ns[None])
assert publisher.text == 'Open Science Framework'
pub_year = root.find('{%s}publicationYear' % schema40.ns[None])
assert pub_year.text == str(registration.registered_date.year)
resource_type = root.find('{%s}resourceType' % schema40.ns[None])
assert resource_type.text == 'Project'
assert resource_type.attrib['resourceTypeGeneral'] == 'Text'
assert root.attrib[xsi_location] == expected_location
identifier = root.find('{%s}identifier' % schema40.ns[None])
assert identifier.attrib['identifierType'] == 'DOI'
assert identifier.text == settings.DOI_FORMAT.format(prefix=settings.DATACITE_PREFIX, guid=registration._id)
creators = root.find('{%s}creators' % schema40.ns[None])
assert len(creators.getchildren()) == len(registration.visible_contributors)
publisher = root.find('{%s}publisher' % schema40.ns[None])
assert publisher.text == 'Open Science Framework'
pub_year = root.find('{%s}publicationYear' % schema40.ns[None])
assert pub_year.text == str(registration.registered_date.year)
resource_type = root.find('{%s}resourceType' % schema40.ns[None])
assert resource_type.text == 'Project'
assert resource_type.attrib['resourceTypeGeneral'] == 'Text'
data['descriptions'] = [{
'descriptionType': 'Abstract',
'description': node.description
}]
if node.node_license:
data['rightsList'] = [{
'rights': node.node_license.name,
'rightsURI': node.node_license.url
}]
# Validate dictionary
assert schema40.validate(data)
# Generate DataCite XML from dictionary.
return schema40.tostring(data)
def serialize_xml(cls, record):
data = json.loads(cls.serialize_json(record))
return schema40.tostring(data)
data['descriptions'] = [{
'descriptionType': 'Abstract',
'description': node.description
}]
if node.node_license:
data['rightsList'] = [{
'rights': node.node_license.name,
'rightsURI': node.node_license.url
}]
# Validate dictionary
assert schema40.validate(data)
# Generate DataCite XML from dictionary.
return schema40.tostring(data)
}
if node.description:
data['descriptions'] = [{
'descriptionType': 'Abstract',
'description': node.description
}]
if node.node_license:
data['rightsList'] = [{
'rights': node.node_license.name,
'rightsURI': node.node_license.url
}]
# Validate dictionary
assert schema40.validate(data)
# Generate DataCite XML from dictionary.
return schema40.tostring(data)
}
if node.description:
data['descriptions'] = [{
'descriptionType': 'Abstract',
'description': node.description
}]
if node.node_license:
data['rightsList'] = [{
'rights': node.node_license.name,
'rightsURI': node.node_license.url
}]
# Validate dictionary
assert schema40.validate(data)
# Generate DataCite XML from dictionary.
return schema40.tostring(data)