class TestTaskManipulation(unittest.TestCase): def setUp(self): self.sql_db = Database(config=DB_CONF) self.sql_db.init_db() self.sql_db.add_task(task_status='Pending', report_id=None) def test_add_second_task(self): resp = self.sql_db.add_task() self.assertEqual(resp, 2) def test_get_task(self): resp = self.sql_db.get_task(task_id=1) self.assertEqual(resp.task_id, 1) self.assertEqual(resp.task_status, 'Pending') self.assertEqual(resp.report_id, None) def test_update_task(self): resp = self.sql_db.update_task( task_id=1, task_status='Complete', report_id= '88d11f0ea5cc77a59b6e47deee859440f26d2d14440beb712dbac8550d35ef1f') self.assertDictEqual(resp, self.sql_db.get_task(1).to_dict()) self.assertDictEqual( resp, { 'task_id': 1, 'task_status': 'Complete', 'report_id': '88d11f0ea5cc77a59b6e47deee859440f26d2d14440beb712dbac8550d35ef1f' }) def test_delete_task(self): deleted = self.sql_db.delete_task(task_id=1) self.assertTrue(deleted) resp = self.sql_db.get_task(task_id=1) self.assertEqual(resp, None) def tearDown(self): if DB_CONF['db_type'] == 'sqlite': os.remove(TEST_DB_PATH) else: drop_db_table(self.sql_db._get_db_engine())
class TestTaskManipulation(unittest.TestCase): def setUp(self): self.sql_db = Database(config=DB_CONF) self.sql_db.init_db() self.sql_db.add_task(task_status='Pending', ) def test_add_second_task(self): resp = self.sql_db.add_task() self.assertEqual(resp, 2) def test_get_task(self): resp = self.sql_db.get_task(task_id=1) self.assertEqual(resp.task_id, 1) self.assertEqual(resp.task_status, 'Pending') self.assertEqual(resp.sample_id, None) self.assertEqual(resp.timestamp, None) def test_update_task(self): resp = self.sql_db.update_task( task_id=1, task_status='Complete', ) self.assertDictEqual(resp, self.sql_db.get_task(1).to_dict()) self.assertDictEqual( resp, { 'task_id': 1, 'sample_id': None, 'task_status': 'Complete', 'timestamp': None }) def test_delete_task(self): deleted = self.sql_db.delete_task(task_id=1) self.assertTrue(deleted) resp = self.sql_db.get_task(task_id=1) self.assertEqual(resp, None) def tearDown(self): if DB_CONF['db_type'] == 'sqlite': os.remove(TEST_DB_PATH) else: drop_db_table(self.sql_db.db_engine)