diff --git a/cvat/apps/dataset_manager/tests/assets/annotations.json b/cvat/apps/dataset_manager/tests/assets/annotations.json index 251d7111ed12..c70dbcb598b5 100644 --- a/cvat/apps/dataset_manager/tests/assets/annotations.json +++ b/cvat/apps/dataset_manager/tests/assets/annotations.json @@ -43,6 +43,41 @@ } ] }, + "CVAT for video 1.1 attributes in tracks": { + "version": 0, + "tags": [], + "shapes": [], + "tracks": [ + { + "frame": 0, + "label_id": null, + "group": 0, + "source": "manual", + "shapes": [ + { + "type": "polygon", + "occluded": false, + "z_order": 0, + "points": [25.04, 13.7, 35.85, 20.2, 16.65, 19.8], + "frame": 0, + "outside": true, + "attributes": [] + }, + { + "type": "polygon", + "occluded": false, + "z_order": 0, + "points": [25.04, 13.7, 35.85, 20.2, 16.65, 19.8], + "frame": 1, + "outside": false, + "attributes": [], + "keyframe": true + } + ], + "attributes": [] + } + ] + }, "WiderFace 1.0": { "version": 0, "tags": [], diff --git a/cvat/apps/dataset_manager/tests/assets/tasks.json b/cvat/apps/dataset_manager/tests/assets/tasks.json index 1cc2d312d7f0..0e24e234f298 100644 --- a/cvat/apps/dataset_manager/tests/assets/tasks.json +++ b/cvat/apps/dataset_manager/tests/assets/tasks.json @@ -97,5 +97,18 @@ ] } ] + }, + "many jobs": { + "name": "many jobs", + "overlap": 0, + "segment_size": 5, + "owner_id": 1, + "labels": [ + { + "name": "car", + "color": "#2080c0", + "attributes": [] + } + ] } } diff --git a/cvat/apps/dataset_manager/tests/test_rest_api_formats.py b/cvat/apps/dataset_manager/tests/test_rest_api_formats.py index aa761514f82b..14af4154922e 100644 --- a/cvat/apps/dataset_manager/tests/test_rest_api_formats.py +++ b/cvat/apps/dataset_manager/tests/test_rest_api_formats.py @@ -103,6 +103,13 @@ def _create_task(self, data, image_data): return task + def _get_data_from_task(self, task_id, include_images): + task_ann = TaskAnnotation(task_id) + task_ann.init_from_db() + task_data = TaskData(task_ann.ir_data, Task.objects.get(pk=task_id)) + extractor = CvatTaskDataExtractor(task_data, include_images=include_images) + return Dataset.from_extractors(extractor) + def _get_request_with_data(self, path, data, user): with ForceLogin(user, self.client): response = self.client.get(path, data) @@ -231,11 +238,45 @@ def test_api_v1_check_widerface_with_all_attributes(self): self._create_annotations(task, f'{dump_format_name}', "random") task_id = task["id"] - task_ann = TaskAnnotation(task_id) - task_ann.init_from_db() - task_data = TaskData(task_ann.ir_data, Task.objects.get(pk=task_id)) - extractor = CvatTaskDataExtractor(task_data, include_images=include_images) - data_from_task_before_upload = Dataset.from_extractors(extractor) + data_from_task_before_upload = self._get_data_from_task(task_id, include_images) + + # dump annotations + url = self._generate_url_dump_tasks_annotations(task_id) + data = { + "format": dump_format_name, + "action": "download", + } + with TestDir() as test_dir: + file_zip_name = osp.join(test_dir, f'{test_name}_{dump_format_name}.zip') + self._download_file(url, data, self.admin, file_zip_name) + self._check_downloaded_file(file_zip_name) + + # remove annotations + self._remove_annotations(url, self.admin) + + # upload annotations + url = self._generate_url_upload_tasks_annotations(task_id, upload_format_name) + with open(file_zip_name, 'rb') as binary_file: + self._upload_file(url, binary_file, self.admin) + + # equals annotations + data_from_task_after_upload = self._get_data_from_task(task_id, include_images) + compare_datasets(self, data_from_task_before_upload, data_from_task_after_upload)\ + + def test_api_v1_check_attribute_import_in_tracks(self): + test_name = self._testMethodName + dump_format_name = "CVAT for video 1.1" + upload_format_name = "CVAT 1.1" + + for include_images in (False, True): + with self.subTest(): + # create task with annotations + images = self._generate_task_images(13) + task = self._create_task(tasks["many jobs"], images) + self._create_annotations(task, f'{dump_format_name} attributes in tracks', "default") + + task_id = task["id"] + data_from_task_before_upload = self._get_data_from_task(task_id, include_images) # dump annotations url = self._generate_url_dump_tasks_annotations(task_id) @@ -257,9 +298,5 @@ def test_api_v1_check_widerface_with_all_attributes(self): self._upload_file(url, binary_file, self.admin) # equals annotations - task_ann = TaskAnnotation(task_id) - task_ann.init_from_db() - task_data = TaskData(task_ann.ir_data, Task.objects.get(pk=task_id)) - extractor = CvatTaskDataExtractor(task_data, include_images=include_images) - data_from_task_after_upload = Dataset.from_extractors(extractor) + data_from_task_after_upload = self._get_data_from_task(task_id, include_images) compare_datasets(self, data_from_task_before_upload, data_from_task_after_upload)