Beispiel #1
0
    def testGetRecordDeletedInRequestedPrefix(self):
        oaijazz = OaiJazz(self.tempdir + '/jazz')
        storage = MultiSequentialStorage(self.tempdir + "/seq-store")
        oairecord = OaiRecord()

        class MyStorage(object):
            def getData(self, identifier, name):
                return 'data'

        oaigetrecord = be((OaiGetRecord(repository=OaiRepository()),
                           (oaijazz, ), (oairecord, (MyStorage(), ))))
        oaijazz.addOaiRecord(identifier='id:0', metadataPrefixes=['A', 'B'])
        oaijazz.deleteOaiRecordInPrefixes(identifier='id:0',
                                          metadataPrefixes=['A'])
        response = oaigetrecord.getRecord(arguments=dict(
            verb=['GetRecord'],
            metadataPrefix=['A'],
            identifier=['id:0'],
        ),
                                          **self.httpkwargs)
        _, body = asString(response).split("\r\n\r\n")
        self.assertEqual(
            'deleted',
            xpathFirst(
                XML(body.encode()),
                '/oai:OAI-PMH/oai:GetRecord/oai:record/oai:header/@status'),
            body)

        response = oaigetrecord.getRecord(arguments=dict(
            verb=['GetRecord'],
            metadataPrefix=['B'],
            identifier=['id:0'],
        ),
                                          **self.httpkwargs)
        _, body = asString(response).split("\r\n\r\n")
        self.assertEqual(
            "data", xpathFirst(XML(body.encode()), '//oai:metadata/text()'))

        response = oaigetrecord.getRecord(arguments=dict(
            verb=['GetRecord'],
            metadataPrefix=['C'],
            identifier=['id:0'],
        ),
                                          **self.httpkwargs)
        _, body = asString(response).split("\r\n\r\n")
        self.assertEqual(
            'cannotDisseminateFormat',
            xpathFirst(XML(body.encode()), '/oai:OAI-PMH/oai:error/@code'))
Beispiel #2
0
    def testGetRecordDeletedInRequestedPrefix(self):
        oaijazz = OaiJazz(self.tempdir + '/jazz')
        storage = MultiSequentialStorage(self.tempdir + "/seq-store")
        oairecord = OaiRecord()
        class MyStorage(object):
            def getData(self, identifier, name):
                return 'data'
        oaigetrecord = be((OaiGetRecord(repository=OaiRepository()),
            (oaijazz,),
            (oairecord,
                (MyStorage(),)
            )
        ))
        oaijazz.addOaiRecord(identifier='id:0', metadataPrefixes=['A', 'B'])
        oaijazz.deleteOaiRecordInPrefixes(identifier='id:0', metadataPrefixes=['A'])
        response = oaigetrecord.getRecord(arguments=dict(
                verb=['GetRecord'],
                metadataPrefix=['A'],
                identifier=['id:0'],
            ),
            **self.httpkwargs)
        _, body = asString(response).split("\r\n\r\n")
        self.assertEqual('deleted', xpathFirst(XML(body), '/oai:OAI-PMH/oai:GetRecord/oai:record/oai:header/@status'), body)

        response = oaigetrecord.getRecord(arguments=dict(
                verb=['GetRecord'],
                metadataPrefix=['B'],
                identifier=['id:0'],
            ),
            **self.httpkwargs)
        _, body = asString(response).split("\r\n\r\n")
        self.assertEqual("data", xpathFirst(XML(body), '//oai:metadata/text()'))

        response = oaigetrecord.getRecord(arguments=dict(
                verb=['GetRecord'],
                metadataPrefix=['C'],
                identifier=['id:0'],
            ),
            **self.httpkwargs)
        _, body = asString(response).split("\r\n\r\n")
        self.assertEqual('cannotDisseminateFormat', xpathFirst(XML(body), '/oai:OAI-PMH/oai:error/@code'))
