Bugfix: respond 204 if no message get claimed.

Change-Id: I4af1810b78ad224fb01614f55ab95b709de9a211
This commit is contained in:
Zhihao Yuan
2013-04-09 16:05:31 -04:00
parent f62cef8c34
commit b94f4e6fe7
2 changed files with 25 additions and 10 deletions

View File

@@ -84,10 +84,12 @@ class TestClaims(util.TestBase):
def test_lifecycle(self):
doc = '{ "ttl": 10 }'
# claim some messages
env = testing.create_environ('/v1/480924/queues/fizbit/claims',
method="POST",
body=doc,
query_string='limit=3')
body=doc)
body = self.app(env, self.srmock)
self.assertEquals(self.srmock.status, falcon.HTTP_200)
@@ -96,6 +98,16 @@ class TestClaims(util.TestBase):
target = self.srmock.headers_dict['Location']
msg_target = st[0]['href']
# no more messages to claim
env = testing.create_environ('/v1/480924/queues/fizbit/claims',
method="POST",
body=doc,
query_string='limit=3')
self.app(env, self.srmock)
self.assertEquals(self.srmock.status, falcon.HTTP_204)
# check its metadata
env = testing.create_environ(target, method="GET")

View File

@@ -44,16 +44,19 @@ class CollectionResource(object):
metadata=metadata,
tenant=tenant_id,
**kwargs)
resp_msgs = list(msgs)
for msg in resp_msgs:
msg['href'] = _msg_uri_from_claim(
req.path.rpartition('/')[0], msg['id'], cid)
del msg['id']
resp.location = req.path + '/' + cid
resp.body = helpers.to_json(resp_msgs)
resp.status = falcon.HTTP_200
if len(resp_msgs) != 0:
for msg in resp_msgs:
msg['href'] = _msg_uri_from_claim(
req.path.rpartition('/')[0], msg['id'], cid)
del msg['id']
resp.location = req.path + '/' + cid
resp.body = helpers.to_json(resp_msgs)
resp.status = falcon.HTTP_200
else:
resp.status = falcon.HTTP_204
except helpers.MalformedJSON:
raise falcon.HTTPBadRequest(_('Bad request'),