Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Fix REST API tests (cvat-ai#5416)
Browse files Browse the repository at this point in the history
Fixed REST API tests after merging cvat-ai#5408 and cvat-ai#5396 to develop

Co-authored-by: Boris Sekachev <sekachev.bs@gmail.com>
Co-authored-by: Nikita Manovich <nikita@cvat.ai>
  • Loading branch information
3 people authored and mikhail-treskin committed Jul 1, 2023
1 parent 2724f4b commit 215d3ca
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ def annotations(self, request, pk):
get_data=dm.task.get_task_data,
)
else:
return Response(data="Exporting a task without data is not allowed",
return Response(data="Exporting annotations from a task without data is not allowed",
status=status.HTTP_400_BAD_REQUEST)
elif request.method == 'POST' or request.method == 'OPTIONS':
return self.import_annotations(
Expand Down Expand Up @@ -1311,7 +1311,7 @@ def dataset_export(self, request, pk):
export_func=_export_annotations,
callback=dm.views.export_task_as_dataset)
else:
return Response(data="Exporting a task without data is not allowed",
return Response(data="Exporting a dataset from a task without data is not allowed",
status=status.HTTP_400_BAD_REQUEST)

@extend_schema(tags=['jobs'])
Expand Down
11 changes: 9 additions & 2 deletions tests/cypress/support/commands_canvas3d.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

/* eslint-disable cypress/no-unnecessary-waiting */

/// <reference types="cypress" />

Cypress.Commands.add('compareImagesAndCheckResult', (baseImage, afterImage, noChangesExpected) => {
cy.compareImages(baseImage, afterImage).then((diffPercent) => {
noChangesExpected ? expect(diffPercent).to.be.lt(0.01) : expect(diffPercent).to.be.gt(0);
if (noChangesExpected) {
expect(diffPercent).to.be.lt(0.02);
} else {
expect(diffPercent).to.be.gt(0);
}
});
});

Expand All @@ -31,5 +38,5 @@ Cypress.Commands.add('customScreenshot', (element, screenshotName) => {
getEl = cy.get(element).find('.cvat-canvas3d-fullsize');
padding = -40;
}
getEl.screenshot(screenshotName, {padding: padding});
getEl.screenshot(screenshotName, { padding });
});
1 change: 0 additions & 1 deletion tests/python/rest_api/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def _test_get_job_annotations_200(self, user, jid, data, **kwargs):
assert response.status == HTTPStatus.OK

response_data = json.loads(response.data)
response_data["shapes"] = sorted(response_data["shapes"], key=lambda a: a["id"])
assert (
DeepDiff(data, response_data, exclude_regex_paths=r"root\['version|updated_date'\]")
== {}
Expand Down
2 changes: 1 addition & 1 deletion tests/python/rest_api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def test_member_update_task_annotation(
):
users = find_users(role=role, org=org)
tasks = tasks_by_org[org]
username, tid = find_task_staff_user(tasks, users, task_staff, [14])
username, tid = find_task_staff_user(tasks, users, task_staff, [12, 14])

data = request_data(tid)
with make_api_client(username) as api_client:
Expand Down
6 changes: 0 additions & 6 deletions tests/python/shared/assets/annotations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1109,12 +1109,6 @@
"tracks": [],
"version": 0
},
"12": {
"shapes": [],
"tags": [],
"tracks": [],
"version": 0
},
"13": {
"shapes": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/python/shared/assets/jobs.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"status": "annotation",
"stop_frame": 24,
"task_id": 15,
"updated_date": "2022-12-01T12:53:35.354431Z",
"updated_date": "2022-12-01T12:53:35.354000Z",
"url": "http://localhost:8080/api/jobs/19"
},
{
Expand Down
4 changes: 2 additions & 2 deletions tests/python/shared/assets/projects.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"assignee": null,
"bug_tracker": "",
"created_date": "2022-12-01T12:52:42.454308Z",
"created_date": "2022-12-01T12:52:42.454000Z",
"dimension": "2d",
"id": 8,
"labels": [
Expand Down Expand Up @@ -53,7 +53,7 @@
"tasks": [
15
],
"updated_date": "2022-12-01T12:53:34.917451Z",
"updated_date": "2022-12-01T12:53:34.917000Z",
"url": "http://localhost:8080/api/projects/8"
},
{
Expand Down
4 changes: 2 additions & 2 deletions tests/python/shared/assets/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"assignee": null,
"bug_tracker": "",
"created_date": "2022-12-01T12:53:10.425141Z",
"created_date": "2022-12-01T12:53:10.425000Z",
"data": 14,
"data_chunk_size": 72,
"data_compressed_chunk_type": "imageset",
Expand Down Expand Up @@ -76,7 +76,7 @@
"id": 16,
"location": "local"
},
"updated_date": "2022-12-01T12:53:35.028385Z",
"updated_date": "2022-12-01T12:53:35.028000Z",
"url": "http://localhost:8080/api/tasks/15"
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/python/shared/assets/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
"is_active": true,
"is_staff": true,
"is_superuser": true,
"last_login": "2022-12-01T12:52:15.631928Z",
"last_login": "2022-12-01T12:52:15.631000Z",
"last_name": "First",
"url": "http://localhost:8080/api/users/1",
"username": "admin1"
Expand Down
6 changes: 4 additions & 2 deletions tests/python/shared/fixtures/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,17 @@ def find(issues, users, is_staff, is_admin):
@pytest.fixture(scope="session")
def filter_jobs_with_shapes(annotations):
def find(jobs):
return list(filter(lambda j: annotations["job"][str(j["id"])]["shapes"], jobs))
return list(filter(lambda j: annotations["job"].get(str(j["id"]), {}).get("shapes"), jobs))

return find


@pytest.fixture(scope="session")
def filter_tasks_with_shapes(annotations):
def find(tasks):
return list(filter(lambda t: annotations["task"][str(t["id"])]["shapes"], tasks))
return list(
filter(lambda t: annotations["task"].get(str(t["id"]), {}).get("shapes"), tasks)
)

return find

Expand Down
4 changes: 3 additions & 1 deletion tests/python/shared/utils/dump_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import json
import os.path as osp
from http import HTTPStatus

from config import ASSETS_DIR, get_method

Expand Down Expand Up @@ -31,7 +32,8 @@
for _obj in response.json()["results"]:
oid = _obj["id"]
response = get_method("admin1", f"{obj}s/{oid}/annotations")
annotations[obj][oid] = response.json()
if response.status_code == HTTPStatus.OK:
annotations[obj][oid] = response.json()

with open(osp.join(ASSETS_DIR, f"annotations.json"), "w") as f:
json.dump(annotations, f, indent=2, sort_keys=True)

0 comments on commit 215d3ca

Please sign in to comment.