Skip to content

Commit

Permalink
Add support for delete_resources_by_asset_ids Admin API
Browse files Browse the repository at this point in the history
  • Loading branch information
const-cloudinary authored Dec 23, 2024
1 parent deb4ae1 commit fe91605
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cloudinary/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,21 @@ def delete_resources(public_ids, **options):
params = __delete_resource_params(options, public_ids=public_ids)
return call_api("delete", uri, params, **options)

def delete_resources_by_asset_ids(asset_ids, **options):
"""
Deletes resources (assets) by asset IDs.
:param asset_ids: The asset IDs of the assets to delete.
:type asset_ids: list[str]
:param options: Additional options.
:type options: dict, optional
:return: The result of the command.
:rtype: dict
"""
uri = ["resources"]
params = __delete_resource_params(options, asset_ids=asset_ids)
return call_json_api("delete", uri, params, **options)


def delete_resources_by_prefix(prefix, **options):
resource_type = options.pop("resource_type", "image")
Expand Down
13 changes: 13 additions & 0 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,19 @@ def test09_delete_resources(self, mocker):
self.assertIn(API_TEST_ID, param)
self.assertIn(API_TEST_ID2, param)

@patch(URLLIB3_REQUEST)
@unittest.skipUnless(cloudinary.config().api_secret, "requires api_key/api_secret")
def test09_delete_resources_by_asset_ids(self, mocker):
""" should allow deleting resources by asset_ids"""
mocker.return_value = MOCK_RESPONSE
api.delete_resources_by_asset_ids([API_TEST_ASSET_ID, API_TEST_ASSET_ID2])

self.assertEqual(get_method(mocker), 'DELETE')
self.assertTrue(get_uri(mocker).endswith('/resources'))
param = get_json_body(mocker)['asset_ids']
self.assertIn(API_TEST_ASSET_ID, param)
self.assertIn(API_TEST_ASSET_ID2, param)

@patch(URLLIB3_REQUEST)
@unittest.skipUnless(cloudinary.config().api_secret, "requires api_key/api_secret")
def test09a_delete_resources_by_prefix(self, mocker):
Expand Down

0 comments on commit fe91605

Please sign in to comment.