diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index be851075f1b3..e6a4842ba0fa 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -80,7 +80,7 @@ def _test_create_job_fails( return response @pytest.mark.parametrize("task_mode", ["annotation", "interpolation"]) - def test_can_create_gt_job_with_manual_frames(self, admin_user, tasks, task_mode): + def test_can_create_gt_job_with_manual_frames(self, admin_user, tasks, jobs, task_mode): user = admin_user job_frame_count = 4 task = next( @@ -90,6 +90,7 @@ def test_can_create_gt_job_with_manual_frames(self, admin_user, tasks, task_mode and not t["organization"] and t["mode"] == task_mode and t["size"] > job_frame_count + and not any(j for j in jobs if j["task_id"] == t["id"] and j["type"] == "ground_truth") ) task_id = task["id"] with make_api_client(user) as api_client: @@ -116,7 +117,7 @@ def test_can_create_gt_job_with_manual_frames(self, admin_user, tasks, task_mode assert job_frame_ids == gt_job_meta.included_frames @pytest.mark.parametrize("task_mode", ["annotation", "interpolation"]) - def test_can_create_gt_job_with_random_frames(self, admin_user, tasks, task_mode): + def test_can_create_gt_job_with_random_frames(self, admin_user, tasks, jobs, task_mode): user = admin_user job_frame_count = 3 required_task_frame_count = job_frame_count + 1 @@ -127,6 +128,7 @@ def test_can_create_gt_job_with_random_frames(self, admin_user, tasks, task_mode and not t["organization"] and t["mode"] == task_mode and t["size"] > required_task_frame_count + and not any(j for j in jobs if j["task_id"] == t["id"] and j["type"] == "ground_truth") ) task_id = task["id"] @@ -574,9 +576,13 @@ def test_get_gt_job_in_org_task( "restore_db_per_class" ) class TestGetGtJobData: - @pytest.mark.usefixtures("restore_db_per_function") + + def _delete_gt_job(self, user, gt_job_id): + with make_api_client(user) as api_client: + api_client.jobs_api.destroy(gt_job_id) + @pytest.mark.parametrize("task_mode", ["annotation", "interpolation"]) - def test_can_get_gt_job_meta(self, admin_user, tasks, task_mode): + def test_can_get_gt_job_meta(self, admin_user, tasks, jobs, task_mode, request): user = admin_user job_frame_count = 4 task = next( @@ -586,6 +592,7 @@ def test_can_get_gt_job_meta(self, admin_user, tasks, task_mode): and not t["organization"] and t["mode"] == task_mode and t["size"] > job_frame_count + and not any(j for j in jobs if j["task_id"] == t["id"] and j["type"] == "ground_truth") ) task_id = task["id"] with make_api_client(user) as api_client: @@ -595,11 +602,13 @@ def test_can_get_gt_job_meta(self, admin_user, tasks, task_mode): job_frame_ids = list(range(task_meta.start_frame, task_meta.stop_frame, frame_step))[ :job_frame_count ] - gt_job = self._get_or_create_gt_job(admin_user, task_id, job_frame_ids) + gt_job = self._create_gt_job(admin_user, task_id, job_frame_ids) with make_api_client(user) as api_client: (gt_job_meta, _) = api_client.jobs_api.retrieve_data_meta(gt_job.id) + request.addfinalizer(lambda: self._delete_gt_job(user, gt_job.id)) + # These values are relative to the resulting task frames, unlike meta values assert 0 == gt_job.start_frame assert task_meta.size - 1 == gt_job.stop_frame @@ -622,8 +631,7 @@ def test_can_get_gt_job_meta(self, admin_user, tasks, task_mode): else: assert False - @pytest.mark.usefixtures("restore_db_per_function") - def test_can_get_gt_job_meta_with_complex_frame_setup(self, admin_user): + def test_can_get_gt_job_meta_with_complex_frame_setup(self, admin_user, request): image_count = 50 start_frame = 3 stop_frame = image_count - 4 @@ -649,11 +657,13 @@ def test_can_get_gt_job_meta_with_complex_frame_setup(self, admin_user): task_frame_ids = range(start_frame, stop_frame, frame_step) job_frame_ids = list(task_frame_ids[::3]) - gt_job = self._get_or_create_gt_job(admin_user, task_id, job_frame_ids) + gt_job = self._create_gt_job(admin_user, task_id, job_frame_ids) with make_api_client(admin_user) as api_client: (gt_job_meta, _) = api_client.jobs_api.retrieve_data_meta(gt_job.id) + request.addfinalizer(lambda: self._delete_gt_job(admin_user, gt_job.id)) + # These values are relative to the resulting task frames, unlike meta values assert 0 == gt_job.start_frame assert len(task_frame_ids) - 1 == gt_job.stop_frame @@ -674,7 +684,7 @@ def test_can_get_gt_job_meta_with_complex_frame_setup(self, admin_user): @pytest.mark.parametrize("task_mode", ["annotation", "interpolation"]) @pytest.mark.parametrize("quality", ["compressed", "original"]) - def test_can_get_gt_job_chunk(self, admin_user, tasks, task_mode, quality): + def test_can_get_gt_job_chunk(self, admin_user, tasks, jobs, task_mode, quality, request): user = admin_user job_frame_count = 4 task = next( @@ -684,6 +694,7 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, task_mode, quality): and not t["organization"] and t["mode"] == task_mode and t["size"] > job_frame_count + and not any(j for j in jobs if j["task_id"] == t["id"] and j["type"] == "ground_truth") ) task_id = task["id"] with make_api_client(user) as api_client: @@ -693,7 +704,7 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, task_mode, quality): job_frame_ids = list(range(task_meta.start_frame, task_meta.stop_frame, frame_step))[ :job_frame_count ] - gt_job = self._get_or_create_gt_job(admin_user, task_id, job_frame_ids) + gt_job = self._create_gt_job(admin_user, task_id, job_frame_ids) with make_api_client(admin_user) as api_client: (chunk_file, response) = api_client.jobs_api.retrieve_data( @@ -701,6 +712,8 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, task_mode, quality): ) assert response.status == HTTPStatus.OK + request.addfinalizer(lambda: self._delete_gt_job(admin_user, gt_job.id)) + frame_range = range( task_meta.start_frame, min(task_meta.stop_frame + 1, task_meta.chunk_size), frame_step ) @@ -724,26 +737,29 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, task_mode, quality): assert image.size > (1, 1) assert np.any(image_data != 0) - def _get_or_create_gt_job(self, user, task_id, frames): + def _create_gt_job(self, user, task_id, frames): with make_api_client(user) as api_client: - (task_jobs, _) = api_client.jobs_api.list(task_id=task_id, type="ground_truth") - if task_jobs.results: - gt_job = task_jobs.results[0] - else: - job_spec = { - "task_id": task_id, - "type": "ground_truth", - "frame_selection_method": "manual", - "frames": frames, - } + job_spec = { + "task_id": task_id, + "type": "ground_truth", + "frame_selection_method": "manual", + "frames": frames, + } + + (gt_job, _) = api_client.jobs_api.create(job_spec) + + return gt_job - (gt_job, _) = api_client.jobs_api.create(job_spec) + def _get_gt_job(self, user, task_id): + with make_api_client(user) as api_client: + (task_jobs, _) = api_client.jobs_api.list(task_id=task_id, type="ground_truth") + gt_job = task_jobs.results[0] return gt_job @pytest.mark.parametrize("task_mode", ["annotation", "interpolation"]) @pytest.mark.parametrize("quality", ["compressed", "original"]) - def test_can_get_gt_job_frame(self, admin_user, tasks, task_mode, quality): + def test_can_get_gt_job_frame(self, admin_user, tasks, jobs, task_mode, quality, request): user = admin_user job_frame_count = 4 task = next( @@ -753,6 +769,7 @@ def test_can_get_gt_job_frame(self, admin_user, tasks, task_mode, quality): and not t["organization"] and t["mode"] == task_mode and t["size"] > job_frame_count + and not any(j for j in jobs if j["task_id"] == t["id"] and j["type"] == "ground_truth") ) task_id = task["id"] with make_api_client(user) as api_client: @@ -762,7 +779,7 @@ def test_can_get_gt_job_frame(self, admin_user, tasks, task_mode, quality): job_frame_ids = list(range(task_meta.start_frame, task_meta.stop_frame, frame_step))[ :job_frame_count ] - gt_job = self._get_or_create_gt_job(admin_user, task_id, job_frame_ids) + gt_job = self._create_gt_job(admin_user, task_id, job_frame_ids) frame_range = range( task_meta.start_frame, min(task_meta.stop_frame + 1, task_meta.chunk_size), frame_step @@ -787,6 +804,8 @@ def test_can_get_gt_job_frame(self, admin_user, tasks, task_mode, quality): ) assert response.status == HTTPStatus.OK + request.addfinalizer(lambda: self._delete_gt_job(admin_user, gt_job.id)) + @pytest.mark.usefixtures("restore_db_per_class") class TestListJobs: