Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete_protected for mapped collections #920

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Added
~~~~~

- Add the ``delete_protected`` field to ``MappedCollectionDocument``. (:pr:`NUMBER`)
7 changes: 7 additions & 0 deletions src/globus_sdk/services/gcs/data/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class CollectionDocument(utils.PayloadWrapper, abc.ABC):

DATATYPE_BASE: str = "collection"
DATATYPE_VERSION_IMPLICATIONS: dict[str, tuple[int, int, int]] = {
"delete_protected": (1, 8, 0),
"guest_auth_policy_id": (1, 6, 0),
"disable_anonymous_writes": (1, 5, 0),
"force_verify": (1, 4, 0),
Expand Down Expand Up @@ -236,6 +237,10 @@ class MappedCollectionDocument(CollectionDocument):
guest collections
:type sharing_users_deny: iterable of str, optional

:param delete_protected: Enable or disable deletion protection on this collection.
Defaults to ``True`` during creation.
:type delete_protected: bool, optional

:param allow_guest_collections: Enable or disable creation and use of Guest
Collections on this Mapped Collection
:type allow_guest_collections: bool, optional
Expand Down Expand Up @@ -292,6 +297,7 @@ def __init__(
sharing_users_deny: t.Iterable[str] | None = None,
sharing_restrict_paths: dict[str, t.Any] | None = None,
# bools
delete_protected: bool | None = None,
allow_guest_collections: bool | None = None,
disable_anonymous_writes: bool | None = None,
# dicts
Expand Down Expand Up @@ -337,6 +343,7 @@ def __init__(
sharing_users_deny=sharing_users_deny,
)
self._set_optbools(
delete_protected=delete_protected,
allow_guest_collections=allow_guest_collections,
disable_anonymous_writes=disable_anonymous_writes,
)
Expand Down
70 changes: 70 additions & 0 deletions tests/unit/helpers/gcs/test_collections.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import uuid

import pytest
Expand All @@ -16,6 +17,10 @@
STUB_UC_ID = uuid.uuid1() # user credential


MappedCollectionSignature = inspect.signature(MappedCollectionDocument)
GuestCollectionSignature = inspect.signature(GuestCollectionDocument)


def test_collection_base_abstract():
with pytest.raises(TypeError):
CollectionDocument()
Expand Down Expand Up @@ -66,6 +71,17 @@ def test_datatype_version_deduction(use_kwargs, doc_version):
({"disable_anonymous_writes": True}, "1.5.0"),
({"disable_anonymous_writes": False}, "1.5.0"),
({"guest_auth_policy_id": str(uuid.uuid4())}, "1.6.0"),
({"delete_protected": False}, "1.8.0"),
# combining a long user_message (which uses callback-based detection) with
# higher and lower bounding fields needs to apply correctly
(
{"force_verify": False, "user_message": "long message..." + "x" * 100},
"1.7.0",
),
(
{"delete_protected": False, "user_message": "long message..." + "x" * 100},
"1.8.0",
),
],
)
def test_datatype_version_deduction_mapped_specific_fields(use_kwargs, doc_version):
Expand Down Expand Up @@ -153,3 +169,57 @@ def test_collection_policies_field(policies_type):
}
else:
raise NotImplementedError


# these test cases enumerate parameters for Guest Collections and Mapped Collections
# and ensure that they're defined on one class but not the other
@pytest.mark.parametrize(
"fieldname",
(
"allow_guest_collections",
"delete_protected",
"disable_anonymous_writes",
"domain_name",
"guest_auth_policy_id",
"policies",
"sharing_restrict_paths",
"sharing_users_allow",
"sharing_users_deny",
"storage_gateway_id",
),
)
def test_settings_which_are_only_supported_in_mapped_collections(fieldname):
assert fieldname in MappedCollectionSignature.parameters
assert fieldname not in GuestCollectionSignature.parameters


@pytest.mark.parametrize(
"fieldname",
(
"mapped_collection_id",
"user_credential_id",
),
)
def test_settings_which_are_only_supported_in_guest_collections(fieldname):
assert fieldname in GuestCollectionSignature.parameters
assert fieldname not in MappedCollectionSignature.parameters


@pytest.mark.parametrize(
"fieldname",
(
"allow_guest_collections",
"delete_protected",
"disable_anonymous_writes",
),
)
@pytest.mark.parametrize("value", (True, False, None))
def test_mapped_collection_opt_bool(fieldname, value):
doc = MappedCollectionDocument(
storage_gateway_id=STUB_SG_ID, collection_base_path="/", **{fieldname: value}
)
if value is not None:
assert fieldname in doc
assert doc[fieldname] == value
else:
assert fieldname not in doc