Skip to content

Commit

Permalink
fix: Resource can tolerate new JSON properties being introduced
Browse files Browse the repository at this point in the history
  • Loading branch information
nicornk committed Sep 25, 2024
1 parent b9640f1 commit 072b708
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def _from_json(
disableInheritedPermissions: api_types.DisableInheritedPermissionsType | None = None, # noqa: N803
propagatePermissions: bool | None = None, # noqa: N803
resourceLevelRoleGrantsAllowed: bool | None = None, # noqa: N803
**kwargs,
):
self.rid = rid
self.name = name
Expand Down Expand Up @@ -153,6 +154,7 @@ def _from_json(
self.disable_inherited_permissions = disableInheritedPermissions
self.propagate_permissions = propagatePermissions
self.resource_level_role_grants_allowed = resourceLevelRoleGrantsAllowed
self._kwargs = kwargs

@classmethod
def _create_class(
Expand Down
53 changes: 53 additions & 0 deletions tests/unit/resources/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,60 @@ def test_wrong_resource_type(test_context_mock):
"disableInheritedPermissions": None,
"propagatePermissions": None,
"resourceLevelRoleGrantsAllowed": None,
"portfolioRid": None,
},
)
with pytest.raises(WrongResourceTypeError):
test_context_mock.get_dataset("ri.foundry.main.folder.1234")


def test_additional_property_in_resource_json(test_context_mock):
test_context_mock.mock_adapter.register_uri(
"GET",
re.compile(re.escape(build_api_url(test_context_mock.token_provider.host.url, "compass", "")) + "resources/*"),
json={
"rid": "ri.foundry.main.folder.1234",
"name": "just_a_name",
"created": {"time": "2024-08-28T06:54:49.569854929Z", "userId": "1234"},
"modified": {"time": "2024-08-28T06:57:20.413795158Z", "userId": "1234"},
"lastModified": 1724828240413.0,
"description": None,
"operations": [
"compass:edit-project",
],
"urlVariables": {"compass:isProject": "false"},
"favorite": None,
"branches": None,
"defaultBranch": None,
"defaultBranchWithMarkings": None,
"branchesCount": None,
"hasBranches": None,
"hasMultipleBranches": None,
"backedObjectTypes": None,
"path": "/some/path",
"longDescription": None,
"directlyTrashed": False,
"inTrash": False,
"isAutosave": False,
"isHidden": False,
"deprecation": None,
"collections": None,
"namedCollections": None,
"tags": None,
"namedTags": None,
"alias": None,
"collaborators": None,
"namedAncestors": None,
"markings": None,
"projectAccessMarkings": None,
"linkedItems": None,
"contactInformation": None,
"classification": None,
"disableInheritedPermissions": None,
"propagatePermissions": None,
"resourceLevelRoleGrantsAllowed": None,
"portfolioRid": None,
},
)
# fixes TypeError: Resource._from_json() got an unexpected keyword argument 'portfolioRid'
test_context_mock.get_resource("ri.foundry.main.folder.1234")

0 comments on commit 072b708

Please sign in to comment.