def testMarkHarvested(self): state = State(self.tempdir, 'repo') state._gmtime = lambda: (2012, 8, 13, 12, 15, 0, 0, 0, 0) state.markStarted() state.markHarvested("9999/9999/9999/9999", "resumptionToken", "2012-08-13T12:14:00") state.close() self.assertEquals('Started: 2012-08-13 12:15:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Done: 2012-08-13 12:15:00, ResumptionToken: resumptionToken\n', open(join(self.tempdir, 'repo.stats')).read()) self.assertEquals('{"from": "2012-08-13T12:14:00", "resumptionToken": "resumptionToken"}', open(join(self.tempdir, 'repo.next')).read()) self.assertEquals({"changedate": "2012-08-13 12:15:00", "status": "Ok", "message": ""}, jsonLoad(open(join(self.tempdir, 'repo.running')))) state = State(self.tempdir, 'repo') self.assertEqual('2012-08-13T12:14:00', state.from_) self.assertEqual('resumptionToken', state.token) state._gmtime = lambda: (2012, 8, 13, 12, 17, 0, 0, 0, 0) state.markStarted() state.markHarvested("9999/9999/9999/9999", "newToken", "2012-08-13T12:16:00Z") state.close() self.assertEquals("""Started: 2012-08-13 12:15:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Done: 2012-08-13 12:15:00, ResumptionToken: resumptionToken Started: 2012-08-13 12:17:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Done: 2012-08-13 12:17:00, ResumptionToken: newToken """, open(join(self.tempdir, 'repo.stats')).read()) self.assertEquals('{"from": "2012-08-13T12:14:00", "resumptionToken": "newToken"}', open(join(self.tempdir, 'repo.next')).read()) self.assertEquals({"changedate": "2012-08-13 12:15:00", "status": "Ok", "message": ""}, jsonLoad(open(join(self.tempdir, 'repo.running'))))
def testMarkDeletedAfterExceptionChange(self): state = State(self.tempdir, 'repo') state._gmtime = lambda: (2012, 8, 13, 12, 15, 0, 0, 0, 0) state.markStarted() try: raise ValueError("whatever") except: exType, exValue, exTraceback = exc_info() state.markException(exType, exValue, "9999/9999/9999/9999") state.close() self.assertEquals({"changedate": "2012-08-13 12:15:00", "status": "Error", "message": "whatever"}, jsonLoad(open(join(self.tempdir, 'repo.running')))) state = State(self.tempdir, 'repo') state._gmtime = lambda: (2012, 8, 13, 12, 17, 0, 0, 0, 0) state.markStarted() state.markDeleted() state.close() self.assertEquals({"changedate": "2012-08-13 12:17:00", "status": "Ok", "message": ""}, jsonLoad(open(join(self.tempdir, 'repo.running'))))
def testSetToLastCleanState(self): state = State(self.tempdir, 'repo') state._gmtime = lambda: (2012, 8, 13, 12, 15, 0, 0, 0, 0) state.markStarted() state.markHarvested("9999/9999/9999/9999", "", "2012-08-13T12:14:00") state.close() state = State(self.tempdir, 'repo') state._gmtime = lambda: (2012, 8, 14, 12, 17, 0, 0, 0, 0) state.markStarted() state.markHarvested("9999/9999/9999/9999", "resumptionToken", "2012-08-14T12:16:00") state.close() state = State(self.tempdir, 'repo') state._gmtime = lambda: (2012, 8, 15, 12, 19, 0, 0, 0, 0) state.setToLastCleanState() state.close() self.assertEquals("""Started: 2012-08-13 12:15:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Done: 2012-08-13 12:15:00, ResumptionToken: \nStarted: 2012-08-14 12:17:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Done: 2012-08-14 12:17:00, ResumptionToken: resumptionToken Started: 2012-08-15 12:19:00, Done: Reset to last clean state. ResumptionToken: \n""", open(join(self.tempdir, 'repo.stats')).read()) self.assertEquals('{"from": "2012-08-14T12:16:00", "resumptionToken": ""}', open(join(self.tempdir, 'repo.next')).read())
def testMarkException(self): state = State(self.tempdir, 'repo') state._gmtime = lambda: (2012, 8, 13, 12, 15, 0, 0, 0, 0) state.markStarted() state.markHarvested("9999/9999/9999/9999", "resumptionToken", "2012-08-13T12:14:00") state.close() self.assertEquals('Started: 2012-08-13 12:15:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Done: 2012-08-13 12:15:00, ResumptionToken: resumptionToken\n', open(join(self.tempdir, 'repo.stats')).read()) self.assertEquals('{"from": "2012-08-13T12:14:00", "resumptionToken": "resumptionToken"}', open(join(self.tempdir, 'repo.next')).read()) self.assertEquals({"changedate": "2012-08-13 12:15:00", "status": "Ok", "message": ""}, jsonLoad(open(join(self.tempdir, 'repo.running')))) state = State(self.tempdir, 'repo') state._gmtime = lambda: (2012, 8, 13, 12, 17, 0, 0, 0, 0) state.markStarted() try: raise ValueError("whatever") except: exType, exValue, exTraceback = exc_info() state.markException(exType, exValue, "9999/9999/9999/9999") state.close() self.assertEquals("""Started: 2012-08-13 12:15:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Done: 2012-08-13 12:15:00, ResumptionToken: resumptionToken Started: 2012-08-13 12:17:00, Harvested/Uploaded/Deleted/Total: 9999/9999/9999/9999, Error: <type 'exceptions.ValueError'>: whatever """, open(join(self.tempdir, 'repo.stats')).read()) self.assertEquals({"changedate": "2012-08-13 12:17:00", "status": "Error", "message": "whatever"}, jsonLoad(open(join(self.tempdir, 'repo.running'))))