class TestStressTest(unittest.TestCase): def setUp(self): self.sql_db = Database(config=DB_CONF) self.sql_db.init_db() for i in range(0, 1000): self.sql_db.add_task() i += 1 def test_get_all_tasks(self): for i in range(1, 1000): self.sql_db.get_task(task_id=i) def tearDown(self): if DB_CONF['db_type'] == 'sqlite': os.remove(TEST_DB_PATH) else: drop_db_table(self.sql_db.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', 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)
class TestGetAllTasks(unittest.TestCase): def setUp(self): self.sql_db = Database(config=DB_CONF) self.sql_db.init_db() for i in range(0, 3): self.sql_db.add_task() i += 1 def test_get_all_tasks(self): expected_response = [ {'task_id': i, 'sample_id': None, 'task_status': 'Pending', 'timestamp': None} for i in range(1, 4) ] resp = self.sql_db.get_all_tasks() for i in range(0, 3): self.assertDictEqual(expected_response[i], resp[i]) def tearDown(self): if DB_CONF['db_type'] == 'sqlite': os.remove(TEST_DB_PATH) else: drop_db_table(self.sql_db.db_engine)
class TestTaskAdd(unittest.TestCase): def setUp(self): self.sql_db = Database(config=DB_CONF) self.sql_db.init_db() def test_add_task(self): task_id = 1 resp = self.sql_db.add_task(task_id=task_id, task_status='Pending', report_id=None) self.assertEqual(resp, task_id) def tearDown(self): if DB_CONF['db_type'] == 'sqlite': os.remove(TEST_DB_PATH) else: drop_db_table(self.sql_db._get_db_engine())