Skip to content

Commit

Permalink
Update assets after merging develop && simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
Marishka17 committed Sep 27, 2024
1 parent 97b9ffd commit ba667cd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 39 deletions.
56 changes: 30 additions & 26 deletions tests/python/rest_api/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,15 @@ def test_can_get_backup_project_when_all_tasks_have_no_data(
"admin1",
"tasks",
{"name": "empty_task1", "project_id": project["id"]},
org_id=project["organization"],
**({"org_id": project["organization"]} if project["organization"] else {}),
)
assert response.status_code == HTTPStatus.CREATED, response.text

response = post_method(
"admin1",
"tasks",
{"name": "empty_task2", "project_id": project["id"]},
org_id=project["organization"],
**({"org_id": project["organization"]} if project["organization"] else {}),
)
assert response.status_code == HTTPStatus.CREATED, response.text

Expand Down Expand Up @@ -909,8 +909,8 @@ def test_can_export_project_dataset_when_some_tasks_have_no_data(
{
"name": "empty_task",
"project_id": project["id"],
"organization": project["organization"],
},
**({"org_id": project["organization"]} if project["organization"] else {}),
)
assert response.status_code == HTTPStatus.CREATED

Expand All @@ -934,15 +934,15 @@ def test_can_export_project_dataset_when_all_tasks_have_no_data(
"admin1",
"tasks",
{"name": "empty_task1", "project_id": project["id"]},
org_id=project["organization"],
**({"org_id": project["organization"]} if project["organization"] else {}),
)
assert response.status_code == HTTPStatus.CREATED, response.text

response = post_method(
"admin1",
"tasks",
{"name": "empty_task2", "project_id": project["id"]},
org_id=project["organization"],
**({"org_id": project["organization"]} if project["organization"] else {}),
)
assert response.status_code == HTTPStatus.CREATED, response.text

Expand Down Expand Up @@ -1413,8 +1413,8 @@ def test_can_update_assignee_updated_date_on_assignee_updates(

op = operator.eq if new_assignee_id == old_assignee_id else operator.ne

# FUTURE-TODO: currently it is possible to have a project with assignee but with assignee_updated_date == None
# because there were no migration to set some assignee_updated_date for such projects/tasks/jobs
# FUTURE-TODO: currently it is possible to have a project with an assignee but with assignee_updated_date == None
# because there was no migration to set some assignee_updated_date for projects/tasks/jobs with assignee != None
if isinstance(updated_project.assignee_updated_date, datetime):
assert op(
str(updated_project.assignee_updated_date.isoformat()).replace("+00:00", "Z"),
Expand Down Expand Up @@ -1515,27 +1515,31 @@ def test_sandbox_update_project_associated_storage(
find_users,
filter_projects,
):
username, project_id = next(
(
(user["username"], project["id"])
for user in find_users(exclude_privilege="admin")
for project in filter_projects(organization=None)
username: Optional[str] = None
project_id: Optional[int] = None

projects = filter_projects(organization=None)
users = find_users(exclude_privilege="admin")

for project in projects:
if project_id is not None:
break
for user in users:
is_user_project_owner = project["owner"]["id"] == user["id"]
is_user_project_assignee = (project["assignee"] or {}).get("id") == user["id"]

if (
(is_owner and project["owner"]["id"] == user["id"])
or (
is_assignee
and project["owner"]["id"] != user["id"]
and (project["assignee"] or {}).get("id") == user["id"]
(is_owner and is_user_project_owner)
or (is_assignee and not is_user_project_owner and is_user_project_assignee)
or not any(
[is_owner, is_assignee, is_user_project_owner, is_user_project_assignee]
)
or (
not is_owner
and not is_assignee
and project["owner"]["id"] != user["id"]
and (project["assignee"] or {}).get("id") != user["id"]
)
)
)
)
):
project_id = project["id"]
username = user["username"]
break

assert project_id is not None

self._test_patch_linked_storage(
username,
Expand Down
35 changes: 22 additions & 13 deletions tests/python/rest_api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3453,26 +3453,35 @@ def test_update_task_linked_storage_by_assignee_or_owner(
if org and task["organization"] != user["org"]:
continue

is_user_task_owner = task["owner"]["id"] == user["id"]
is_user_task_assignee = (task["assignee"] or {}).get("id") == user["id"]
project = projects[task["project_id"]] if task["project_id"] else None
is_user_project_owner = (project or {}).get("owner", {}).get("id") == user["id"]
is_user_project_assignee = ((project or {}).get("assignee") or {}).get(
"id"
) == user["id"]

if (
is_task_owner
and task["owner"]["id"] == user["id"]
and is_user_task_owner
or is_task_assignee
and (task["assignee"] or {}).get("id") == user["id"]
and is_user_task_assignee
or is_project_owner
and projects[task["project_id"]]["owner"]["id"] == user["id"]
and is_user_project_owner
or is_project_assignee
and (projects[task["project_id"]]["assignee"] or {}).get("id") == user["id"]
and is_user_project_assignee
or (
not any(
[is_task_owner, is_task_assignee, is_project_owner, is_project_assignee]
)
and task["owner"]["id"] != user["id"]
and (task["assignee"] or {}).get("id") != user["id"]
and (
not task["project_id"]
or projects[task["project_id"]]["owner"]["id"] != user["id"]
and (projects[task["project_id"]]["assignee"] or {}).get("id")
!= user["id"]
[
is_task_owner,
is_task_assignee,
is_project_owner,
is_project_assignee,
is_user_task_owner,
is_user_task_assignee,
is_user_project_owner,
is_project_assignee,
]
)
)
):
Expand Down
3 changes: 3 additions & 0 deletions tests/python/shared/assets/jobs.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"created_date": "2024-09-23T21:42:23.045000Z",
"data_chunk_size": 72,
"data_compressed_chunk_type": "imageset",
"data_original_chunk_type": "imageset",
"dimension": "2d",
"frame_count": 1,
"guide_id": null,
Expand Down Expand Up @@ -51,6 +52,7 @@
"created_date": "2024-09-23T10:52:04.507000Z",
"data_chunk_size": 72,
"data_compressed_chunk_type": "imageset",
"data_original_chunk_type": "imageset",
"dimension": "2d",
"frame_count": 1,
"guide_id": null,
Expand Down Expand Up @@ -92,6 +94,7 @@
"created_date": "2024-09-23T10:51:32.932000Z",
"data_chunk_size": 72,
"data_compressed_chunk_type": "imageset",
"data_original_chunk_type": "imageset",
"dimension": "2d",
"frame_count": 1,
"guide_id": null,
Expand Down

0 comments on commit ba667cd

Please sign in to comment.