def test_current_task_lock(self): database = factory.DatabaseFactory() task1 = TaskHistoryFactory() task2 = TaskHistoryFactory() database.pin_task(task1) self.assertFalse(database.pin_task(task2)) database.unpin_task() self.assertTrue(database.pin_task(task2))
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_task_with_error(self, add_access): add_access.side_effect = Exception('Fake error') task = TaskHistoryFactory() self.assertIsNone(task.details) self.assertFalse(purge_unused_exports(task)) self.assertIn('Removing: {}'.format(self.export), task.details) self.assertIn('Error: Fake error'.format(self.export), task.details)
def test_task_with_success(self, delete_export_method): task = TaskHistoryFactory() self.assertIsNone(task.details) self.assertTrue(purge_unused_exports(task)) self.assertEqual(0, len(self.exports)) self.assertNotIn(self.export, self.exports) self.assertIn('Removing: {}'.format(self.export), task.details) self.assertIn('Success', task.details) delete_export_method.assert_called() delete_export_method.assert_called_once_with( self.environment, self.export.nfsaas_path_host)
def test_task_with_error(self, delete_export_method): delete_export_method.side_effect = Exception('Fake error') task = TaskHistoryFactory() self.assertIsNone(task.details) self.assertFalse(purge_unused_exports(task)) self.assertEqual(1, len(self.exports)) self.assertIn(self.export, self.exports) self.assertIn('Removing: {}'.format(self.export), task.details) self.assertIn('Error: Fake error'.format(self.export), task.details) delete_export_method.assert_called() delete_export_method.assert_called_once_with( self.environment, self.export.nfsaas_path_host)
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))
def setUp(self): self.fake_task = TaskHistoryFactory.build() self.fake_task.user = '******' self.fake_task.task_name = 'notification.fake.fake_task' self.fake_task.id = 123 self.fake_task.task_status = 'SUCCESS' self.fake_task.updated_at = datetime(2017, 7, 27, 14, 39, 22, 160307) self.fake_task.arguments = 'Database: database_fake, New Disk Offering: Micro' self.default_expected_params = { u'task_id': self.fake_task.id, u'task_name': u'fake_task', u'task_status': 'SUCCESS', u'user': '******', u'arguments': self.fake_task.arguments, u'updated_at': 1501177162, u'is_new': 1, u'read': 0, }
def setUp(self): self.fake_task = TaskHistoryFactory.build() self.fake_task.user = '******' self.fake_task.task_name = 'notification.fake.fake_task' self.fake_task.id = 123 self.fake_task.task_status = 'SUCCESS' self.fake_task.updated_at = datetime(2017, 7, 27, 14, 39, 22, 160307) self.fake_task.arguments = 'Database: database_fake, New Disk Offering: Micro' self.fake_task.database_name = 'database_fake' self.default_expected_params = { u'task_id': self.fake_task.id, u'task_name': u'fake_task', u'task_status': 'SUCCESS', u'user': '******', u'arguments': self.fake_task.arguments, u'database_name': 'database_fake', u'updated_at': 1501177162, u'is_new': 1, u'read': 0, }
def setUp(self): self.task = TaskHistoryFactory()
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)
def setUp(self): self.task = TaskHistoryFactory(task_status=TaskHistory.STATUS_WARNING)
def setUp(self): self.task = TaskHistoryFactory( task_status=TaskHistory.STATUS_WARNING )
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)
def test_task_with_success(self): task = TaskHistoryFactory() self.assertIsNone(task.details) self.assertTrue(purge_unused_exports(task)) self.assertIn('Removing: {}'.format(self.export), task.details) self.assertIn('Success', task.details)
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))
def setUp(self): self.fake_database_create = DatabaseCreate() self.fake_database_create.task = TaskHistoryFactory.build() self.fake_database = Database()
def setUpClass(self): self.database = DatabaseFactory() self.task = TaskHistoryFactory( object_class=self.database._meta.db_table, object_id=self.database.id, task_status=TaskHistory.STATUS_WAITING)