def test_find_tasks_running(self): task_running = TaskHistoryFactory() task_running.task_status = TaskHistory.STATUS_RUNNING task_running.save() task_pending = TaskHistoryFactory() url = reverse(running_tasks_api) response = self.client.get(url) tasks = loads(response.content) self.assertIn(str(task_running.id), tasks) self.assertEqual(tasks[str(task_running.id)], task_running.task_name) self.assertNotIn(str(task_pending.id), tasks)
def test_find_tasks_waiting(self): task_waiting = TaskHistoryFactory() task_waiting.task_status = TaskHistory.STATUS_WAITING task_waiting.save() task_pending = TaskHistoryFactory() url = reverse(waiting_tasks_api) response = self.client.get(url) tasks = loads(response.content) self.assertIn(str(task_waiting.id), tasks) self.assertEqual(tasks[str(task_waiting.id)], task_waiting.task_name) self.assertNotIn(str(task_pending.id), tasks)
def test_lock_retry(self): database = factory.DatabaseFactory() task1 = TaskHistoryFactory() task2 = TaskHistoryFactory() task3 = TaskHistoryFactory() task1.task_status = TaskHistory.STATUS_ERROR task1.save() task2.task_name = task1.task_name task2.save() database.pin_task(task1) self.assertFalse(database.update_task(task3)) self.assertTrue(database.update_task(task2)) self.assertFalse(database.update_task(task2)) database.unpin_task() self.assertTrue(database.pin_task(task3))
class TaskHistoryTestCase(TestCase): def setUp(self): self.task = TaskHistoryFactory() def test_can_add_message_detail(self): self.assertIsNone(self.task.details) self.task.add_detail(message='Testing') self.assertEqual('Testing', self.task.details) self.task.add_detail(message='Again, with new line') self.assertEqual('Testing\nAgain, with new line', self.task.details) def test_can_add_message_detail_with_level(self): self.assertIsNone(self.task.details) self.task.add_detail(message='Testing', level=1) self.assertEqual('-> Testing', self.task.details) self.task.add_detail(message='Again, with new line', level=2) self.assertEqual('-> Testing\n--> Again, with new line', self.task.details) def test_can_add_step(self): self.assertIsNone(self.task.details) step = 1 total = 15 description = 'testing' message = '- Step {} of {} - {}'.format(step, total, description) self.task.add_step(step=step, total=total, description=description) self.assertIn(message, self.task.details) def test_can_get_running_tasks(self): self.task.task_status = TaskHistory.STATUS_RUNNING self.task.save() tasks = TaskHistory.running_tasks() self.assertIsNotNone(tasks) self.assertIn(self.task, tasks) def test_can_get_running_tasks_empty(self): tasks = TaskHistory.running_tasks() self.assertEqual(len(tasks), 0) def test_can_get_waiting_tasks(self): self.task.task_status = TaskHistory.STATUS_WAITING self.task.save() tasks = TaskHistory.waiting_tasks() self.assertIsNotNone(tasks) self.assertIn(self.task, tasks) def test_can_get_waiting_tasks_empty(self): tasks = TaskHistory.waiting_tasks() self.assertEqual(len(tasks), 0) def test_is_running(self): self.task.task_status = TaskHistory.STATUS_RUNNING self.assertTrue(self.task.is_running) def test_is_not_running(self): self.task.task_status = TaskHistory.STATUS_SUCCESS self.assertFalse(self.task.is_running)
class TaskHistoryTestCase(TestCase): def setUp(self): self.task = TaskHistoryFactory( task_status=TaskHistory.STATUS_WARNING ) def test_can_add_message_detail(self): self.assertIsNone(self.task.details) self.task.add_detail(message='Testing') self.assertEqual('Testing', self.task.details) self.task.add_detail(message='Again, with new line') self.assertEqual('Testing\nAgain, with new line', self.task.details) def test_can_add_message_detail_with_level(self): self.assertIsNone(self.task.details) self.task.add_detail(message='Testing', level=1) self.assertEqual('-> Testing', self.task.details) self.task.add_detail(message='Again, with new line', level=2) self.assertEqual('-> Testing\n--> Again, with new line', self.task.details) def test_can_add_step(self): self.assertIsNone(self.task.details) step = 1 total = 15 description = 'testing' message = '- Step {} of {} - {}'.format(step, total, description) self.task.add_step(step=step, total=total, description=description) self.assertIn(message, self.task.details) def test_can_get_running_tasks(self): self.task.task_status = TaskHistory.STATUS_RUNNING self.task.save() tasks = TaskHistory.running_tasks() self.assertIsNotNone(tasks) self.assertIn(self.task, tasks) def test_can_get_running_tasks_empty(self): tasks = TaskHistory.running_tasks() self.assertEqual(len(tasks), 0) def test_can_get_waiting_tasks(self): self.task.task_status = TaskHistory.STATUS_WAITING self.task.save() tasks = TaskHistory.waiting_tasks() self.assertIsNotNone(tasks) self.assertIn(self.task, tasks) def test_can_get_waiting_tasks_empty(self): tasks = TaskHistory.waiting_tasks() self.assertEqual(len(tasks), 0) def test_is_running(self): self.task.task_status = TaskHistory.STATUS_RUNNING self.assertTrue(self.task.is_running) def test_is_not_running(self): self.task.task_status = TaskHistory.STATUS_SUCCESS self.assertFalse(self.task.is_running) def test_is_error(self): self.task.task_status = TaskHistory.STATUS_ERROR self.assertTrue(self.task.is_status_error) def test_is_not_error(self): self.task.task_status = TaskHistory.STATUS_SUCCESS self.assertFalse(self.task.is_status_error)