Merge "Catch KeyError exception as early as possible when there is no matching data on the server."

This commit is contained in:
Jenkins
2013-03-14 08:26:36 +00:00
committed by Gerrit Code Review
2 changed files with 18 additions and 1 deletions

View File

@@ -56,7 +56,10 @@ class Manager(object):
obj_class = self.resource_class
if response_key:
data = body[response_key]
try:
data = body[response_key]
except KeyError:
return []
else:
data = body
return [obj_class(self, res, loaded=True) for res in data if res]

View File

@@ -111,6 +111,12 @@ fixtures = {
]},
),
},
'/v1/meters': {
'GET': (
{},
{'meters': []},
),
},
}
@@ -120,6 +126,14 @@ class SampleManagerTest(unittest.TestCase):
self.api = utils.FakeAPI(fixtures)
self.mgr = ceilometerclient.v1.meters.SampleManager(self.api)
def test_list_all(self):
samples = list(self.mgr.list(counter_name=None))
expect = [
('GET', '/v1/meters', {}, None),
]
self.assertEqual(self.api.calls, expect)
self.assertEqual(len(samples), 0)
def test_list_by_source(self):
samples = list(self.mgr.list(source='openstack',
counter_name='this'))