|
|
|
|
@ -17,6 +17,7 @@ from typing import Dict, Optional
|
|
|
|
|
import pytest
|
|
|
|
|
from cvat_sdk.api_client import ApiClient, Configuration, models
|
|
|
|
|
from deepdiff import DeepDiff
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
|
from shared.utils.config import BASE_URL, USER_PASS, get_method, make_api_client, patch_method
|
|
|
|
|
|
|
|
|
|
@ -735,3 +736,124 @@ class TestPatchProjectLabel:
|
|
|
|
|
)
|
|
|
|
|
assert response.status_code == HTTPStatus.OK
|
|
|
|
|
assert len(response.json()["labels"]) == len(project["labels"]) + 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures("restore_db_per_class")
|
|
|
|
|
class TestGetProjectPreview:
|
|
|
|
|
def _test_response_200(self, username, project_id, **kwargs):
|
|
|
|
|
with make_api_client(username) as api_client:
|
|
|
|
|
(_, response) = api_client.projects_api.retrieve_preview(project_id, **kwargs)
|
|
|
|
|
|
|
|
|
|
assert response.status == HTTPStatus.OK
|
|
|
|
|
(width, height) = Image.open(BytesIO(response.data)).size
|
|
|
|
|
assert width > 0 and height > 0
|
|
|
|
|
|
|
|
|
|
def _test_response_403(self, username, project_id):
|
|
|
|
|
with make_api_client(username) as api_client:
|
|
|
|
|
(_, response) = api_client.projects_api.retrieve_preview(
|
|
|
|
|
project_id, _parse_response=False, _check_status=False
|
|
|
|
|
)
|
|
|
|
|
assert response.status == HTTPStatus.FORBIDDEN
|
|
|
|
|
|
|
|
|
|
def _test_response_404(self, username, project_id):
|
|
|
|
|
with make_api_client(username) as api_client:
|
|
|
|
|
(_, response) = api_client.projects_api.retrieve_preview(
|
|
|
|
|
project_id, _parse_response=False, _check_status=False
|
|
|
|
|
)
|
|
|
|
|
assert response.status == HTTPStatus.NOT_FOUND
|
|
|
|
|
|
|
|
|
|
# Admin can see any project preview even he has no ownerships for this project.
|
|
|
|
|
def test_project_preview_admin_accessibility(
|
|
|
|
|
self, projects, find_users, is_project_staff, org_staff
|
|
|
|
|
):
|
|
|
|
|
users = find_users(privilege="admin")
|
|
|
|
|
|
|
|
|
|
user, project = next(
|
|
|
|
|
(user, project)
|
|
|
|
|
for user, project in product(users, projects)
|
|
|
|
|
if not is_project_staff(user["id"], project["organization"])
|
|
|
|
|
and user["id"] not in org_staff(project["organization"])
|
|
|
|
|
and project["tasks"]
|
|
|
|
|
)
|
|
|
|
|
self._test_response_200(user["username"], project["id"])
|
|
|
|
|
|
|
|
|
|
# Project owner or project assignee can see project preview.
|
|
|
|
|
def test_project_preview_owner_accessibility(self, projects):
|
|
|
|
|
for p in projects:
|
|
|
|
|
if not p["tasks"]:
|
|
|
|
|
continue
|
|
|
|
|
if p["owner"] is not None:
|
|
|
|
|
project_with_owner = p
|
|
|
|
|
if p["assignee"] is not None:
|
|
|
|
|
project_with_assignee = p
|
|
|
|
|
|
|
|
|
|
assert project_with_owner is not None
|
|
|
|
|
assert project_with_assignee is not None
|
|
|
|
|
|
|
|
|
|
self._test_response_200(project_with_owner["owner"]["username"], project_with_owner["id"])
|
|
|
|
|
self._test_response_200(
|
|
|
|
|
project_with_assignee["assignee"]["username"], project_with_assignee["id"]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_project_preview_not_found(self, projects):
|
|
|
|
|
for p in projects:
|
|
|
|
|
if p["tasks"]:
|
|
|
|
|
continue
|
|
|
|
|
if p["owner"] is not None:
|
|
|
|
|
project_with_owner = p
|
|
|
|
|
if p["assignee"] is not None:
|
|
|
|
|
project_with_assignee = p
|
|
|
|
|
|
|
|
|
|
assert project_with_owner is not None
|
|
|
|
|
assert project_with_assignee is not None
|
|
|
|
|
|
|
|
|
|
self._test_response_404(project_with_owner["owner"]["username"], project_with_owner["id"])
|
|
|
|
|
self._test_response_404(
|
|
|
|
|
project_with_assignee["assignee"]["username"], project_with_assignee["id"]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_user_cannot_see_project_preview(
|
|
|
|
|
self, projects, find_users, is_project_staff, org_staff
|
|
|
|
|
):
|
|
|
|
|
users = find_users(exclude_privilege="admin")
|
|
|
|
|
|
|
|
|
|
user, project = next(
|
|
|
|
|
(user, project)
|
|
|
|
|
for user, project in product(users, projects)
|
|
|
|
|
if not is_project_staff(user["id"], project["organization"])
|
|
|
|
|
and user["id"] not in org_staff(project["organization"])
|
|
|
|
|
)
|
|
|
|
|
self._test_response_403(user["username"], project["id"])
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("role", ("supervisor", "worker"))
|
|
|
|
|
def test_if_supervisor_or_worker_cannot_see_project_preview(
|
|
|
|
|
self, projects, is_project_staff, find_users, role
|
|
|
|
|
):
|
|
|
|
|
user, pid = next(
|
|
|
|
|
(
|
|
|
|
|
(user, project["id"])
|
|
|
|
|
for user in find_users(role=role, exclude_privilege="admin")
|
|
|
|
|
for project in projects
|
|
|
|
|
if project["organization"] == user["org"]
|
|
|
|
|
and not is_project_staff(user["id"], project["id"])
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self._test_response_403(user["username"], pid)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("role", ("maintainer", "owner"))
|
|
|
|
|
def test_if_maintainer_or_owner_can_see_project_preview(
|
|
|
|
|
self, find_users, projects, is_project_staff, role
|
|
|
|
|
):
|
|
|
|
|
user, pid = next(
|
|
|
|
|
(
|
|
|
|
|
(user, project["id"])
|
|
|
|
|
for user in find_users(role=role, exclude_privilege="admin")
|
|
|
|
|
for project in projects
|
|
|
|
|
if project["organization"] == user["org"]
|
|
|
|
|
and not is_project_staff(user["id"], project["id"])
|
|
|
|
|
and project["tasks"]
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self._test_response_200(user["username"], pid, org_id=user["org"])
|
|
|
|
|
|