From 882e091c8b31341eab7286d03c6ff2d16351a138 Mon Sep 17 00:00:00 2001 From: Maya Date: Fri, 2 Dec 2022 13:12:01 +0100 Subject: [PATCH 1/7] Fix rest api tests --- tests/python/rest_api/test_jobs.py | 1 - tests/python/rest_api/test_tasks.py | 4 ++-- tests/python/shared/assets/annotations.json | 7 +------ tests/python/shared/assets/jobs.json | 2 +- tests/python/shared/assets/projects.json | 4 ++-- tests/python/shared/assets/tasks.json | 4 ++-- tests/python/shared/assets/users.json | 2 +- tests/python/shared/fixtures/data.py | 12 +++++++++--- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/python/rest_api/test_jobs.py b/tests/python/rest_api/test_jobs.py index 1246b40d0c0..0a8bb53c37e 100644 --- a/tests/python/rest_api/test_jobs.py +++ b/tests/python/rest_api/test_jobs.py @@ -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'\]") == {} diff --git a/tests/python/rest_api/test_tasks.py b/tests/python/rest_api/test_tasks.py index af7591d50e6..683efb43341 100644 --- a/tests/python/rest_api/test_tasks.py +++ b/tests/python/rest_api/test_tasks.py @@ -332,7 +332,7 @@ def test_user_update_task_annotations( ): users = find_users(privilege=privilege) tasks = tasks_by_org[org] - filtered_tasks = filter_tasks_with_shapes(tasks) + filtered_tasks = filter_tasks_with_shapes(tasks, skip_tasks=[12]) # skip task without data username, tid = find_task_staff_user(filtered_tasks, users, task_staff) data = request_data(tid) @@ -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: diff --git a/tests/python/shared/assets/annotations.json b/tests/python/shared/assets/annotations.json index f2a7dbe4d1e..eb1b09cad7e 100644 --- a/tests/python/shared/assets/annotations.json +++ b/tests/python/shared/assets/annotations.json @@ -1109,12 +1109,7 @@ "tracks": [], "version": 0 }, - "12": { - "shapes": [], - "tags": [], - "tracks": [], - "version": 0 - }, + "12": "Exporting a task without data is not allowed", "13": { "shapes": [ { diff --git a/tests/python/shared/assets/jobs.json b/tests/python/shared/assets/jobs.json index 2df47bfa09f..627bd290407 100644 --- a/tests/python/shared/assets/jobs.json +++ b/tests/python/shared/assets/jobs.json @@ -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" }, { diff --git a/tests/python/shared/assets/projects.json b/tests/python/shared/assets/projects.json index c21987f28aa..482b983a79a 100644 --- a/tests/python/shared/assets/projects.json +++ b/tests/python/shared/assets/projects.json @@ -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": [ @@ -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" }, { diff --git a/tests/python/shared/assets/tasks.json b/tests/python/shared/assets/tasks.json index 4a2113bb5cd..d04e65d47d7 100644 --- a/tests/python/shared/assets/tasks.json +++ b/tests/python/shared/assets/tasks.json @@ -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", @@ -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" }, { diff --git a/tests/python/shared/assets/users.json b/tests/python/shared/assets/users.json index bfd9abd562e..af5d8066289 100644 --- a/tests/python/shared/assets/users.json +++ b/tests/python/shared/assets/users.json @@ -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" diff --git a/tests/python/shared/fixtures/data.py b/tests/python/shared/fixtures/data.py index 18b9c0f3904..c3327f9217e 100644 --- a/tests/python/shared/fixtures/data.py +++ b/tests/python/shared/fixtures/data.py @@ -357,8 +357,14 @@ def find(jobs): @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)) + def find(tasks, skip_tasks=None): + def _is_task_with_shapes(t): + if skip_tasks is not None and t["id"] in skip_tasks or \ + not annotations["task"][str(t["id"])]["shapes"]: + return False + return True + + return list(filter(_is_task_with_shapes, tasks)) return find @@ -370,7 +376,7 @@ def jobs_with_shapes(jobs, filter_jobs_with_shapes): @pytest.fixture(scope="session") def tasks_with_shapes(tasks, filter_tasks_with_shapes): - return filter_tasks_with_shapes(tasks) + return filter_tasks_with_shapes(tasks, skip_tasks=[12]) @pytest.fixture(scope="session") From 91e77d09f8cf82d2b5a3bbf58dea2431ce96cad2 Mon Sep 17 00:00:00 2001 From: Maya Date: Fri, 2 Dec 2022 13:16:11 +0100 Subject: [PATCH 2/7] Fix black issues --- tests/python/rest_api/test_tasks.py | 2 +- tests/python/shared/fixtures/data.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/python/rest_api/test_tasks.py b/tests/python/rest_api/test_tasks.py index 683efb43341..19c9bae18ef 100644 --- a/tests/python/rest_api/test_tasks.py +++ b/tests/python/rest_api/test_tasks.py @@ -332,7 +332,7 @@ def test_user_update_task_annotations( ): users = find_users(privilege=privilege) tasks = tasks_by_org[org] - filtered_tasks = filter_tasks_with_shapes(tasks, skip_tasks=[12]) # skip task without data + filtered_tasks = filter_tasks_with_shapes(tasks, skip_tasks=[12]) # skip task without data username, tid = find_task_staff_user(filtered_tasks, users, task_staff) data = request_data(tid) diff --git a/tests/python/shared/fixtures/data.py b/tests/python/shared/fixtures/data.py index c3327f9217e..c4a32ee6d01 100644 --- a/tests/python/shared/fixtures/data.py +++ b/tests/python/shared/fixtures/data.py @@ -359,8 +359,11 @@ def find(jobs): def filter_tasks_with_shapes(annotations): def find(tasks, skip_tasks=None): def _is_task_with_shapes(t): - if skip_tasks is not None and t["id"] in skip_tasks or \ - not annotations["task"][str(t["id"])]["shapes"]: + if ( + skip_tasks is not None + and t["id"] in skip_tasks + or not annotations["task"][str(t["id"])]["shapes"] + ): return False return True From c69864464fe4d41505002349e7b84075ce8ebb08 Mon Sep 17 00:00:00 2001 From: Maya Date: Fri, 2 Dec 2022 14:39:11 +0100 Subject: [PATCH 3/7] Apply comment --- tests/python/rest_api/test_tasks.py | 2 +- tests/python/shared/fixtures/data.py | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/python/rest_api/test_tasks.py b/tests/python/rest_api/test_tasks.py index 19c9bae18ef..e85d86884b0 100644 --- a/tests/python/rest_api/test_tasks.py +++ b/tests/python/rest_api/test_tasks.py @@ -332,7 +332,7 @@ def test_user_update_task_annotations( ): users = find_users(privilege=privilege) tasks = tasks_by_org[org] - filtered_tasks = filter_tasks_with_shapes(tasks, skip_tasks=[12]) # skip task without data + filtered_tasks = filter_tasks_with_shapes(tasks) username, tid = find_task_staff_user(filtered_tasks, users, task_staff) data = request_data(tid) diff --git a/tests/python/shared/fixtures/data.py b/tests/python/shared/fixtures/data.py index c4a32ee6d01..166b9fe844d 100644 --- a/tests/python/shared/fixtures/data.py +++ b/tests/python/shared/fixtures/data.py @@ -357,15 +357,11 @@ def find(jobs): @pytest.fixture(scope="session") def filter_tasks_with_shapes(annotations): - def find(tasks, skip_tasks=None): + def find(tasks): def _is_task_with_shapes(t): - if ( - skip_tasks is not None - and t["id"] in skip_tasks - or not annotations["task"][str(t["id"])]["shapes"] - ): - return False - return True + if t.get("data") and annotations["task"][str(t["id"])]["shapes"]: + return True + return False return list(filter(_is_task_with_shapes, tasks)) @@ -379,7 +375,7 @@ def jobs_with_shapes(jobs, filter_jobs_with_shapes): @pytest.fixture(scope="session") def tasks_with_shapes(tasks, filter_tasks_with_shapes): - return filter_tasks_with_shapes(tasks, skip_tasks=[12]) + return filter_tasks_with_shapes(tasks) @pytest.fixture(scope="session") From a54bdbcb785602fe8f7e5c9b196c258d3738bb09 Mon Sep 17 00:00:00 2001 From: Boris Sekachev Date: Thu, 1 Dec 2022 12:00:21 -0800 Subject: [PATCH 4/7] Increased test threshold --- tests/cypress/support/commands_canvas3d.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/cypress/support/commands_canvas3d.js b/tests/cypress/support/commands_canvas3d.js index 3abcccae3e4..3343429ed1c 100644 --- a/tests/cypress/support/commands_canvas3d.js +++ b/tests/cypress/support/commands_canvas3d.js @@ -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 */ + /// 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); + } }); }); @@ -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 }); }); From 317d8648be71e9292fb873a796aad25d3b9a273c Mon Sep 17 00:00:00 2001 From: Nikita Manovich Date: Fri, 2 Dec 2022 21:22:46 +0200 Subject: [PATCH 5/7] Fix some issues with dump_objects script in the testing system. --- tests/python/shared/assets/annotations.json | 1 - tests/python/shared/fixtures/data.py | 7 +------ tests/python/shared/utils/dump_objects.py | 4 +++- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/python/shared/assets/annotations.json b/tests/python/shared/assets/annotations.json index eb1b09cad7e..7cc496b2c23 100644 --- a/tests/python/shared/assets/annotations.json +++ b/tests/python/shared/assets/annotations.json @@ -1109,7 +1109,6 @@ "tracks": [], "version": 0 }, - "12": "Exporting a task without data is not allowed", "13": { "shapes": [ { diff --git a/tests/python/shared/fixtures/data.py b/tests/python/shared/fixtures/data.py index 166b9fe844d..18b9c0f3904 100644 --- a/tests/python/shared/fixtures/data.py +++ b/tests/python/shared/fixtures/data.py @@ -358,12 +358,7 @@ def find(jobs): @pytest.fixture(scope="session") def filter_tasks_with_shapes(annotations): def find(tasks): - def _is_task_with_shapes(t): - if t.get("data") and annotations["task"][str(t["id"])]["shapes"]: - return True - return False - - return list(filter(_is_task_with_shapes, tasks)) + return list(filter(lambda t: annotations["task"][str(t["id"])]["shapes"], tasks)) return find diff --git a/tests/python/shared/utils/dump_objects.py b/tests/python/shared/utils/dump_objects.py index 7a1bbc6a693..fb9b2fcacec 100644 --- a/tests/python/shared/utils/dump_objects.py +++ b/tests/python/shared/utils/dump_objects.py @@ -4,6 +4,7 @@ import json import os.path as osp +from http import HTTPStatus from config import ASSETS_DIR, get_method @@ -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) From 6bf1fe4282821c3472c4cd63c8602b78cd97b1ef Mon Sep 17 00:00:00 2001 From: Nikita Manovich Date: Fri, 2 Dec 2022 22:23:16 +0200 Subject: [PATCH 6/7] Fix an exeption for test_can_export_task_dataset --- cvat/apps/engine/views.py | 4 ++-- tests/python/shared/fixtures/data.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cvat/apps/engine/views.py b/cvat/apps/engine/views.py index 0d2f3673687..d507d7e9adf 100644 --- a/cvat/apps/engine/views.py +++ b/cvat/apps/engine/views.py @@ -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( @@ -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']) diff --git a/tests/python/shared/fixtures/data.py b/tests/python/shared/fixtures/data.py index 18b9c0f3904..569bf5af987 100644 --- a/tests/python/shared/fixtures/data.py +++ b/tests/python/shared/fixtures/data.py @@ -350,7 +350,8 @@ 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 @@ -358,7 +359,8 @@ def find(jobs): @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 From f8abf89cb2792fdb167de27c1739e01770094492 Mon Sep 17 00:00:00 2001 From: Nikita Manovich Date: Fri, 2 Dec 2022 23:20:55 +0200 Subject: [PATCH 7/7] Fix black issues --- tests/python/shared/fixtures/data.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/python/shared/fixtures/data.py b/tests/python/shared/fixtures/data.py index 569bf5af987..4f18cdd5e32 100644 --- a/tests/python/shared/fixtures/data.py +++ b/tests/python/shared/fixtures/data.py @@ -350,8 +350,7 @@ 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"].get( - str(j["id"]), {}).get("shapes"), jobs)) + return list(filter(lambda j: annotations["job"].get(str(j["id"]), {}).get("shapes"), jobs)) return find @@ -359,8 +358,9 @@ def find(jobs): @pytest.fixture(scope="session") def filter_tasks_with_shapes(annotations): def find(tasks): - return list(filter(lambda t: annotations["task"].get( - str(t["id"]), {}).get("shapes"), tasks)) + return list( + filter(lambda t: annotations["task"].get(str(t["id"]), {}).get("shapes"), tasks) + ) return find