Add missing __contains__() and get() methods to QuotaUsage
The QuotaUsage class was missing __contains__() and get() methods which was causing unexpected behaviour, e.g: >>> usages = quotas.tenant_quota_usages(request) >>> 'ram' in usages False >>> usages.get('ram') None Change-Id: Ib0b1ad69c4bf4effd7c10827d23bcc713bdc5ed6
This commit is contained in:
parent
10fb49695c
commit
f2de787d8a
|
@ -119,6 +119,11 @@ class QuotaTests(test.APITestCase):
|
|||
# Compare internal structure of usages to expected.
|
||||
self.assertEqual(quota_usages.usages, expected_output)
|
||||
|
||||
# Make sure that the `in` operator and the `.get()` method
|
||||
# behave as expected
|
||||
self.assertIn('ram', quota_usages)
|
||||
self.assertIsNotNone(quota_usages.get('ram'))
|
||||
|
||||
@test.create_stubs({api.nova: ('server_list',
|
||||
'flavor_list',
|
||||
'tenant_quota_get',),
|
||||
|
|
|
@ -65,6 +65,9 @@ class QuotaUsage(dict):
|
|||
def __init__(self):
|
||||
self.usages = defaultdict(dict)
|
||||
|
||||
def __contains__(self, key):
|
||||
return key in self.usages
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self.usages[key]
|
||||
|
||||
|
@ -76,6 +79,9 @@ class QuotaUsage(dict):
|
|||
def __repr__(self):
|
||||
return repr(dict(self.usages))
|
||||
|
||||
def get(self, key, default=None):
|
||||
return self.usages.get(key, default)
|
||||
|
||||
def add_quota(self, quota):
|
||||
"""Adds an internal tracking reference for the given quota."""
|
||||
if quota.limit is None or quota.limit == -1:
|
||||
|
|
Loading…
Reference in New Issue