def test_api(self):
        doi = self._random_doi()

        doc = '''<resource xmlns="http://datacite.org/schema/kernel-2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://datacite.org/schema/kernel-2.2 http://schema.datacite.org/meta/kernel-2.2/metadata.xsd">
        <identifier identifierType="DOI">%s</identifier>
        <creators>
            <creator>
                <creatorName>Simko, T</creatorName>
            </creator>
        </creators>
        <titles>
            <title>Invenio Software at Ærø</title>
        </titles>
        <publisher>CERN</publisher>
        <publicationYear>2002</publicationYear>
        </resource>
        ''' % doi

        d = dataciteutils.DataCite(prefix="10.5072", test_mode=False)

        # Set metadata for DOI
        d.metadata_post(doc)

        # Mint new DOI
        url = "http://openaire.cern.ch/doi/%s" % doi
        d.doi_post(doi, url)

        # Get DOI location
        location = d.doi_get(doi)
        self.assertEqual(location, url)

        # Get metadata for DOI
        resdoc = d.metadata_get(doi)
        # Newlines are different in submitted and response, so process values
        # before comparing.
        submitted = filter(lambda x: x, [x.strip() for x in doc.splitlines()])
        received = filter(lambda x: x,
                          [x.strip() for x in resdoc.splitlines()])
        self.assertEqual(submitted, received)

        # Set Media
        pdfurl = "http://openaire.cern.ch/pdf/doi/%s" % doi
        d.media_post(doi, {"application/pdf": pdfurl})

        # Get Media
        m = d.media_get(doi)
        self.assertTrue('application/pdf' in m)
        self.assertEqual(m['application/pdf'], pdfurl)

        # Make DOI inactive
        d.metadata_delete(doi)
        self.assertRaises(dataciteutils.DataCiteGoneError, d.metadata_get, doi)
Esempio n. 2
0
 def setUp(self):
     # Force API in test mode
     self.d = dataciteutils.DataCite(test_mode=True)
Esempio n. 3
0
 def test_unauthenticated(self):
     d = dataciteutils.DataCite(username="******", password="******")
     self.assertRaises(dataciteutils.DataCiteUnauthorizedError, d.doi_get, "10.5072/INVENIO.TEST.22KX-LRQR")