Fix REST API tests (#5416)

Fixed REST API tests after merging #5408 and #5396 to develop

Co-authored-by: Boris Sekachev <sekachev.bs@gmail.com>
Co-authored-by: Nikita Manovich <nikita@cvat.ai>
main
Maria Khrustaleva 3 years ago committed by GitHub
parent 966f2e4efd
commit 9b0d963d1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1131,7 +1131,7 @@ class TaskViewSet(viewsets.GenericViewSet, mixins.ListModelMixin,
get_data=dm.task.get_task_data, get_data=dm.task.get_task_data,
) )
else: 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) status=status.HTTP_400_BAD_REQUEST)
elif request.method == 'POST' or request.method == 'OPTIONS': elif request.method == 'POST' or request.method == 'OPTIONS':
return self.import_annotations( return self.import_annotations(
@ -1311,7 +1311,7 @@ class TaskViewSet(viewsets.GenericViewSet, mixins.ListModelMixin,
export_func=_export_annotations, export_func=_export_annotations,
callback=dm.views.export_task_as_dataset) callback=dm.views.export_task_as_dataset)
else: 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) status=status.HTTP_400_BAD_REQUEST)
@extend_schema(tags=['jobs']) @extend_schema(tags=['jobs'])

@ -1,12 +1,19 @@
// Copyright (C) 2021-2022 Intel Corporation // Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
/* eslint-disable cypress/no-unnecessary-waiting */
/// <reference types="cypress" /> /// <reference types="cypress" />
Cypress.Commands.add('compareImagesAndCheckResult', (baseImage, afterImage, noChangesExpected) => { Cypress.Commands.add('compareImagesAndCheckResult', (baseImage, afterImage, noChangesExpected) => {
cy.compareImages(baseImage, afterImage).then((diffPercent) => { 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);
}
}); });
}); });
@ -31,5 +38,5 @@ Cypress.Commands.add('customScreenshot', (element, screenshotName) => {
getEl = cy.get(element).find('.cvat-canvas3d-fullsize'); getEl = cy.get(element).find('.cvat-canvas3d-fullsize');
padding = -40; padding = -40;
} }
getEl.screenshot(screenshotName, {padding: padding}); getEl.screenshot(screenshotName, { padding });
}); });

@ -153,7 +153,6 @@ class TestGetAnnotations:
assert response.status == HTTPStatus.OK assert response.status == HTTPStatus.OK
response_data = json.loads(response.data) response_data = json.loads(response.data)
response_data["shapes"] = sorted(response_data["shapes"], key=lambda a: a["id"])
assert ( assert (
DeepDiff(data, response_data, exclude_regex_paths=r"root\['version|updated_date'\]") DeepDiff(data, response_data, exclude_regex_paths=r"root\['version|updated_date'\]")
== {} == {}

@ -375,7 +375,7 @@ class TestPatchTaskAnnotations:
): ):
users = find_users(role=role, org=org) users = find_users(role=role, org=org)
tasks = tasks_by_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) data = request_data(tid)
with make_api_client(username) as api_client: with make_api_client(username) as api_client:

@ -1109,12 +1109,6 @@
"tracks": [], "tracks": [],
"version": 0 "version": 0
}, },
"12": {
"shapes": [],
"tags": [],
"tracks": [],
"version": 0
},
"13": { "13": {
"shapes": [ "shapes": [
{ {

@ -38,7 +38,7 @@
"status": "annotation", "status": "annotation",
"stop_frame": 24, "stop_frame": 24,
"task_id": 15, "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" "url": "http://localhost:8080/api/jobs/19"
}, },
{ {

@ -6,7 +6,7 @@
{ {
"assignee": null, "assignee": null,
"bug_tracker": "", "bug_tracker": "",
"created_date": "2022-12-01T12:52:42.454308Z", "created_date": "2022-12-01T12:52:42.454000Z",
"dimension": "2d", "dimension": "2d",
"id": 8, "id": 8,
"labels": [ "labels": [
@ -53,7 +53,7 @@
"tasks": [ "tasks": [
15 15
], ],
"updated_date": "2022-12-01T12:53:34.917451Z", "updated_date": "2022-12-01T12:53:34.917000Z",
"url": "http://localhost:8080/api/projects/8" "url": "http://localhost:8080/api/projects/8"
}, },
{ {

@ -6,7 +6,7 @@
{ {
"assignee": null, "assignee": null,
"bug_tracker": "", "bug_tracker": "",
"created_date": "2022-12-01T12:53:10.425141Z", "created_date": "2022-12-01T12:53:10.425000Z",
"data": 14, "data": 14,
"data_chunk_size": 72, "data_chunk_size": 72,
"data_compressed_chunk_type": "imageset", "data_compressed_chunk_type": "imageset",
@ -76,7 +76,7 @@
"id": 16, "id": 16,
"location": "local" "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" "url": "http://localhost:8080/api/tasks/15"
}, },
{ {

@ -310,7 +310,7 @@
"is_active": true, "is_active": true,
"is_staff": true, "is_staff": true,
"is_superuser": true, "is_superuser": true,
"last_login": "2022-12-01T12:52:15.631928Z", "last_login": "2022-12-01T12:52:15.631000Z",
"last_name": "First", "last_name": "First",
"url": "http://localhost:8080/api/users/1", "url": "http://localhost:8080/api/users/1",
"username": "admin1" "username": "admin1"

@ -350,7 +350,7 @@ def find_issue_staff_user(is_issue_staff, is_issue_admin):
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def filter_jobs_with_shapes(annotations): def filter_jobs_with_shapes(annotations):
def find(jobs): 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 return find
@ -358,7 +358,9 @@ def filter_jobs_with_shapes(annotations):
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def filter_tasks_with_shapes(annotations): def filter_tasks_with_shapes(annotations):
def find(tasks): 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 return find

@ -4,6 +4,7 @@
import json import json
import os.path as osp import os.path as osp
from http import HTTPStatus
from config import ASSETS_DIR, get_method from config import ASSETS_DIR, get_method
@ -31,6 +32,7 @@ if __name__ == "__main__":
for _obj in response.json()["results"]: for _obj in response.json()["results"]:
oid = _obj["id"] oid = _obj["id"]
response = get_method("admin1", f"{obj}s/{oid}/annotations") response = get_method("admin1", f"{obj}s/{oid}/annotations")
if response.status_code == HTTPStatus.OK:
annotations[obj][oid] = response.json() annotations[obj][oid] = response.json()
with open(osp.join(ASSETS_DIR, f"annotations.json"), "w") as f: with open(osp.join(ASSETS_DIR, f"annotations.json"), "w") as f:

Loading…
Cancel
Save