Bugfix: respond 204 if no message get claimed.
Change-Id: I4af1810b78ad224fb01614f55ab95b709de9a211
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user