def test_archive(connect, tmpdir): endm = connect().end_maintenance with request_population(5, tmpdir) as (rm, reqs): # len(ARCHIVE) == 4, won't touch the last one in reqs for req, state in zip(reqs, sorted(ARCHIVE)): req.state = state req._reqid = str(state) att = Attempt() att.duration = 5 req.attempts = [att] req.save() rm.archive() endm.assert_called_once_with({ 'success': { 'duration': 5, 'result': 'success' }, 'error': { 'duration': 5, 'result': 'error' }, 'retrylimit': { 'duration': 5, 'result': 'retrylimit' }, 'deleted': { 'duration': 5, 'result': 'deleted' }, }) for r in reqs[0:3]: assert 'archive/' in r.dir assert 'requests/' in reqs[4].dir
def test_list(reqmanager): r1 = Request(Activity(), "14m", "pending request") reqmanager.add(r1) r2 = Request(Activity(), "2h", "due request") r2.state = State.due r2.next_due = datetime.datetime(2016, 4, 20, 12, tzinfo=pytz.UTC) reqmanager.add(r2) r3 = Request(Activity(), "1m 30s", "error request") r3.state = State.error r3.next_due = datetime.datetime(2016, 4, 20, 11, tzinfo=pytz.UTC) att = Attempt() att.duration = datetime.timedelta(seconds=75) att.returncode = 1 r3.attempts = [att] reqmanager.add(r3) assert ( str(reqmanager) == """\ St Id Scheduled Estimate Comment e {id3} 2016-04-20 11:00 UTC 1m 30s error request (duration: 1m 15s) * {id2} 2016-04-20 12:00 UTC 2h due request - {id1} --- TBA --- 14m pending request\ """.format( id1=r1.id[:7], id2=r2.id[:7], id3=r3.id[:7] ) )
def test_archive(connect, tmpdir): endm = connect().end_maintenance with request_population(5, tmpdir) as (rm, reqs): # len(ARCHIVE) == 4, won't touch the last one in reqs for req, state in zip(reqs, sorted(ARCHIVE)): req.state = state req._reqid = str(state) att = Attempt() att.duration = 5 req.attempts = [att] req.save() rm.archive() endm.assert_called_once_with( { "success": {"duration": 5, "result": "success"}, "error": {"duration": 5, "result": "error"}, "retrylimit": {"duration": 5, "result": "retrylimit"}, "deleted": {"duration": 5, "result": "deleted"}, } ) for r in reqs[0:3]: assert "archive/" in r.dir assert "requests/" in reqs[4].dir
def test_duration(): r = Request(Activity(), 1) a = Attempt() a.duration = 10 r.attempts.append(a) a = Attempt() a.duration = 5 r.attempts.append(a) assert r.duration == 5 # last attempt counts