Skip to content

Commit 6eb59cb

Browse files
Paul Hewletteccles
authored andcommitted
Access policies count_matching methods
Problem: The backend does not support counting of matching assets or access_policies in the access_policy endpoint. Solution: Removed count_matching_assets() and count_matching_access_polices() methods in access_policies endpoint. Additionally made keyword arguments in update method mandatory. Signed-off-by: Paul Hewlett <[email protected]>
1 parent a1ccb20 commit 6eb59cb

File tree

2 files changed

+2
-112
lines changed

2 files changed

+2
-112
lines changed

archivist/access_policies.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def read(self, identity: str) -> AccessPolicy:
129129
def update(
130130
self,
131131
identity,
132+
*,
132133
props: Optional[Dict] = None,
133134
filters: Optional[List] = None,
134135
access_permissions: Optional[List] = None,
@@ -228,22 +229,6 @@ def list(
228229
)
229230

230231
# additional queries on different endpoints
231-
def count_matching_assets(self, access_policy_id: str) -> int:
232-
"""Count assets that match access_policy.
233-
234-
Counts number of assets that match an access_policy.
235-
236-
Args:
237-
access_policy_id (str): e.g. access_policies/xxxxxxxxxxxxxxx
238-
239-
Returns:
240-
integer count of assets.
241-
242-
"""
243-
return self._archivist.count(
244-
f"{self._subpath}/{access_policy_id}/{ASSETS_LABEL}"
245-
)
246-
247232
def list_matching_assets(
248233
self, access_policy_id: str, *, page_size: Optional[int] = None
249234
):
@@ -268,22 +253,6 @@ def list_matching_assets(
268253
)
269254
)
270255

271-
def count_matching_access_policies(self, asset_id: str) -> int:
272-
"""Count access policies that match asset.
273-
274-
Counts number of access policies that match asset.
275-
276-
Args:
277-
asset_id (str): e.g. assets/xxxxxxxxxxxxxxx
278-
279-
Returns:
280-
integer count of access policies.
281-
282-
"""
283-
return self._archivist.count(
284-
f"{self._subpath}/{asset_id}/{ACCESS_POLICIES_LABEL}"
285-
)
286-
287256
def list_matching_access_policies(
288257
self, asset_id: str, *, page_size: Optional[int] = None
289258
):

unittests/testaccess_policies.py

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def test_access_policies_update(self):
197197

198198
access_policy = self.arch.access_policies.update(
199199
IDENTITY,
200-
PROPS,
200+
props=PROPS,
201201
)
202202
args, kwargs = mock_patch.call_args
203203
self.assertEqual(
@@ -382,46 +382,6 @@ def test_access_policies_list_by_name(self):
382382
msg="GET method called incorrectly",
383383
)
384384

385-
def test_access_policies_count_matching_access_policies(self):
386-
"""
387-
Test access_policy counting
388-
"""
389-
with mock.patch.object(self.arch.session, "get") as mock_get:
390-
mock_get.return_value = MockResponse(
391-
200,
392-
headers={HEADERS_TOTAL_COUNT: 1},
393-
access_policies=[
394-
RESPONSE,
395-
],
396-
)
397-
398-
count = self.arch.access_policies.count_matching_access_policies(ASSET_ID)
399-
self.assertEqual(
400-
tuple(mock_get.call_args),
401-
(
402-
(
403-
(
404-
f"url/{ROOT}/"
405-
f"{ACCESS_POLICIES_SUBPATH}/{ASSET_ID}/{ACCESS_POLICIES_LABEL}"
406-
),
407-
),
408-
{
409-
"headers": {
410-
"authorization": "Bearer authauthauth",
411-
HEADERS_REQUEST_TOTAL_COUNT: "true",
412-
},
413-
"params": {"page_size": 1},
414-
"verify": True,
415-
},
416-
),
417-
msg="GET method called incorrectly",
418-
)
419-
self.assertEqual(
420-
count,
421-
1,
422-
msg="Incorrect count",
423-
)
424-
425385
def test_access_policies_list_matching_access_policies(self):
426386
"""
427387
Test access_policy counting
@@ -468,45 +428,6 @@ def test_access_policies_list_matching_access_policies(self):
468428
msg="GET method called incorrectly",
469429
)
470430

471-
def test_access_policies_count_matching_assets(self):
472-
"""
473-
Test access_policy counting
474-
"""
475-
with mock.patch.object(self.arch.session, "get") as mock_get:
476-
mock_get.return_value = MockResponse(
477-
200,
478-
headers={HEADERS_TOTAL_COUNT: 1},
479-
assets=[
480-
ASSET,
481-
],
482-
)
483-
484-
count = self.arch.access_policies.count_matching_assets(IDENTITY)
485-
self.assertEqual(
486-
tuple(mock_get.call_args),
487-
(
488-
(
489-
(
490-
f"url/{ROOT}/{ACCESS_POLICIES_SUBPATH}/{IDENTITY}/{ASSETS_LABEL}"
491-
),
492-
),
493-
{
494-
"headers": {
495-
"authorization": "Bearer authauthauth",
496-
HEADERS_REQUEST_TOTAL_COUNT: "true",
497-
},
498-
"params": {"page_size": 1},
499-
"verify": True,
500-
},
501-
),
502-
msg="GET method called incorrectly",
503-
)
504-
self.assertEqual(
505-
count,
506-
1,
507-
msg="Incorrect count",
508-
)
509-
510431
def test_access_policies_list_matching_assets(self):
511432
"""
512433
Test access_policy counting

0 commit comments

Comments
 (0)