From fb0eb4375ef887ccfebd64b19a78d4d5c87dbc81 Mon Sep 17 00:00:00 2001 From: zaha Date: Tue, 2 Jul 2024 15:38:22 +0300 Subject: [PATCH] Check creating task with advanced params with file from cloud data (#8014) ### Motivation and context Test for https://github.com/cvat-ai/cvat/pull/7969 ### How has this been tested? ### Checklist - [x] I submit my changes into the `develop` branch - [ ] I have created a changelog fragment - [ ] I have updated the documentation accordingly - [ ] I have added tests to cover my changes - [ ] I have linked related issues (see [GitHub docs]( https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword)) - [ ] I have increased versions of npm packages if it is necessary ([cvat-canvas](https://github.com/cvat-ai/cvat/tree/develop/cvat-canvas#versioning), [cvat-core](https://github.com/cvat-ai/cvat/tree/develop/cvat-core#versioning), [cvat-data](https://github.com/cvat-ai/cvat/tree/develop/cvat-data#versioning) and [cvat-ui](https://github.com/cvat-ai/cvat/tree/develop/cvat-ui#versioning)) ### License - [x] I submit _my code changes_ under the same [MIT License]( https://github.com/cvat-ai/cvat/blob/develop/LICENSE) that covers the project. Feel free to contact the maintainers if that's a concern. ## Summary by CodeRabbit - **Tests** - Added tests for data retrieval and frame information in the REST API. - Updated test logic to handle video file generation and removal. - Enhanced test utility function to support additional specifications for tasks. --------- Co-authored-by: Boris Sekachev --- tests/python/rest_api/test_tasks.py | 91 ++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 15 deletions(-) diff --git a/tests/python/rest_api/test_tasks.py b/tests/python/rest_api/test_tasks.py index c6f25c82d66..e7b57673433 100644 --- a/tests/python/rest_api/test_tasks.py +++ b/tests/python/rest_api/test_tasks.py @@ -16,7 +16,7 @@ from pathlib import Path from tempfile import NamedTemporaryFile, TemporaryDirectory from time import sleep, time -from typing import Any, List, Optional, Tuple +from typing import Any, Dict, List, Optional, Tuple import pytest from cvat_sdk import Client, Config, exceptions @@ -1332,30 +1332,48 @@ def _create_task_with_cloud_data( server_files: List[str], use_cache: bool = True, sorting_method: str = "lexicographical", + spec: Optional[Dict[str, Any]] = None, + data_type: str = "image", + video_frame_count: int = 10, server_files_exclude: Optional[List[str]] = None, org: Optional[str] = None, filenames: Optional[List[str]] = None, ) -> Tuple[int, Any]: s3_client = s3.make_client() - images = generate_image_files( - 3, **({"prefixes": ["img_"] * 3} if not filenames else {"filenames": filenames}) - ) - - for image in images: - for i in range(2): - image.seek(0) - s3_client.create_file( - data=image, + if data_type == "video": + video = generate_video_file(video_frame_count) + s3_client.create_file( + data=video, + bucket=cloud_storage["resource"], + filename=f"test/video/{video.name}", + ) + request.addfinalizer( + partial( + s3_client.remove_file, bucket=cloud_storage["resource"], - filename=f"test/sub_{i}/{image.name}", + filename=f"test/video/{video.name}", ) - request.addfinalizer( - partial( - s3_client.remove_file, + ) + else: + images = generate_image_files( + 3, **({"prefixes": ["img_"] * 3} if not filenames else {"filenames": filenames}) + ) + + for image in images: + for i in range(2): + image.seek(0) + s3_client.create_file( + data=image, bucket=cloud_storage["resource"], filename=f"test/sub_{i}/{image.name}", ) - ) + request.addfinalizer( + partial( + s3_client.remove_file, + bucket=cloud_storage["resource"], + filename=f"test/sub_{i}/{image.name}", + ) + ) if use_manifest: with TemporaryDirectory() as tmp_dir: @@ -1400,6 +1418,9 @@ def _create_task_with_cloud_data( ), "sorting_method": sorting_method, } + if spec is not None: + data_spec.update(spec) + if server_files_exclude: data_spec["server_files_exclude"] = server_files_exclude @@ -1743,6 +1764,46 @@ def test_create_task_with_cloud_storage_and_check_data_sorting( for image_name, frame in zip(filenames, data_meta.frames): assert frame.name.rsplit("/", maxsplit=1)[1] == image_name + @pytest.mark.with_external_services + @pytest.mark.parametrize( + "cloud_storage_id, org", + [ + (1, ""), + ], + ) + def test_create_task_with_cloud_storage_and_check_retrieve_data_meta( + self, + cloud_storage_id: int, + org: str, + cloud_storages, + request, + ): + cloud_storage = cloud_storages[cloud_storage_id] + + data_spec = { + "start_frame": 2, + "stop_frame": 6, + "frame_filter": "step=2", + } + + task_id, _ = self._create_task_with_cloud_data( + request=request, + cloud_storage=cloud_storage, + use_manifest=False, + use_cache=False, + server_files=["test/video/video.avi"], + org=org, + spec=data_spec, + data_type="video", + ) + + with make_api_client(self._USERNAME) as api_client: + data_meta, _ = api_client.tasks_api.retrieve_data_meta(task_id) + + assert data_meta.start_frame == 2 + assert data_meta.stop_frame == 6 + assert data_meta.size == 3 + def test_can_specify_file_job_mapping(self): task_spec = { "name": f"test file-job mapping",