Beispiel #3
0
    def testExport(self):
        jazz = OaiJazz(join(self.tempdir, 'oai'), deleteInSets=True)
        jazz.updateMetadataFormat(prefix='someprefix',
                                  schema='https://example.org/schema.xsd',
                                  namespace='urn:ns')
        jazz.updateMetadataFormat(prefix='prefix',
                                  schema='schema',
                                  namespace='namespace')
        jazz.updateSet(setSpec='a', setName='A')
        jazz.updateSet(setSpec='setSpec', setName='setName')
        jazz.addOaiRecord(identifier='id:0', metadataPrefixes=['prefix'])
        jazz.addOaiRecord(identifier='id:1',
                          metadataPrefixes=['prefix'],
                          setSpecs=['a', 'a:b', 'd:e:f'])
        jazz.addOaiRecord(identifier='id:2',
                          metadataPrefixes=['prefix', 'someprefix'],
                          setSpecs=['a', 'a:b', 'd:e:f'])
        jazz.addOaiRecord(identifier='id:3',
                          metadataPrefixes=['prefix', 'someprefix'],
                          setSpecs=['a', 'a:b', 'd:e:f'])
        for i in range(4, 3000):
            jazz.addOaiRecord(identifier='id:{}'.format(i),
                              metadataPrefixes=['prefix'])

        jazz.deleteOaiRecordInPrefixes(identifier='id:2',
                                       metadataPrefixes=['someprefix'])
        jazz.deleteOaiRecordInSets(identifier='id:3', setSpecs=['d:e:f'])
        jazz.deleteOaiRecord(identifier='id:7')

        dumpfile = join(self.tempdir, 'dump')
        jazz.export(dumpfile)

        with open(dumpfile) as fp:
            d = fp.readlines()
        self.assertEqual(3003, len(d))
        self.assertEqual('META:\n', d[0])
        self.assertEqual('RECORDS:\n', d[2])
        meta = loads(d[1].strip())
        self.assertEqual(
            {
                'export_version': 1,
                'metadataPrefixes': {
                    'someprefix': {
                        'schema': 'https://example.org/schema.xsd',
                        'namespace': 'urn:ns'
                    },
                    'prefix': {
                        'schema': 'schema',
                        'namespace': 'namespace'
                    },
                },
                'sets': {
                    'a': {
                        'setName': 'A'
                    },
                    'a:b': {
                        'setName': ''
                    },
                    'd': {
                        'setName': ''
                    },
                    'd:e': {
                        'setName': ''
                    },
                    'd:e:f': {
                        'setName': ''
                    },
                    'setSpec': {
                        'setName': 'setName'
                    },
                }
            }, meta)
        record0 = loads(d[3].strip())
        self.assertAlmostEqual(time(), record0['timestamp'] / 10.0**6, delta=3)
        record0['timestamp'] = 'TIMESTAMP'
        self.assertEqual(
            {
                'identifier': 'id:0',
                'timestamp': 'TIMESTAMP',
                'tombstone': False,
                'deletedPrefixes': [],
                'prefixes': ['prefix'],
                'deletedSets': [],
                'sets': [],
            }, record0)
        record2 = loads(d[-3].strip())
        record2['timestamp'] = 'TIMESTAMP'
        self.assertEqual(
            {
                'identifier': 'id:2',
                'timestamp': 'TIMESTAMP',
                'tombstone': False,
                'deletedPrefixes': ['someprefix'],
                'prefixes': ['prefix', 'someprefix'],
                'deletedSets': [],
                'sets': ['a', 'a:b', 'd', 'd:e', 'd:e:f'],
            }, record2)
        record3 = loads(d[-2].strip())
        record3['timestamp'] = 'TIMESTAMP'
        self.assertEqual(
            {
                'identifier': 'id:3',
                'timestamp': 'TIMESTAMP',
                'tombstone': False,
                'deletedPrefixes': [],
                'prefixes': ['prefix', 'someprefix'],
                'deletedSets': ['d:e:f'],
                'sets': ['a', 'a:b', 'd', 'd:e', 'd:e:f'],
            }, record3)
        record7 = loads(d[-1].strip())
        record7['timestamp'] = 'TIMESTAMP'
        self.assertEqual(
            {
                'identifier': 'id:7',
                'timestamp': 'TIMESTAMP',
                'tombstone': True,
                'deletedPrefixes': ['prefix'],
                'prefixes': ['prefix'],
                'deletedSets': [],
                'sets': [],
            }, record7)