未验证 提交 b029bc9d 编写于 作者: Р Роман Донченко 提交者: GitHub

cvat-sdk: Fix creating tasks with non-local files (#5058)

* Move the test file share contents to tests/share

This way, it can be reused between tests.

* cvat-sdk: Fix creating tasks with non-local files

Forcing the `Content-Type` for the `upload_data` API call to
`multipart/form-data` does not work, because the current logic for
converting Python values to parts (`ApiClient._convert_body_to_post_params`)
does not encode them in a way that Django REST Framework can understand (it
JSON-encodes each part).

Fortunately, we don't actually need to do that, since when we create a task
with non-local files, we don't need to upload any files, and so we can just
post the original JSON, so do just that.

I couldn't add a test for the remote image case, because CVAT rejects all URLs
with non-public IP addressses. However, I did test this case manually.
上级 b7371ede
......@@ -35,6 +35,8 @@ non-ascii paths while adding files from "Connected file share" (issue #4428)
- Invisible label item in label constructor when label color background is white,
or close to it (<https://github.com/opencv/cvat/pull/5041>)
- Fixed cvat-core ESlint problems (<https://github.com/opencv/cvat/pull/5027>)
- Fixed task creation with non-local files via the SDK/CLI
(<https://github.com/opencv/cvat/issues/4962>)
### Security
- TDB
......
......@@ -77,9 +77,9 @@ class Task(
if resource_type is ResourceType.LOCAL:
pass # handled later
elif resource_type is ResourceType.REMOTE:
data = {f"remote_files[{i}]": f for i, f in enumerate(resources)}
data["remote_files"] = resources
elif resource_type is ResourceType.SHARE:
data = {f"server_files[{i}]": f for i, f in enumerate(resources)}
data["server_files"] = resources
data["image_quality"] = 70
data.update(
......@@ -104,7 +104,6 @@ class Task(
self.api.create_data(
self.id,
data_request=models.DataRequest(**data),
_content_type="multipart/form-data",
)
elif resource_type == ResourceType.LOCAL:
url = self._client.api_map.make_endpoint_url(
......
......@@ -3,7 +3,7 @@ version: '3.3'
services:
cvat_worker_default:
volumes:
- ./tests/cypress/integration/actions_tasks3/assets/case_107:/home/django/share:rw
- ./tests/mounted_file_share:/home/django/share:rw
cvat_server:
volumes:
- ./tests/cypress/integration/actions_tasks3/assets/case_107:/home/django/share:rw
- ./tests/mounted_file_share:/home/django/share:rw
......@@ -126,6 +126,23 @@ class TestTaskUsecases:
assert "100%" in pbar_out.getvalue().strip("\r").split("\r")[-1]
assert self.stdout.getvalue() == ""
def test_can_create_task_with_remote_data(self):
task = self.client.tasks.create_from_data(
spec={
"name": "test_task",
"labels": [{"name": "car"}, {"name": "person"}],
},
resource_type=ResourceType.SHARE,
resources=["image_case_107_2.png", "image_case_107_1.png"],
# make sure string fields are transferred correctly;
# see https://github.com/opencv/cvat/issues/4962
data_params={"sorting_method": "lexicographical"},
)
assert task.size == 2
assert task.get_frames_info()[0].name == "image_case_107_1.png"
assert self.stdout.getvalue() == ""
def test_cant_create_task_with_no_data(self):
pbar_out = io.StringIO()
pbar = make_pbar(file=pbar_out)
......
......@@ -30,6 +30,7 @@ DC_FILES = [
osp.join(CVAT_ROOT_DIR, dc_file)
for dc_file in (
"docker-compose.dev.yml",
"tests/docker-compose.file_share.yml",
"tests/docker-compose.minio.yml",
"tests/docker-compose.webhook.yml",
)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册