class TestURLCase(unittest.TestCase): def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db() self.app = api.app.test_client() # Replace the real production DB w/ a testing DB api.db = self.sql_db api.UPLOAD_FOLDER = TEST_UPLOAD_FOLDER if not os.path.isdir(api.UPLOAD_FOLDER): os.makedirs(api.UPLOAD_FOLDER) api.multiscanner_process = fake_multiscanner_process def test_index(self): expected_response = {'Message': 'True'} resp = self.app.get('/') self.assertEqual(resp.status_code, api.HTTP_OK) self.assertEqual(json.loads(resp.data), expected_response) def test_empty_db(self): expected_response = {'Tasks': []} resp = self.app.get('/api/v1/tasks/list/') self.assertEqual(resp.status_code, api.HTTP_OK) self.assertEqual(json.loads(resp.data), expected_response) def test_create_first_task(self): expected_response = {'Message': {'task_id': 1}} resp = post_file(self.app) self.assertEqual(resp.status_code, api.HTTP_CREATED) self.assertEqual(json.loads(resp.data), expected_response) def tearDown(self): # Clean up Test DB and upload folder os.remove(TEST_DB_PATH) shutil.rmtree(TEST_UPLOAD_FOLDER)
class TestTaskDeleteCase(unittest.TestCase): def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db() self.app = api.app.test_client() # Replace the real production DB w/ a testing DB api.db = self.sql_db api.UPLOAD_FOLDER = TEST_UPLOAD_FOLDER if not os.path.isdir(api.UPLOAD_FOLDER): os.makedirs(api.UPLOAD_FOLDER) # populate the DB w/ a task post_file(self.app) def test_delete_task(self): expected_response = {'Message': 'Deleted'} resp = self.app.get('/api/v1/tasks/delete/1') self.assertEqual(resp.status_code, api.HTTP_OK) self.assertDictEqual(json.loads(resp.data), expected_response) def test_delete_nonexistent_task(self): expected_response = api.TASK_NOT_FOUND resp = self.app.get('/api/v1/tasks/delete/2') self.assertEqual(resp.status_code, api.HTTP_NOT_FOUND) self.assertDictEqual(json.loads(resp.data), expected_response) def tearDown(self): # Clean up Test DB and upload folder os.remove(TEST_DB_PATH) shutil.rmtree(TEST_UPLOAD_FOLDER)
class TestDBInit(unittest.TestCase): def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db() def test_db_init(self): self.assertEqual("SQLite 3.x database", magic.from_file(TEST_DB_PATH)) def tearDown(self): os.remove(TEST_DB_PATH)
class TestDBInit(unittest.TestCase): def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db() def test_db_init(self): self.assertEqual('SQLite 3.x database', magic.from_file(TEST_DB_PATH)) def tearDown(self): os.remove(TEST_DB_PATH)
def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db() self.app = api.app.test_client() # Replace the real production DB w/ a testing DB api.db = self.sql_db api.UPLOAD_FOLDER = TEST_UPLOAD_FOLDER if not os.path.isdir(api.UPLOAD_FOLDER): os.makedirs(api.UPLOAD_FOLDER) api.multiscanner_process = fake_multiscanner_process
def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db() self.app = api.app.test_client() # Replace the real production DB w/ a testing DB api.db = self.sql_db api.UPLOAD_FOLDER = TEST_UPLOAD_FOLDER if not os.path.isdir(api.UPLOAD_FOLDER): os.makedirs(api.UPLOAD_FOLDER) # populate the DB w/ a task post_file(self.app)
class TestTaskAdd(unittest.TestCase): def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_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): os.remove(TEST_DB_PATH)
class TestTaskCreateCase(unittest.TestCase): def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db() self.app = api.app.test_client() # Replace the real production DB w/ a testing DB api.db = self.sql_db api.UPLOAD_FOLDER = TEST_UPLOAD_FOLDER if not os.path.isdir(api.UPLOAD_FOLDER): os.makedirs(api.UPLOAD_FOLDER) api.multiscanner_process = fake_multiscanner_process # populate the DB w/ a task post_file(self.app) def test_get_task(self): expected_response = { 'Task': { 'task_id': 1, 'task_status': 'Pending', 'report_id': None } } resp = self.app.get('/api/v1/tasks/list/1') self.assertEqual(resp.status_code, api.HTTP_OK) self.assertDictEqual(json.loads(resp.data), expected_response) def test_get_nonexistent_task(self): expected_response = api.TASK_NOT_FOUND resp = self.app.get('/api/v1/tasks/list/2') self.assertEqual(resp.status_code, api.HTTP_NOT_FOUND) self.assertDictEqual(json.loads(resp.data), expected_response) def test_get_task_list(self): # expected_response = {'Tasks': [{'report_id': None, 'task_id': 1, 'task_status': 'Pending'}]} expected_response = { 'Tasks': [{ 'task_id': 1, 'task_status': 'Pending', 'report_id': None }] } resp = self.app.get('/api/v1/tasks/list/') self.assertEqual(resp.status_code, api.HTTP_OK) self.assertDictEqual(json.loads(resp.data), expected_response) def tearDown(self): # Clean up Test DB and upload folder os.remove(TEST_DB_PATH) shutil.rmtree(TEST_UPLOAD_FOLDER)
class TestTaskAdd(unittest.TestCase): def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_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): os.remove(TEST_DB_PATH)
class TestGetAllTasks(unittest.TestCase): def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_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, "task_status": "Pending", "report_id": 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): os.remove(TEST_DB_PATH)
def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db() self.sql_db.add_task( task_id=1, task_status='Pending', report_id=None )
class TestTaskCreateCase(unittest.TestCase): def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db() self.app = api.app.test_client() # Replace the real production DB w/ a testing DB api.db = self.sql_db api.UPLOAD_FOLDER = TEST_UPLOAD_FOLDER if not os.path.isdir(api.UPLOAD_FOLDER): os.makedirs(api.UPLOAD_FOLDER) api.multiscanner_process = fake_multiscanner_process # populate the DB w/ a task post_file(self.app) def test_get_task(self): expected_response = { 'Task': { 'task_id': 1, 'task_status': 'Pending', 'report_id': None } } resp = self.app.get('/api/v1/tasks/list/1') self.assertEqual(resp.status_code, api.HTTP_OK) self.assertDictEqual(json.loads(resp.data), expected_response) def test_get_nonexistent_task(self): expected_response = api.TASK_NOT_FOUND resp = self.app.get('/api/v1/tasks/list/2') self.assertEqual(resp.status_code, api.HTTP_NOT_FOUND) self.assertDictEqual(json.loads(resp.data), expected_response) def test_get_task_list(self): # expected_response = {'Tasks': [{'report_id': None, 'task_id': 1, 'task_status': 'Pending'}]} expected_response = {'Tasks': [{'task_id': 1, 'task_status': 'Pending', 'report_id': None}]} resp = self.app.get('/api/v1/tasks/list/') self.assertEqual(resp.status_code, api.HTTP_OK) self.assertDictEqual(json.loads(resp.data), expected_response) def tearDown(self): # Clean up Test DB and upload folder os.remove(TEST_DB_PATH) shutil.rmtree(TEST_UPLOAD_FOLDER)
class TestGetAllTasks(unittest.TestCase): def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_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, 'task_status': 'Pending', 'report_id': 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): os.remove(TEST_DB_PATH)
class TestTaskManipulation(unittest.TestCase): def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db() self.sql_db.add_task(task_id=1, 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): os.remove(TEST_DB_PATH)
class TestTaskManipulation(unittest.TestCase): def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db() self.sql_db.add_task(task_id=1, 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): os.remove(TEST_DB_PATH)
def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db() self.sql_db.add_task(task_id=1, task_status='Pending', report_id=None)
def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db() for i in range(0, 3): self.sql_db.add_task() i += 1
def setUp(self): self.sql_db = Database(TEST_DB_PATH) self.sql_db.init_sqlite_db()