Merge "feat(wsgi): message bulk deletion"
This commit is contained in:
commit
a011f07cf1
@ -143,6 +143,36 @@ class MessagesBaseTest(base.TestBase):
|
||||
self.simulate_get(path + '/' + msg_id, self.project_id)
|
||||
self.assertEquals(self.srmock.status, falcon.HTTP_404)
|
||||
|
||||
# Safe to delete non-existing ones
|
||||
self.simulate_delete(path + '/' + msg_id, self.project_id)
|
||||
self.assertEquals(self.srmock.status, falcon.HTTP_204)
|
||||
|
||||
def test_bulk_delete(self):
|
||||
path = self.queue_path + '/messages'
|
||||
self._post_messages(path, repeat=5)
|
||||
[target, params] = self.srmock.headers_dict['Location'].split('?')
|
||||
|
||||
# Deleting the whole collection is denied
|
||||
self.simulate_delete(path, self.project_id)
|
||||
self.assertEquals(self.srmock.status, falcon.HTTP_400)
|
||||
|
||||
self.simulate_delete(target, self.project_id, query_string=params)
|
||||
self.assertEquals(self.srmock.status, falcon.HTTP_204)
|
||||
|
||||
self.simulate_get(target, self.project_id, query_string=params)
|
||||
self.assertEquals(self.srmock.status, falcon.HTTP_404)
|
||||
|
||||
# Safe to delete non-existing ones
|
||||
self.simulate_delete(target, self.project_id, query_string=params)
|
||||
self.assertEquals(self.srmock.status, falcon.HTTP_204)
|
||||
|
||||
# Even after the queue is gone
|
||||
self.simulate_delete(self.queue_path, self.project_id)
|
||||
self.assertEquals(self.srmock.status, falcon.HTTP_204)
|
||||
|
||||
self.simulate_delete(target, self.project_id, query_string=params)
|
||||
self.assertEquals(self.srmock.status, falcon.HTTP_204)
|
||||
|
||||
def test_list(self):
|
||||
path = self.queue_path + '/messages'
|
||||
self._post_messages(path, repeat=10)
|
||||
|
@ -210,6 +210,25 @@ class CollectionResource(object):
|
||||
|
||||
resp.body = helpers.to_json(response)
|
||||
|
||||
def on_delete(self, req, resp, project_id, queue_name):
|
||||
# NOTE(zyuan): Attempt to delete the whole message collection
|
||||
# (without an "ids" parameter) is not allowed
|
||||
ids = req.get_param_as_list('ids', required=True)
|
||||
|
||||
try:
|
||||
self.message_controller.bulk_delete(
|
||||
queue_name,
|
||||
message_ids=ids,
|
||||
project=project_id)
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = 'Messages could not be deleted.'
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
else:
|
||||
resp.status = falcon.HTTP_204
|
||||
|
||||
|
||||
class ItemResource(object):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user