Skip to content

Commit

Permalink
Added e2e tests and support for visibility workspace (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raalsky authored Mar 16, 2022
1 parent 9885885 commit 5860b41
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## neptune-client 0.15.2 [UNRELEASED]

## Features
- Added support for workspace visibility in Management API ([#843](https://github.com/neptune-ai/neptune-client/pull/843))
- Exposed container with a property of Handler ([#864](https://github.com/neptune-ai/neptune-client/pull/864))

## neptune-client 0.15.1
Expand Down
74 changes: 74 additions & 0 deletions e2e_tests/management/test_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
delete_project,
remove_project_member,
)
from neptune.management.exceptions import (
UserAlreadyHasAccess,
UserNotExistsOrWithoutAccess,
)
from neptune.management.internal.utils import normalize_project_name
from e2e_tests.base import BaseE2ETest, fake
from e2e_tests.utils import a_project_name, Environment
Expand Down Expand Up @@ -103,3 +107,73 @@ def test_standard_scenario(self, environment: Environment):
assert project_identifier not in get_project_list(
api_token=environment.admin_token
)

def test_visibility_workspace(self, environment: "Environment"):
project_name, project_key = a_project_name(
project_slug=f"{fake.slug()}-workspace"
)
project_identifier = normalize_project_name(
name=project_name, workspace=environment.workspace
)

assert project_identifier not in get_project_list(
api_token=environment.admin_token
)
assert environment.user in get_workspace_member_list(
name=environment.workspace, api_token=environment.admin_token
)
assert (
get_workspace_member_list(
name=environment.workspace, api_token=environment.admin_token
).get(environment.user)
== "member"
)

created_project_identifier = create_project(
name=project_name,
key=project_key,
visibility="workspace",
workspace=environment.workspace,
api_token=environment.admin_token,
)

assert created_project_identifier == project_identifier
assert created_project_identifier in get_project_list(
api_token=environment.admin_token
)
assert environment.user in get_project_member_list(
name=created_project_identifier, api_token=environment.admin_token
)
assert (
get_project_member_list(
name=created_project_identifier, api_token=environment.admin_token
).get(environment.user)
== "owner"
)

with pytest.raises(UserAlreadyHasAccess):
add_project_member(
name=created_project_identifier,
username=environment.user,
role="contributor",
api_token=environment.admin_token,
)

assert created_project_identifier in get_project_list(
api_token=environment.user_token
)

with pytest.raises(UserNotExistsOrWithoutAccess):
remove_project_member(
name=created_project_identifier,
username=environment.user,
api_token=environment.admin_token,
)

delete_project(
name=created_project_identifier, api_token=environment.admin_token
)

assert project_identifier not in get_project_list(
api_token=environment.admin_token
)
7 changes: 5 additions & 2 deletions neptune/management/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ class AccessRevokedOnMemberRemoval(ManagementOperationFailure):

class UserNotExistsOrWithoutAccess(ManagementOperationFailure):
code = 9
description = 'User "{user}" not exists or has no access to project "{project}".'
description = (
'User "{user}" does not exist or has no access to project "{project}". '
"If the project visibility is set to workspace, a user cannot be added or removed."
)


class UserAlreadyHasAccess(ManagementOperationFailure):
code = 10
description = 'User "{user}" already has access to project "{project}".'
description = 'User "{user}" already has access to the project "{project}". Role already set to "{role}".'


class ProjectsLimitReached(ManagementOperationFailure):
Expand Down
8 changes: 7 additions & 1 deletion neptune/management/internal/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,13 @@ def add_project_member(
except HTTPNotFound as e:
raise ProjectNotFound(name=project_identifier) from e
except HTTPConflict as e:
raise UserAlreadyHasAccess(user=username, project=project_identifier) from e
members = get_project_member_list(
name=name, workspace=workspace, api_token=api_token
)
user_role = members.get(username)
raise UserAlreadyHasAccess(
user=username, project=project_identifier, role=user_role
) from e


@with_api_exceptions_handler
Expand Down
2 changes: 2 additions & 0 deletions neptune/management/internal/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class ProjectVisibilityDTO(Enum):
PRIVATE = "priv"
PUBLIC = "pub"
WORKSPACE = "workspace"

@classmethod
def from_str(cls, visibility: str) -> "ProjectVisibilityDTO":
Expand All @@ -37,6 +38,7 @@ def from_str(cls, visibility: str) -> "ProjectVisibilityDTO":
return {
ProjectVisibility.PRIVATE: ProjectVisibilityDTO.PRIVATE,
ProjectVisibility.PUBLIC: ProjectVisibilityDTO.PUBLIC,
ProjectVisibility.WORKSPACE: ProjectVisibilityDTO.WORKSPACE,
}[visibility]
except KeyError as e:
raise UnsupportedValue(enum=cls.__name__, value=visibility) from e
Expand Down
1 change: 1 addition & 0 deletions neptune/management/internal/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class ProjectVisibility:
PRIVATE = "priv"
PUBLIC = "pub"
WORKSPACE = "workspace"


class ProjectMemberRole:
Expand Down

0 comments on commit 5860b41

Please sign in to comment.