def test_process_tasks(self): now = datetime.datetime.now() webui.models_in_queue = { "lifestage_test": { "RUN" : { 'last_update': now - datetime.timedelta(seconds=100) }, "OCCUPANCY_GIF": { 'last_update': now - datetime.timedelta(seconds=500) } } } before_complete = webui.last_notice updates=webui.process_tasks() self.assertEqual(webui.last_notice, before_complete) before_complete = webui.last_notice webui.models_in_queue['lifestage_test']['RUN']['complete']= \ datetime.datetime.now() updates=webui.process_tasks() self.assertTrue(webui.last_notice > before_complete) # test to ensure old completed actions are removed: webui.models_in_queue['lifestage_test']['RUN']['last_update']= \ datetime.datetime.now() - datetime.timedelta(days=8) updates=webui.process_tasks() self.assertTrue('RUN' not in \ webui.models_in_queue['lifestage_test'])
def test_process_tasks_errors(self): # test errors now = datetime.datetime.now() # We have to remove at least a little bit of time because # webui.last_notice will match now on a VM (while testing Windows) webui.last_notice -= datetime.timedelta(milliseconds=100) webui.models_in_queue = { "lifestage_test": { "RUN" : { 'last_update': now, 'error': "test error" }, "OCCUPANCY_GIF": { 'last_update': now - datetime.timedelta(seconds=1) } } } before_complete = webui.last_notice updates=webui.process_tasks() self.assertEqual(updates[0][0][0], 'lifestage_test') self.assertEqual(updates[0][0][1], 'OCCUPANCY_GIF') self.assertEqual(updates[0][1][1], 'RUN') before_complete = webui.last_notice # ensure error message disappears updates=webui.process_tasks() self.assertEqual(webui.last_notice, before_complete) self.assertEqual(len(updates[0]), 1)