Skip to content
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
33 changes: 1 addition & 32 deletions archivist/access_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def read(self, identity: str) -> AccessPolicy:
def update(
self,
identity,
*,
props: Optional[Dict] = None,
filters: Optional[List] = None,
access_permissions: Optional[List] = None,
Expand Down Expand Up @@ -228,22 +229,6 @@ def list(
)

# additional queries on different endpoints
def count_matching_assets(self, access_policy_id: str) -> int:
"""Count assets that match access_policy.

Counts number of assets that match an access_policy.

Args:
access_policy_id (str): e.g. access_policies/xxxxxxxxxxxxxxx

Returns:
integer count of assets.

"""
return self._archivist.count(
f"{self._subpath}/{access_policy_id}/{ASSETS_LABEL}"
)

def list_matching_assets(
self, access_policy_id: str, *, page_size: Optional[int] = None
):
Expand All @@ -268,22 +253,6 @@ def list_matching_assets(
)
)

def count_matching_access_policies(self, asset_id: str) -> int:
"""Count access policies that match asset.

Counts number of access policies that match asset.

Args:
asset_id (str): e.g. assets/xxxxxxxxxxxxxxx

Returns:
integer count of access policies.

"""
return self._archivist.count(
f"{self._subpath}/{asset_id}/{ACCESS_POLICIES_LABEL}"
)

def list_matching_access_policies(
self, asset_id: str, *, page_size: Optional[int] = None
):
Expand Down
81 changes: 1 addition & 80 deletions unittests/testaccess_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def test_access_policies_update(self):

access_policy = self.arch.access_policies.update(
IDENTITY,
PROPS,
props=PROPS,
)
args, kwargs = mock_patch.call_args
self.assertEqual(
Expand Down Expand Up @@ -381,46 +381,6 @@ def test_access_policies_list_by_name(self):
msg="GET method called incorrectly",
)

def test_access_policies_count_matching_access_policies(self):
"""
Test access_policy counting
"""
with mock.patch.object(self.arch.session, "get") as mock_get:
mock_get.return_value = MockResponse(
200,
headers={HEADERS_TOTAL_COUNT: 1},
access_policies=[
RESPONSE,
],
)

count = self.arch.access_policies.count_matching_access_policies(ASSET_ID)
self.assertEqual(
tuple(mock_get.call_args),
(
(
(
f"url/{ROOT}/"
f"{ACCESS_POLICIES_SUBPATH}/{ASSET_ID}/{ACCESS_POLICIES_LABEL}"
),
),
{
"headers": {
"authorization": "Bearer authauthauth",
HEADERS_REQUEST_TOTAL_COUNT: "true",
},
"params": {"page_size": 1},
"verify": True,
},
),
msg="GET method called incorrectly",
)
self.assertEqual(
count,
1,
msg="Incorrect count",
)

def test_access_policies_list_matching_access_policies(self):
"""
Test access_policy counting
Expand Down Expand Up @@ -467,45 +427,6 @@ def test_access_policies_list_matching_access_policies(self):
msg="GET method called incorrectly",
)

def test_access_policies_count_matching_assets(self):
"""
Test access_policy counting
"""
with mock.patch.object(self.arch.session, "get") as mock_get:
mock_get.return_value = MockResponse(
200,
headers={HEADERS_TOTAL_COUNT: 1},
assets=[
ASSET,
],
)

count = self.arch.access_policies.count_matching_assets(IDENTITY)
self.assertEqual(
tuple(mock_get.call_args),
(
(
(
f"url/{ROOT}/{ACCESS_POLICIES_SUBPATH}/{IDENTITY}/{ASSETS_LABEL}"
),
),
{
"headers": {
"authorization": "Bearer authauthauth",
HEADERS_REQUEST_TOTAL_COUNT: "true",
},
"params": {"page_size": 1},
"verify": True,
},
),
msg="GET method called incorrectly",
)
self.assertEqual(
count,
1,
msg="Incorrect count",
)

def test_access_policies_list_matching_assets(self):
"""
Test access_policy counting
Expand Down