Skip to content

Commit

Permalink
feat: adds permission delete
Browse files Browse the repository at this point in the history
  • Loading branch information
tdstein committed Apr 2, 2024
1 parent cfaadb4 commit 8fade93
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/posit/connect/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ def principal_type(self) -> str:
def role(self) -> str:
return self.get("role") # type: ignore

def delete(self) -> None:
"""Delete the permission."""
path = f"v1/content/{self.content_guid}/permissions/{self.id}"
url = urls.append_path(self.config.url, path)
self.session.delete(url)

@overload
def update(self, role: str) -> None:
"""Update a permission.
"""Update the permission.
Parameters
----------
Expand All @@ -44,11 +50,11 @@ def update(self, role: str) -> None:

@overload
def update(self, *args, **kwargs) -> None:
"""Update a permission."""
"""Update the permission."""
...

def update(self, *args, **kwargs) -> None:
"""Update a permission."""
"""Update the permission."""
body = dict(*args, **kwargs)
path = f"v1/content/{self.content_guid}/permissions/{self.id}"
url = urls.append_path(self.config.url, path)
Expand Down
25 changes: 25 additions & 0 deletions tests/posit/connect/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@
from .api import load_mock # type: ignore


class TestPermissionDelete:
@responses.activate
def test(self):
# data
id = "94"
content_guid = "f2f37341-e21d-3d80-c698-a935ad614066"

# behavior
mock_delete = responses.delete(
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{id}"
)

# setup
config = Config(api_key="12345", url="https://connect.example/")
session = requests.Session()
fake_permission = load_mock(f"v1/content/{content_guid}/permissions/{id}.json")
permission = Permission(config, session, **fake_permission)

# invoke
permission.delete()

# assert
assert mock_delete.call_count == 1


class TestPermissionUpdate:
@responses.activate
def test_request_shape(self):
Expand Down

0 comments on commit 8fade93

Please sign in to comment.