Skip to content

Commit

Permalink
feat: adds permissions count (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdstein authored Apr 2, 2024
1 parent f072cf3 commit f848dc0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/posit/connect/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ def __init__(self, config: Config, session: Session, *, content_guid: str) -> No
super().__init__(config, session)
self.content_guid = content_guid

def count(self) -> int:
"""Count the number of permissions.
Returns
-------
int
"""
return len(self.find())

@overload
def create(self, principal_guid: str, principal_type: str, role: str) -> Permission:
"""Create a permission.
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 @@ -131,6 +131,31 @@ def test_role_update(self):
assert permission.role == new_role


class TestPermissionsCount:
@responses.activate
def test(self):
# test data
content_guid = "f2f37341-e21d-3d80-c698-a935ad614066"
fake_permissions = load_mock(f"v1/content/{content_guid}/permissions.json")

# define api behavior
responses.get(
f"https://connect.example/__api__/v1/content/{content_guid}/permissions",
json=fake_permissions,
)

# setup
config = Config(api_key="12345", url="https://connect.example/")
session = requests.Session()
permissions = Permissions(config, session, content_guid=content_guid)

# invoke
count = permissions.count()

# assert response
assert count == len(fake_permissions)


class TestPermissionsCreate:
@responses.activate
def test(self):
Expand Down

0 comments on commit f848dc0

Please sign in to comment.