Skip to content

Commit

Permalink
Merge branch 'delete-acl' of https://github.com/smashwilson/python-cl…
Browse files Browse the repository at this point in the history
…ient into smashwilson-delete-acl
  • Loading branch information
zds97 committed Dec 8, 2016
2 parents 8bb868a + c3fe60c commit 6f205b8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions objectrocket/acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from objectrocket import bases
from objectrocket import util
from objectrocket import errors

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -88,6 +89,24 @@ def get(self, instance, acl):
data = self._get_response_data(response)
return self._concrete_acl(data)

@util.token_auto_auth
def delete(self, instance, acl):
"""Delete an ACL by ID belonging to the instance specified by name.
:param str instance: The name of the instance on which the ACL exists.
:param str acll: The ID of the ACL to delete.
"""
base_url = self._url.format(instance=instance)
url = '{base}{aclid}/'.format(base=base_url, aclid=acl)
response = requests.delete(url, **self._default_request_kwargs)

if response.status_code == 200:
logger.info('Successfully deleted ACL {}'.format(acl))
else:
logger.info('Failed to delete ACL {}'.format(acl))
logger.info('Response: [{0}] {1}'.format(response.status_code, response.content))
raise errors.ObjectRocketException('Failed to delete ACL.')

######################
# Private interface. #
######################
Expand Down
17 changes: 17 additions & 0 deletions tests/test_acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ def test_get_makes_expected_api_request(client, acl_doc):
assert output.id == expected_acl_object.id
assert isinstance(output, Acl)

# Tests for delete. #
@responses.activate
def test_delete_makes_expected_api_request(client, acl):
instance_name = 'test_instance'
expected_url = 'http://localhost:5050/v2/instances/{}/acls/{}/'.format(
instance_name,
acl.id
)
responses.add(
responses.DELETE,
expected_url,
status=200,
json={'data':{}},
content_type="application/json",
)

client.acls.delete(instance_name, acl.id)

#####################################
# Tests for Acls private interface. #
Expand Down

0 comments on commit 6f205b8

Please sign in to comment.