コード例 #1
0
    def testHarvesterStateWithError(self):
        resumptionToken = "u|c1286437597991025|mprefix|s|f"
        open(join(self.tempdir, 'harvester.state'), 'w').write("Resumptiontoken: %s\n" % resumptionToken)
        observer = CallTrace()
        observer.exceptions={'add': Exception("Could be anything")}
        oaiDownloadProcessor = OaiDownloadProcessor(path="/oai", metadataPrefix="oai_dc", workingDirectory=self.tempdir, xWait=True, err=StringIO(), name="Name")
        oaiDownloadProcessor.addObserver(observer)
        self.assertRaises(Exception, lambda: list(compose(oaiDownloadProcessor.handle(parse(StringIO(LISTRECORDS_RESPONSE % RESUMPTION_TOKEN))))))
        state = oaiDownloadProcessor.getState()
        self.assertEquals(resumptionToken, state.resumptionToken)
        self.assertEquals(None, state.from_)
        self.assertEquals("ERROR while processing 'oai:identifier:1': Could be anything", state.errorState)
        self.assertEquals("Name", state.name)

        oaiDownloadProcessor2 = OaiDownloadProcessor(path="/oai", metadataPrefix="oai_dc", workingDirectory=self.tempdir, xWait=True, err=StringIO())
        state2 = oaiDownloadProcessor2.getState()
        self.assertEquals(resumptionToken, state2.resumptionToken)
        self.assertEquals("ERROR while processing 'oai:identifier:1': Could be anything", state2.errorState)
コード例 #2
0
    def testShutdownPersistsStateOnAutocommit(self):
        observer = CallTrace(emptyGeneratorMethods=['add'])
        oaiDownloadProcessor = OaiDownloadProcessor(path="/oai", metadataPrefix="oai_dc", workingDirectory=self.tempdir, autoCommit=False)
        oaiDownloadProcessor.addObserver(observer)
        consume(oaiDownloadProcessor.handle(parse(StringIO(LISTRECORDS_RESPONSE % RESUMPTION_TOKEN))))
        state = oaiDownloadProcessor.getState()
        self.assertFalse(isfile(join(self.tempdir, 'harvester.state')))

        oaiDownloadProcessor.handleShutdown()
        self.assertEquals({"errorState": None, 'from': '2002-06-01T19:20:30Z', "resumptionToken": state.resumptionToken}, load(open(join(self.tempdir, 'harvester.state'))))
コード例 #3
0
    def testHarvesterState(self):
        observer = CallTrace(emptyGeneratorMethods=['add'])
        oaiDownloadProcessor = OaiDownloadProcessor(path="/oai", metadataPrefix="oai_dc", workingDirectory=self.tempdir, xWait=True, err=StringIO())
        oaiDownloadProcessor.addObserver(observer)
        state = oaiDownloadProcessor.getState()
        self.assertEquals(None, state.resumptionToken)
        self.assertEquals(None, state.from_)
        self.assertEquals(None, state.errorState)
        self.assertEquals(None, state.name)
        self.assertEquals("/oai", state.path)
        self.assertEquals("oai_dc", state.metadataPrefix)
        self.assertEquals(None, state.set)
        self.assertEquals(0, state.nextRequestTime)
        oaiDownloadProcessor.setSet('s')
        oaiDownloadProcessor.setPath('/p')
        oaiDownloadProcessor.setMetadataPrefix('pref')
        oaiDownloadProcessor.observable_setName('aName')
        consume(oaiDownloadProcessor.handle(parse(StringIO(LISTRECORDS_RESPONSE % RESUMPTION_TOKEN))))
        state = oaiDownloadProcessor.getState()
        self.assertEquals("x?y&z", state.resumptionToken)
        self.assertEquals('2002-06-01T19:20:30Z', state.from_)
        self.assertEquals(None, state.errorState)
        self.assertEquals('aName', state.name)
        self.assertEquals("/p", state.path)
        self.assertEquals("pref", state.metadataPrefix)
        self.assertEquals('s', state.set)
        self.assertEquals(0, state.nextRequestTime)

        # Change state of oaiDownloadProcessor -> changes stateView.
        oaiDownloadProcessor.setSet('x')
        self.assertEquals('x', state.set)

        oaiDownloadProcessor2 = OaiDownloadProcessor(path="/oai", metadataPrefix="oai_dc", workingDirectory=self.tempdir, xWait=True, err=StringIO())
        state2 = oaiDownloadProcessor2.getState()
        self.assertEquals(None, state2.name)
        self.assertEquals("oai_dc", state2.metadataPrefix)
        self.assertEquals("x?y&z", state2.resumptionToken)
        self.assertEquals('2002-06-01T19:20:30Z', state2.from_)
        self.assertEquals(None, state2.errorState)
        self.assertEquals(0, state.nextRequestTime)