From 4f1666c756db7b651dbcb070d18b673d1852b3ab Mon Sep 17 00:00:00 2001 From: vidit Date: Sun, 17 Mar 2024 19:35:29 +0530 Subject: [PATCH 01/13] added filter to not include gt_job when the test intends to create one. --- tests/python/rest_api/test_jobs.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index be851075f1b3..1c43556b8a34 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"] @@ -576,7 +578,7 @@ def test_get_gt_job_in_org_task( class TestGetGtJobData: @pytest.mark.usefixtures("restore_db_per_function") @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): user = admin_user job_frame_count = 4 task = next( @@ -586,6 +588,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: @@ -674,7 +677,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): user = admin_user job_frame_count = 4 task = next( @@ -684,6 +687,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: @@ -728,6 +732,7 @@ def _get_or_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: + # TODO: to modify this to only get gt_job only with the mentioned frames gt_job = task_jobs.results[0] else: job_spec = { @@ -743,7 +748,7 @@ def _get_or_create_gt_job(self, user, task_id, frames): @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): user = admin_user job_frame_count = 4 task = next( @@ -753,6 +758,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: From 2d85a435982057cce2a981a4743272b2880eaee8 Mon Sep 17 00:00:00 2001 From: Vidit Agarwal Date: Mon, 18 Mar 2024 18:07:02 +0530 Subject: [PATCH 02/13] added check to if specific frames are requested then there shouldn't be a gt_job --- tests/python/rest_api/test_jobs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index 1c43556b8a34..c34306e6b49d 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -732,7 +732,7 @@ def _get_or_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: - # TODO: to modify this to only get gt_job only with the mentioned frames + assert not frames, "specific frames requested but gt_job exists" gt_job = task_jobs.results[0] else: job_spec = { From b6b9052a7fe89389347b6c9a15ea2f4e0e024b25 Mon Sep 17 00:00:00 2001 From: vidit Date: Mon, 18 Mar 2024 23:46:49 +0530 Subject: [PATCH 03/13] restoring testing database to original state after each test --- tests/python/rest_api/test_jobs.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index c34306e6b49d..510fd6c9ea35 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -704,6 +704,8 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, jobs, task_mode, quality) gt_job.id, number=0, quality=quality, type="chunk" ) assert response.status == HTTPStatus.OK + (_, gt_job_del_response) = api_client.jobs_api.destroy(gt_job.id) + assert gt_job_del_response.status == HTTPStatus.NO_CONTENT, "newly created gt_job couldn't be deleted" frame_range = range( task_meta.start_frame, min(task_meta.stop_frame + 1, task_meta.chunk_size), frame_step @@ -746,6 +748,7 @@ def _get_or_create_gt_job(self, user, task_id, frames): return gt_job + @pytest.mark.usefixtures("restore_db_per_function") @pytest.mark.parametrize("task_mode", ["annotation", "interpolation"]) @pytest.mark.parametrize("quality", ["compressed", "original"]) def test_can_get_gt_job_frame(self, admin_user, tasks, jobs, task_mode, quality): From 3fd9460be3229639defcb9f530a9d0338fd31cae Mon Sep 17 00:00:00 2001 From: vidit Date: Tue, 19 Mar 2024 00:07:23 +0530 Subject: [PATCH 04/13] linted tests --- tests/python/rest_api/test_jobs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index 510fd6c9ea35..5f2f1ebd5cdb 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -705,7 +705,9 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, jobs, task_mode, quality) ) assert response.status == HTTPStatus.OK (_, gt_job_del_response) = api_client.jobs_api.destroy(gt_job.id) - assert gt_job_del_response.status == HTTPStatus.NO_CONTENT, "newly created gt_job couldn't be deleted" + assert ( + gt_job_del_response.status == HTTPStatus.NO_CONTENT + ), "newly created gt_job couldn't be deleted" frame_range = range( task_meta.start_frame, min(task_meta.stop_frame + 1, task_meta.chunk_size), frame_step From e69a4d16fbd677a96fd00387b71ca2e708ef7919 Mon Sep 17 00:00:00 2001 From: vidit Date: Tue, 19 Mar 2024 23:14:52 +0530 Subject: [PATCH 05/13] added request.addfinalizer to remove created gt_jobs --- tests/python/rest_api/test_jobs.py | 38 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index 5f2f1ebd5cdb..c1a1402c51f8 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -569,16 +569,18 @@ def test_get_gt_job_in_org_task( self._test_get_job_403(user["username"], job["id"]) -@pytest.mark.usefixtures( - # if the db is restored per test, there are conflicts with the server data cache - # if we don't clean the db, the gt jobs created will be reused, and their - # ids won't conflict - "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: + (_, gt_job_del_response) = api_client.jobs_api.destroy(gt_job_id) + assert ( + gt_job_del_response.status == HTTPStatus.NO_CONTENT + ), "newly created gt_job couldn't be deleted" + + # @pytest.fixture @pytest.mark.parametrize("task_mode", ["annotation", "interpolation"]) - def test_can_get_gt_job_meta(self, admin_user, tasks, jobs, 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( @@ -603,6 +605,8 @@ def test_can_get_gt_job_meta(self, admin_user, tasks, jobs, task_mode): 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 @@ -625,8 +629,7 @@ def test_can_get_gt_job_meta(self, admin_user, tasks, jobs, 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 @@ -657,6 +660,8 @@ def test_can_get_gt_job_meta_with_complex_frame_setup(self, admin_user): 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 @@ -677,7 +682,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, jobs, 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( @@ -704,10 +709,8 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, jobs, task_mode, quality) gt_job.id, number=0, quality=quality, type="chunk" ) assert response.status == HTTPStatus.OK - (_, gt_job_del_response) = api_client.jobs_api.destroy(gt_job.id) - assert ( - gt_job_del_response.status == HTTPStatus.NO_CONTENT - ), "newly created gt_job couldn't be deleted" + + 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 @@ -750,10 +753,9 @@ def _get_or_create_gt_job(self, user, task_id, frames): return gt_job - @pytest.mark.usefixtures("restore_db_per_function") @pytest.mark.parametrize("task_mode", ["annotation", "interpolation"]) @pytest.mark.parametrize("quality", ["compressed", "original"]) - def test_can_get_gt_job_frame(self, admin_user, tasks, jobs, 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( @@ -798,6 +800,8 @@ def test_can_get_gt_job_frame(self, admin_user, tasks, jobs, 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: From 2a547c7c1fa4363ab689b6f46845873865f7695a Mon Sep 17 00:00:00 2001 From: Vidit Agarwal Date: Wed, 20 Mar 2024 02:46:29 +0530 Subject: [PATCH 06/13] made testing db revert to original state after running TestGetGtJobData --- tests/python/rest_api/test_jobs.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index c1a1402c51f8..a914de03f11c 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -568,7 +568,12 @@ def test_get_gt_job_in_org_task( else: self._test_get_job_403(user["username"], job["id"]) - +@pytest.mark.usefixtures( + # if the db is restored per test, there are conflicts with the server data cache + # if we don't clean the db, the gt jobs created will be reused, and their + # ids won't conflict + "restore_db_per_class" +) class TestGetGtJobData: def delete_gt_job(self, user, gt_job_id): From eefa0f669d3ed4cb89219c0d51e443b39b6633f3 Mon Sep 17 00:00:00 2001 From: Vidit Agarwal Date: Wed, 20 Mar 2024 02:48:04 +0530 Subject: [PATCH 07/13] fixed linting --- tests/python/rest_api/test_jobs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index a914de03f11c..511b3e5b12f1 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -568,6 +568,7 @@ def test_get_gt_job_in_org_task( else: self._test_get_job_403(user["username"], job["id"]) + @pytest.mark.usefixtures( # if the db is restored per test, there are conflicts with the server data cache # if we don't clean the db, the gt jobs created will be reused, and their From 40f1e96906734e07f5529d6b7d362a0f95339e14 Mon Sep 17 00:00:00 2001 From: vidit Date: Wed, 20 Mar 2024 23:33:36 +0530 Subject: [PATCH 08/13] reformatted function name of helper method --- tests/python/rest_api/test_jobs.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index c1a1402c51f8..ea5f60917a36 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -571,14 +571,14 @@ def test_get_gt_job_in_org_task( class TestGetGtJobData: - def delete_gt_job(self, user, gt_job_id): + def _delete_gt_job(self, user, gt_job_id): with make_api_client(user) as api_client: (_, gt_job_del_response) = api_client.jobs_api.destroy(gt_job_id) assert ( gt_job_del_response.status == HTTPStatus.NO_CONTENT ), "newly created gt_job couldn't be deleted" - # @pytest.fixture + @pytest.mark.parametrize("task_mode", ["annotation", "interpolation"]) def test_can_get_gt_job_meta(self, admin_user, tasks, jobs, task_mode, request): user = admin_user @@ -721,6 +721,8 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, jobs, task_mode, quality, # with placeholders in the frames outside the job. # This is required by the UI implementation with zipfile.ZipFile(chunk_file) as chunk: + print(set(chunk.namelist())) + print(set("{:06d}.jpeg".format(i) for i in frame_range)) assert set(chunk.namelist()) == set("{:06d}.jpeg".format(i) for i in frame_range) for file_info in chunk.filelist: From 33af1b7455502053598ee6634fe1d7a8450fda1c Mon Sep 17 00:00:00 2001 From: vidit Date: Wed, 20 Mar 2024 23:44:55 +0530 Subject: [PATCH 09/13] split the get and create gt job function into two separate functions and refactored code accordingly --- tests/python/rest_api/test_jobs.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index 19cc6039ac24..6cd0b8ceccb9 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -584,7 +584,6 @@ def _delete_gt_job(self, user, gt_job_id): gt_job_del_response.status == HTTPStatus.NO_CONTENT ), "newly created gt_job couldn't be deleted" - @pytest.mark.parametrize("task_mode", ["annotation", "interpolation"]) def test_can_get_gt_job_meta(self, admin_user, tasks, jobs, task_mode, request): user = admin_user @@ -606,7 +605,7 @@ def test_can_get_gt_job_meta(self, admin_user, tasks, jobs, task_mode, request): 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) @@ -661,7 +660,7 @@ def test_can_get_gt_job_meta_with_complex_frame_setup(self, admin_user, request) 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) @@ -708,7 +707,7 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, jobs, 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( @@ -743,12 +742,11 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, jobs, 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: - assert not frames, "specific frames requested but gt_job exists" - gt_job = task_jobs.results[0] + raise RuntimeError(f"gt_job already exist for task {task_id}") else: job_spec = { "task_id": task_id, @@ -761,6 +759,16 @@ def _get_or_create_gt_job(self, user, task_id, frames): return gt_job + def _get_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: + raise RuntimeError(f"gt_job doesn't exist for task {task_id}") + + 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, jobs, task_mode, quality, request): @@ -783,7 +791,7 @@ def test_can_get_gt_job_frame(self, admin_user, tasks, jobs, 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 From 88bb859f81d481a39cf1162a79be486ee098c959 Mon Sep 17 00:00:00 2001 From: vidit Date: Thu, 21 Mar 2024 00:15:20 +0530 Subject: [PATCH 10/13] refactored the name change of delete gt job method --- tests/python/rest_api/test_jobs.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index 6cd0b8ceccb9..76854b5fe9b7 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -610,7 +610,7 @@ def test_can_get_gt_job_meta(self, admin_user, tasks, jobs, task_mode, request): 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)) + 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 @@ -665,7 +665,7 @@ def test_can_get_gt_job_meta_with_complex_frame_setup(self, admin_user, request) 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)) + 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 @@ -715,7 +715,7 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, jobs, task_mode, quality, ) assert response.status == HTTPStatus.OK - request.addfinalizer(lambda: self.delete_gt_job(admin_user, gt_job.id)) + 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 @@ -816,7 +816,7 @@ def test_can_get_gt_job_frame(self, admin_user, tasks, jobs, task_mode, quality, ) assert response.status == HTTPStatus.OK - request.addfinalizer(lambda: self.delete_gt_job(admin_user, gt_job.id)) + request.addfinalizer(lambda: self._delete_gt_job(admin_user, gt_job.id)) @pytest.mark.usefixtures("restore_db_per_class") From 1d9e2a4dc15d9219b4940958751e4587938aec04 Mon Sep 17 00:00:00 2001 From: vidit Date: Thu, 21 Mar 2024 00:30:50 +0530 Subject: [PATCH 11/13] removed raised warnings depened on the presence of gt_job in task --- tests/python/rest_api/test_jobs.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index 76854b5fe9b7..5870c085b11f 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -745,27 +745,21 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, jobs, task_mode, quality, 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: - raise RuntimeError(f"gt_job already exist for task {task_id}") - 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) + (gt_job, _) = api_client.jobs_api.create(job_spec) return gt_job - def _get_gt_job(self, user, task_id, frames): + 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") - if task_jobs.results: - gt_job = task_jobs.results[0] - else: - raise RuntimeError(f"gt_job doesn't exist for task {task_id}") + gt_job = task_jobs.results[0] return gt_job From 109c8a9d7dc48d0bc8076226c29a515f7a02bcb6 Mon Sep 17 00:00:00 2001 From: vidit Date: Thu, 21 Mar 2024 00:33:36 +0530 Subject: [PATCH 12/13] removed the unwanted job list call while creating a gt_job --- tests/python/rest_api/test_jobs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index 5870c085b11f..92444a3eb91d 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -744,7 +744,6 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, jobs, task_mode, quality, 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") job_spec = { "task_id": task_id, "type": "ground_truth", From de646add8b30b52e4315e43533eee3c1be2ac864 Mon Sep 17 00:00:00 2001 From: Maxim Zhiltsov Date: Thu, 21 Mar 2024 13:13:36 +0300 Subject: [PATCH 13/13] Apply suggestions from code review --- tests/python/rest_api/test_jobs.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index 92444a3eb91d..e6a4842ba0fa 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -579,10 +579,7 @@ class TestGetGtJobData: def _delete_gt_job(self, user, gt_job_id): with make_api_client(user) as api_client: - (_, gt_job_del_response) = api_client.jobs_api.destroy(gt_job_id) - assert ( - gt_job_del_response.status == HTTPStatus.NO_CONTENT - ), "newly created gt_job couldn't be deleted" + 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, jobs, task_mode, request): @@ -726,8 +723,6 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, jobs, task_mode, quality, # with placeholders in the frames outside the job. # This is required by the UI implementation with zipfile.ZipFile(chunk_file) as chunk: - print(set(chunk.namelist())) - print(set("{:06d}.jpeg".format(i) for i in frame_range)) assert set(chunk.namelist()) == set("{:06d}.jpeg".format(i) for i in frame_range) for file_info in chunk.filelist: