Esempio n. 1
0
 def testOverrideMetadataPrefix(self):
     '''test that the metadataPrefix for an OAI feed can be overridden.
     The extra_data for OAI can be either just a set spec or a html query
     string of set= &metadataPrefix=
     '''
     httpretty.register_uri(httpretty.GET,
                            'http://content.cdlib.org/oai',
                            body=open(DIR_FIXTURES + '/testOAI.xml').read())
     set_fetcher = fetcher.OAIFetcher('http://content.cdlib.org/oai',
                                      'set=oac:images')
     self.assertEqual(set_fetcher._set, 'oac:images')
     rec = set_fetcher.next()
     self.assertIsInstance(rec, dict)
     self.assertIn('id', rec)
     self.assertEqual(rec['id'], '13030/hb796nb5mn')
     self.assertIn('datestamp', rec)
     self.assertIn(rec['datestamp'], '2005-12-13')
     self.assertEqual(
         httpretty.last_request().querystring, {
             u'verb': [u'ListRecords'],
             u'set': [u'oac:images'],
             u'metadataPrefix': [u'oai_dc']
         })
     httpretty.register_uri(httpretty.GET,
                            'http://content.cdlib.org/oai',
                            body=open(DIR_FIXTURES +
                                      '/testOAI-didl.xml').read())
     didl_fetcher = fetcher.OAIFetcher(
         'http://content.cdlib.org/oai',
         'set=oac:images&metadataPrefix=didl')
     self.assertEqual(didl_fetcher._set, 'oac:images')
     self.assertEqual(didl_fetcher._metadataPrefix, 'didl')
     rec = didl_fetcher.next()
     self.assertIsInstance(rec, dict)
     self.assertIn('id', rec)
     self.assertEqual(rec['id'], 'oai:ucispace-prod.lib.uci.edu:10575/25')
     self.assertEqual(rec['title'], ['Schedule of lectures'])
     self.assertIn('datestamp', rec)
     self.assertEqual(rec['datestamp'], '2015-05-20T11:04:23Z')
     self.assertEqual(
         httpretty.last_request().querystring, {
             u'verb': [u'ListRecords'],
             u'set': [u'oac:images'],
             u'metadataPrefix': [u'didl']
         })
     self.assertEqual(
         rec['Resource']['@ref'],
         'http://ucispace-prod.lib.uci.edu/xmlui/bitstream/' +
         '10575/25/1/!COLLOQU.IA.pdf')
     self.assertEqual(rec['Item']['@id'],
                      'uuid-640925bd-9cdf-46be-babb-b2138c3fce9c')
     self.assertEqual(rec['Component']['@id'],
                      'uuid-897984d8-9392-4a68-912f-ffdf6fd7ce59')
     self.assertIn('Descriptor', rec)
     self.assertEqual(rec['Statement']['@mimeType'],
                      'application/xml; charset=utf-8')
     self.assertEqual(
         rec['DIDLInfo']['{urn:mpeg:mpeg21:2002:02-DIDL-NS}DIDLInfo'][0]
         ['text'], '2015-05-20T20:30:26Z')
     del didl_fetcher
Esempio n. 2
0
 def setUp(self):
     super(OAIFetcherTestCase, self).setUp()
     httpretty.register_uri(httpretty.GET,
                            'http://content.cdlib.org/oai',
                            body=open(DIR_FIXTURES + '/testOAI.xml').read())
     self.fetcher = fetcher.OAIFetcher('http://content.cdlib.org/oai',
                                       'oac:images')
Esempio n. 3
0
 def test_getMetadataPrefix(self):
     fmts = open(DIR_FIXTURES+'/oai-fmts.xml').read()
     fmts_qdc = open(DIR_FIXTURES+'/oai-fmts-qdc.xml').read()
     httpretty.register_uri(
             httpretty.GET,
             'http://xxxx.cdlib.org/oai?verb=ListMetadataFormats',
             responses=[
                 httpretty.Response(body=fmts, status=200),
                 httpretty.Response(body=fmts, status=200),
                 httpretty.Response(body=fmts, status=200),
                 httpretty.Response(body=fmts_qdc, status=200),
             ])
     set_fetcher = fetcher.OAIFetcher('http://xxxx.cdlib.org/oai',
                                      'set=bogus')
     self.assertEqual(set_fetcher._metadataPrefix, 'oai_dc')
     prefix = set_fetcher.get_metadataPrefix('')
     self.assertEqual(prefix, 'oai_dc')
     prefix = set_fetcher.get_metadataPrefix('metadataPrefix=override')
     self.assertEqual(prefix, 'override')
     prefix = set_fetcher.get_metadataPrefix('')
     self.assertEqual(prefix, 'oai_qdc')
Esempio n. 4
0
    def testDCTERMS(self):
        '''Test the OAI fetcher when the source data has exteneded dcterms in
        it.
        '''
        DCTERMS = (
                'abstract', 'accessRights', 'accrualMethod',
                'accrualPeriodicity', 'accrualPolicy', 'alternative',
                'audience', 'available', 'bibliographicCitation', 'conformsTo',
                'contributor', 'coverage', 'created', 'creator', 'date',
                'dateAccepted', 'dateCopyrighted', 'dateSubmitted',
                'description', 'educationLevel', 'extent', 'format',
                'hasFormat', 'hasPart', 'hasVersion', 'identifier',
                'instructionalMethod', 'isFormatOf', 'isPartOf',
                'isReferencedBy', 'isReplacedBy', 'isRequiredBy', 'issued',
                'isVersionOf', 'language', 'license', 'mediator', 'medium',
                'modified', 'provenance', 'publisher', 'references',
                'relation', 'replaces', 'requires', 'rights', 'rightsHolder',
                'source', 'spatial', 'subject', 'tableOfContents', 'temporal',
                'title', 'type', 'valid')

        httpretty.register_uri(
                httpretty.GET,
                'http://content.cdlib.org/oai',
                body=open(DIR_FIXTURES+'/oai-with-dcterms.xml').read())
        set_fetcher = fetcher.OAIFetcher('http://content.cdlib.org/oai',
                                         'set=bogus')
        self.assertEqual(set_fetcher._set, 'bogus')
        rec = set_fetcher.next()
        self.assertIsInstance(rec, dict)
        self.assertIn('id', rec)
        self.assertEqual(rec['id'],
                         'oai:digitalcollections.usfca.edu:p264101coll6/188')
        for term in DCTERMS:  # dependent on data fed to sickle
            self.assertIn(term, rec.keys())
        self.assertEqual(rec['created'], ['TEST dcterms:created'])
        self.assertEqual(rec['date'], ['1927; ', 'TEST dcterms:date'])