Skip to content

Commit

Permalink
Merge pull request #920 from sirosen/support-delete-protected
Browse files Browse the repository at this point in the history
Add `delete_protected` for mapped collections
  • Loading branch information
sirosen authored Dec 12, 2023
2 parents bba4dfc + 99035ca commit 3bc55d7
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
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

0 comments on commit 3bc55d7

Please sign in to comment.