Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix REST API tests #5416

Merged
merged 10 commits into from
Dec 2, 2022
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
4 changes: 2 additions & 2 deletions tests/python/rest_api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down 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
7 changes: 1 addition & 6 deletions tests/python/shared/assets/annotations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1109,12 +1109,7 @@
"tracks": [],
"version": 0
},
"12": {
"shapes": [],
"tags": [],
"tracks": [],
"version": 0
},
"12": "Exporting a task without data is not allowed",
"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
15 changes: 12 additions & 3 deletions tests/python/shared/fixtures/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,17 @@ 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
Copy link
Contributor

@sizov-kirill sizov-kirill Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use such solution?

Suggested change
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
def find(tasks):
def _is_task_with_shapes(t):
if (
not t.get("data")
or not annotations["task"][str(t["id"])]["shapes"]
):
return False
return True

It won't make us always remember about skip_tasks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks


return list(filter(_is_task_with_shapes, tasks))

return find

Expand All @@ -370,7 +379,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")
Expand Down