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.assertEqual(None, state.resumptionToken) self.assertEqual(None, state.from_) self.assertEqual(None, state.errorState) self.assertEqual(None, state.name) self.assertEqual("/oai", state.path) self.assertEqual("oai_dc", state.metadataPrefix) self.assertEqual(None, state.set) self.assertEqual(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.assertEqual("x?y&z", state.resumptionToken) self.assertEqual('2002-06-01T19:20:30Z', state.from_) self.assertEqual(None, state.errorState) self.assertEqual('aName', state.name) self.assertEqual("/p", state.path) self.assertEqual("pref", state.metadataPrefix) self.assertEqual('s', state.set) self.assertEqual(0, state.nextRequestTime) # Change state of oaiDownloadProcessor -> changes stateView. oaiDownloadProcessor.setSet('x') self.assertEqual('x', state.set) oaiDownloadProcessor2 = OaiDownloadProcessor( path="/oai", metadataPrefix="oai_dc", workingDirectory=self.tempdir, xWait=True, err=StringIO()) state2 = oaiDownloadProcessor2.getState() self.assertEqual(None, state2.name) self.assertEqual("oai_dc", state2.metadataPrefix) self.assertEqual("x?y&z", state2.resumptionToken) self.assertEqual('2002-06-01T19:20:30Z', state2.from_) self.assertEqual(None, state2.errorState) self.assertEqual(0, state.nextRequestTime)
def testUpdateRequest(self): oaiDownloadProcessor = OaiDownloadProcessor( path="/oai", metadataPrefix="oai_dc", workingDirectory=self.tempdir, xWait=True) oaiDownloadProcessor.setPath('/otherOai') oaiDownloadProcessor.setMetadataPrefix('otherPrefix') oaiDownloadProcessor.setSet('aSet') oaiDownloadProcessor.setFrom('2014') self.assertEqual( """GET /otherOai?verb=ListRecords&from=2014&metadataPrefix=otherPrefix&set=aSet&x-wait=True HTTP/1.0\r\nX-Meresco-Oai-Client-Identifier: %s\r\nUser-Agent: Meresco-Oai-DownloadProcessor/5.x\r\n\r\n""" % oaiDownloadProcessor._identifier, oaiDownloadProcessor.buildRequest())
def testUpdateRequestAfterSetResumptionToken(self): oaiDownloadProcessor = OaiDownloadProcessor( path="/oai", metadataPrefix="oai_dc", set="aSet", workingDirectory=self.tempdir, xWait=False) oaiDownloadProcessor.setPath('/otherOai') oaiDownloadProcessor.setFrom('2014') oaiDownloadProcessor.setResumptionToken('ReSumptionToken') self.assertEqual( """GET /otherOai?verb=ListRecords&resumptionToken=ReSumptionToken HTTP/1.0\r\nX-Meresco-Oai-Client-Identifier: %s\r\nUser-Agent: Meresco-Oai-DownloadProcessor/5.x\r\n\r\n""" % oaiDownloadProcessor._identifier, oaiDownloadProcessor.buildRequest())