Skip to content

Commit

Permalink
Add support for delete_backed_up_assets Admin API
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyg-cld authored Dec 22, 2024
1 parent 950936f commit 1bb7515
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cloudinary/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,24 @@ def delete_derived_by_transformation(public_ids, transformations,
return call_api("delete", uri, params, **options)


def delete_backed_up_assets(asset_id, version_ids, **options):
"""
Deletes backed up versions of a resource by asset IDs.
:param asset_id: The asset ID of the asset to update.
:type asset_id: str
:param version_ids: The array of version IDs.
:type version_ids: list[str]
:param options: Additional options.
:type options: dict, optional
:return: The result of the command.
:rtype: dict
"""
uri = ["resources", "backup", asset_id]
params = {"version_ids": utils.build_array(version_ids)}
return call_json_api("delete", uri, params, **options)


def add_related_assets(public_id, assets_to_relate, resource_type="image", type="upload", **options):
"""
Relates an asset to other assets by public IDs.
Expand Down
15 changes: 15 additions & 0 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
API_TEST_ID6 = "api_test_{}6".format(SUFFIX)
API_TEST_ID7 = "api_test_{}7".format(SUFFIX)
API_TEST_ASSET_ID = "4af5a0d1d4047808528b5425d166c101"
API_TEST_ASSET_ID_VERSION_ID = "ded32c1fa9b710b04574f0676133c00a"
API_TEST_ASSET_ID_VERSION_ID_2 = "aae2bae059d13e1ef0ec1742033bb5f7"
API_TEST_ASSET_ID2 = "4af5a0d1d4047808528b5425d166c102"
API_TEST_ASSET_ID3 = "4af5a0d1d4047808528b5425d166c103"
API_TEST_TRANS = "api_test_transformation_{}".format(SUFFIX)
Expand Down Expand Up @@ -586,6 +588,19 @@ def test_delete_related_assets_by_asset_ids(self, mocker):
self.assertIn(API_TEST_ASSET_ID2, param)
self.assertIn(API_TEST_ASSET_ID3, param)

@patch(URLLIB3_REQUEST)
@unittest.skipUnless(cloudinary.config().api_secret, "requires api_key/api_secret")
def test_delete_backed_up_assets(self, mocker):
""" should allow deleting backed up versions of an asset by asset id"""
mocker.return_value = MOCK_RESPONSE
api.delete_backed_up_assets(API_TEST_ASSET_ID, [API_TEST_ASSET_ID_VERSION_ID, API_TEST_ASSET_ID_VERSION_ID_2])
args, _ = mocker.call_args
self.assertEqual(get_method(mocker), 'DELETE')
self.assertTrue(get_uri(mocker).endswith('/resources/backup/' + API_TEST_ASSET_ID))
version_ids = get_json_body(mocker)['version_ids']
self.assertIn(API_TEST_ASSET_ID_VERSION_ID, version_ids)
self.assertIn(API_TEST_ASSET_ID_VERSION_ID_2, version_ids)

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

0 comments on commit 1bb7515

Please sign in to comment.