-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
Permissions.delete(*permissions)
method (#339)
- Loading branch information
Showing
5 changed files
with
262 additions
and
12 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
integration/tests/posit/connect/test_content_item_permissions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from posit import connect | ||
from posit.connect.content import ContentItem | ||
|
||
|
||
class TestContentPermissions: | ||
content: ContentItem | ||
|
||
@classmethod | ||
def setup_class(cls): | ||
cls.client = connect.Client() | ||
cls.content = cls.client.content.create(name="example") | ||
|
||
cls.user_aron = cls.client.users.create( | ||
username="permission_aron", | ||
email="[email protected]", | ||
password="permission_s3cur3p@ssword", | ||
) | ||
cls.user_bill = cls.client.users.create( | ||
username="permission_bill", | ||
email="[email protected]", | ||
password="permission_s3cur3p@ssword", | ||
) | ||
|
||
cls.group_friends = cls.client.groups.create(name="Friends") | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
cls.content.delete() | ||
assert cls.client.content.count() == 0 | ||
|
||
cls.group_friends.delete() | ||
assert cls.client.groups.count() == 0 | ||
|
||
def test_permissions_add_destroy(self): | ||
assert self.client.groups.count() == 1 | ||
assert self.client.users.count() == 3 | ||
assert self.content.permissions.find() == [] | ||
|
||
# Add permissions | ||
self.content.permissions.create( | ||
principal_guid=self.user_aron["guid"], | ||
principal_type="user", | ||
role="viewer", | ||
) | ||
self.content.permissions.create( | ||
principal_guid=self.group_friends["guid"], | ||
principal_type="group", | ||
role="owner", | ||
) | ||
|
||
def assert_permissions_match_guids(permissions, objs_with_guid): | ||
for permission, obj_with_guid in zip(permissions, objs_with_guid): | ||
assert permission["principal_guid"] == obj_with_guid["guid"] | ||
|
||
# Prove they have been added | ||
assert_permissions_match_guids( | ||
self.content.permissions.find(), | ||
[self.user_aron, self.group_friends], | ||
) | ||
|
||
# Remove permissions (and from some that isn't an owner) | ||
destroyed_permissions = self.content.permissions.destroy(self.user_aron, self.user_bill) | ||
assert_permissions_match_guids( | ||
destroyed_permissions, | ||
[self.user_aron], | ||
) | ||
|
||
# Prove they have been removed | ||
assert_permissions_match_guids( | ||
self.content.permissions.find(), | ||
[self.group_friends], | ||
) | ||
|
||
# Remove the last permission | ||
destroyed_permissions = self.content.permissions.destroy(self.group_friends) | ||
assert_permissions_match_guids( | ||
destroyed_permissions, | ||
[self.group_friends], | ||
) | ||
|
||
# Prove they have been removed | ||
assert self.content.permissions.find() == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ class TestUser: | |
@classmethod | ||
def setup_class(cls): | ||
cls.client = client = connect.Client() | ||
|
||
# Play nicely with other tests | ||
cls.existing_user_count = client.users.count() | ||
|
||
cls.aron = client.users.create( | ||
username="aron", | ||
email="[email protected]", | ||
|
@@ -29,8 +33,8 @@ def test_lock(self): | |
assert len(self.client.users.find(account_status="locked")) == 0 | ||
|
||
def test_count(self): | ||
# aron, bill, cole, and me | ||
assert self.client.users.count() == 4 | ||
# aron, bill, cole, and me (and existing user) | ||
assert self.client.users.count() == 3 + self.existing_user_count | ||
|
||
def test_find(self): | ||
assert self.client.users.find(prefix="aron") == [self.aron] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters