Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Raises ContainerNotEmpty Error When Attempting to Delete Non-Empty Co…

…ntainer

Resolves Issue #10
  • Loading branch information...
commit cfa09f5ea58007d2061d89a4467c5790f94b506d 1 parent 6a8dea8
@sudorandom sudorandom authored
View
12 object_storage/client.py
@@ -248,12 +248,12 @@ def delete_container(self, name, recursive=False):
if recursive:
params['recursive'] = True
- def _formatter(res):
- if res.status_code is 409:
- raise errors.ContainerNotEmpty(name)
- return True
-
- return self.make_request('DELETE', [name], params=params, formatter=_formatter)
+ try:
+ return self.make_request('DELETE', [name], params=params, formatter=lambda r: True)
+ except errors.ResponseError, ex:
+ if ex.status == 409:
+ raise errors.ContainerNotEmpty(ex.status, "ContainerNotEmpty Error")
+ raise ex
def containers(self, marker=None, headers=None):
""" Lists containers
View
2  object_storage/transport/__init__.py
@@ -8,9 +8,7 @@
from urlparse import urlparse
from object_storage.errors import ResponseError, NotFound
from object_storage import consts
-from object_storage.utils import unicode_quote
-import urllib
import urllib2
import re
View
13 tests/test_client.py
@@ -4,6 +4,7 @@
import unittest
from mock import Mock
from object_storage.client import Client
+from object_storage.errors import ResponseError, ContainerNotEmpty
class ClientTest(unittest.TestCase):
@@ -42,6 +43,18 @@ def test_create_container(self):
self.assert_(created_item == result, 'returns the container itself')
self.container_class.assert_called_with('container_name', client=self.client, headers=None)
+ def test_delete_container_raises_not_empty(self):
+ self.client.make_request = Mock()
+ self.client.make_request.side_effect = ResponseError(409, '409 Client Error')
+ self.connection.make_request().content
+ self.assertRaises(ContainerNotEmpty, self.client.delete_container, 'container')
+
+ def test_delete_container_raises_other_error(self):
+ self.client.make_request = Mock()
+ self.client.make_request.side_effect = ResponseError(404, '404 Not Found')
+ self.connection.make_request().content
+ self.assertRaises(ResponseError, self.client.delete_container, 'container')
+
def test_list_containers(self):
self.connection.storage_url = 'storage_url'
self.connection.make_request().content = '[{"name":"container_name","count":10,"bytes":100}]'
Please sign in to comment.
Something went wrong with that request. Please try again.