Esempio n. 1
0
def test_minimal_xsd(xsd31):
    """Test that example XML converts to example JSON."""
    xsd31.assertValid(
        etree.XML(
            tostring({
                'identifier': {
                    'identifierType': 'DOI',
                    'identifier': '10.1234/foo.bar',
                },
                'creators': [{
                    'creatorName': 'Nielsen, Lars Holm',
                }, {
                    'creatorName': 'Nielsen, Lars Holm',
                    'nameIdentifier': {
                        'nameIdentifier': '1234',
                        'schemeURI': 'http://orcid.org',
                        'nameIdentifierScheme': 'ORCID',
                    }
                }],
                'titles': [{
                    'title': 'Minimal Test Case',
                }],
                'publisher':
                'Invenio Software',
                'publicationYear':
                '2016',
            }).encode('utf8')))
Esempio n. 2
0
    def serialize(self, pid, record, links_factory=None):
        """Serialize a single record and persistent identifier.

        :param pid: Persistent identifier instance.
        :param record: Record instance.
        :param links_factory: Factory function for record links.
        """
        return schema31.tostring(
            self.transform_record(pid, record, links_factory))
Esempio n. 3
0
 def _create_doi(self, doi, url, data):
     metadata = None
     try:
         schema31.validate(data)
         metadata = schema31.tostring(data)
     except ValidationError as e:
         self.errors.append(str(e))
     #import pdb; pdb.set_trace()
     self._post_metadata(metadata)
     self._post_doi(doi, url)
Esempio n. 4
0
    def serialize_search(self, pid_fetcher, search_result, links=None,
                         item_links_factory=None):
        """Serialize a search result.

        :param pid_fetcher: Persistent identifier fetcher.
        :param search_result: Elasticsearch search result.
        :param links: Dictionary of links to add to response.
        """
        records = []
        for hit in search_result['hits']['hits']:
            records.append(schema31.tostring(self.transform_search_hit(
                pid_fetcher(hit['_id'], hit['_source']),
                hit,
                links_factory=item_links_factory,
            )))

        return "\n".join(records)
Esempio n. 5
0
def test_minimal_xsd(xsd31):
    """Test that example XML converts to example JSON."""
    xsd31.assertValid(etree.XML(tostring({
        'identifier': {
            'identifierType': 'DOI',
            'identifier': '10.1234/foo.bar',
        },
        'creators': [
            {'creatorName': 'Nielsen, Lars Holm', },
            {
                'creatorName': 'Nielsen, Lars Holm',
                'nameIdentifier': {
                    'nameIdentifier': '1234',
                    'schemeURI': 'http://orcid.org',
                    'nameIdentifierScheme': 'ORCID',
                }
            }
        ],
        'titles': [
            {'title': 'Minimal Test Case', }
        ],
        'publisher': 'Invenio Software',
        'publicationYear': '2016',
    }).encode('utf8')))
Esempio n. 6
0
def test_json_to_xml(example_xml_file, example_json, xsd31):
    """Test that example XML converts to example JSON."""
    xsd31.assertValid(etree.XML(example_xml_file.encode('utf8')))
    assert ET.dump(ET.XML(example_xml_file)) == \
        ET.dump(ET.XML(tostring(example_json)))
Esempio n. 7
0
def test_json_to_xml(example_xml_file, example_json, xsd31):
    """Test that example XML converts to example JSON."""
    xsd31.assertValid(etree.XML(example_xml_file.encode('utf8')))
    xsd31.assertValid(etree.XML(tostring(example_json).encode('utf8')))
Esempio n. 8
0
    },
    'creators': [
        {'creatorName': 'Smith, John'}
    ],
    'titles': [
        {'title': 'DataCite PyPI Package'}
    ],
    'publisher': 'CERN',
    'publicationYear': '2015',
}

# Validate dictionary
assert schema31.validate(data)

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

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

# Set metadata for DOI
d.metadata_post(doc)

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