Don't return links if subscriptions are empty

The commit I08dd0f675bcd25cd63e17a0aa9779895bd401e32 try to fix
the links format when a queue's subscriptions are empty. But it
doesn't work. Because the "results" which storage returns will
never be None.

This patch fix the nit and also add a test to ensure it works.

Change-Id: Ib7fb0b6bfccc5e913ff618257f07903f692201f1
This commit is contained in:
wangxiyuan 2016-02-15 09:28:19 +08:00
parent 2bc8de46fe
commit bee17b9633
2 changed files with 14 additions and 1 deletions

View File

@ -176,6 +176,19 @@ class TestSubscriptionsMongoDB(base.V2Base):
def test_list_works(self):
self._list_subscription()
def test_list_empty(self):
resp = self.simulate_get(self.subscription_path,
headers=self.headers)
self.assertEqual(falcon.HTTP_200, self.srmock.status)
resp_doc = jsonutils.loads(resp[0])
self.assertIsInstance(resp_doc, dict)
self.assertIn('subscriptions', resp_doc)
self.assertIn('links', resp_doc)
self.assertEqual([], resp_doc['subscriptions'])
self.assertEqual([], resp_doc['links'])
@ddt.data(1, 5, 10, 15)
def test_listing_works_with_limit(self, limit):
self._list_subscription(count=15, limit=limit)

View File

@ -142,7 +142,7 @@ class CollectionResource(object):
kwargs['marker'] = next(results) or kwargs.get('marker', '')
links = []
if results:
if subscriptions:
links = [
{
'rel': 'next',